Skip to main content
The run context includes an agent boolean that indicates whether the command is being invoked by an agent or a human.

Overview

How It Works

c.agent is true when:
  • stdout is not a TTY — output is piped, redirected, or consumed programmatically
  • --json or --format is used — explicit format flags indicate agent consumption
  • --mcp is used — running as an MCP stdio server
Otherwise, c.agent is false (human mode).

Use Cases

Progress Messages

Show progress to humans without polluting agent output:

Interactive Prompts

Skip prompts when invoked by agents:

Colored Output

Use colors for humans, plain text for agents:

Logging

Log to stderr in human mode, stay silent in agent mode:

Spinners and Animations

Only show spinners in human mode:

Detection Heuristics

incur uses the same heuristics as standard CLI tools:
This is true when:
  • Output is piped: my-cli deploy | jq
  • Output is redirected: my-cli deploy > output.txt
  • Running in an agent tool call (MCP, skill invocation)
This is false when:
  • Running in a terminal emulator (iTerm, Terminal.app, etc.)
  • Running in an SSH session with a TTY

Middleware Access

Middleware also has access to c.agent:

Best Practices

Do

  • Use console.log() or console.error() for human-facing messages
  • Use return for structured data that goes to both agents and humans
  • Check c.agent before prompting for input
  • Check c.agent before showing progress indicators

Don’t

  • Don’t change the return value based on c.agent — return the same data structure in both modes
  • Don’t use c.agent to hide errors — errors should always be shown
  • Don’t use c.agent for authentication — it’s a UI hint, not a security boundary