Covers agent mode detection via environment variables and --agent flag, behavior changes when active, opt-out mechanisms, and exempt commands.
Agent mode is detected via environment variables at init() time in
internal/agent/agent.go and via the --agent CLI flag pre-parsed in
main.go before Cobra command construction.
| Variable | Set by | Effect |
|---|---|---|
GCX_AGENT_MODE |
Explicit opt-in/out | 1/true/yes enables; 0/false/no disables (overrides all others) |
CLAUDECODE |
Claude Code | Truthy value activates agent mode |
CLAUDE_CODE |
Claude Code | Truthy value activates agent mode |
CURSOR_AGENT |
Cursor | Truthy value activates agent mode |
GITHUB_COPILOT |
GitHub Copilot | Truthy value activates agent mode |
AMAZON_Q |
Amazon Q | Truthy value activates agent mode |
The --agent persistent flag can also enable agent mode. --agent=false
explicitly disables agent mode even when env vars are set.
Priority order: GCX_AGENT_MODE=0 (disable) > any truthy env var
(enable) > --agent flag > default (disabled).
API: agent.IsAgentMode() bool, agent.SetFlag(bool), agent.DetectedFromEnv() bool
Reference: internal/agent/agent.go
When agent mode is active:
- Default output format becomes
jsonfor all commands (overrides per-commandDefaultFormat()inio.Options.BindFlags()) - Color is disabled (
color.NoColor = trueinPersistentPreRun) - Pipe-aware behavior is forced:
IsPiped=true,NoTruncate=trueregardless of actual TTY state (see pipe-awareness.md § TTY Detection) - In-band error JSON is written to stdout on failure (see errors.md § In-Band Error Reporting)
The following are not yet implemented:
5. Spinners/progress indicators suppressed (none exist yet; the suppression
contract via IsPiped is in place for when they are added)
6. Confirmation prompts auto-approved (safety.md § Agent Mode Auto-Approve)
Explicit flags override agent mode defaults:
-o textor-o yamloverrides the JSON default--agent=falsedisables agent mode entirely (even when env vars are set)GCX_AGENT_MODE=0disables agent mode regardless of other env vars
Commands that produce non-data output are exempt from format switching:
config set,config use-context— confirmations onlyserve— starts a long-running serverpush,pull— output is status messages, not data
See environment-variables.md § Agent Mode Variables for the full variable reference.