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
--jsonor--formatis used — explicit format flags indicate agent consumption--mcpis used — running as an MCP stdio server
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: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)
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 toc.agent:
Best Practices
Do
- Use
console.log()orconsole.error()for human-facing messages - Use
returnfor structured data that goes to both agents and humans - Check
c.agentbefore prompting for input - Check
c.agentbefore 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.agentto hide errors — errors should always be shown - Don’t use
c.agentfor authentication — it’s a UI hint, not a security boundary
Related
- See Output Policy for suppressing data output in human mode
- See TOON Output for token-efficient output formatting

