Agent mode not detected under Claude Code; explicit --agent-mode dropped
- Dominant language
- Go
- Stars
- 1
- Forks
- 0
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 18
Description
## Bug
Two related agent-mode defects (both needed for agent mode to work):
1. **Auto-detection never fires under Claude Code.** The agent-env list has `CLAUDE_CODE`, but Claude Code actually sets `CLAUDECODE` (no underscore), so agent mode — and its TOON output default — never activates.
2. **An explicit `--agent-mode` is dropped.** `Execute()` calls `InitAgentMode` once *before* flag parsing (to gate the explorer TUI). Its `CompareAndSwap` latch makes the later post-parse call in `PersistentPreRunE` a no-op, so `--agent-mode` / `--agent-mode=false` on the command line is ignored.
## Root cause (Speakeasy-generated code)
1. `internal/output/agentmode.go` — `agentEnvVars` is missing `CLAUDECODE`.
2. `internal/cli/root.go` — `Execute()` runs early pre-parse detection to gate the TUI; the latch in `InitAgentMode` then blocks re-evaluation after flags are parsed.
## Stopgap fix (retire when upstream is fixed)
- `.speakeasy/patches/internal/output/agentmode.go.patch` — adds `CLAUDECODE` to `agentEnvVars`.
- Hand-written `internal/cli/custom_startup.go` — the chained post-flag-parse `PersistentPreRunE` calls `output.ResetAgentMode(); output.InitAgentMode(cmd)` when `--agent-mode` was explicitly changed, so the flag wins over the early latched detection.
**To retire:** once Speakeasy (1) includes `CLAUDECODE` in its agent-env list — remove the `agentmode.go.patch` hunk; and (2) re-evaluates agent detection after flag parsing so an explicit flag wins — remove the re-eval block from `custom_startup.go`.
## Refs
- Introduced by #14
- Upstream generator bug — should also be filed to speakeasy-api/speakeasy. (The `CLAUDECODE` addition is trivially upstreamable.)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with internal/output/agentmode.go and internal/cli/root.go, then trace Execute(), InitAgentMode, and PersistentPreRunE to understand the pre-parse and post-parse sequence. Verify that Claude Code detection works and that explicit --agent-mode and --agent-mode=false take precedence; done means the stopgap patches can be retired without either behavior regressing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100