Repository navigation
Conversation
NickJosevski
force-pushed
the
robe/claude-ua
branch
from
August 14, 2026 04:37
365a62e to
25dc418
Compare
NickJosevski
approved these changes
Aug 14, 2026
NickJosevski
left a comment
Contributor
There was a problem hiding this comment.
you still want this in?
Report the AI agent driving a process as its own user agent token, separate from the automation (CI) environment, so an agent running in CI or on an Octopus worker reports both rather than one at random. - Honour the emerging AI_AGENT convention, mapping known values to a canonical name and passing the sanitised raw value through as a comment - Fall back to vendor variables for Claude Code, Cursor, Codex, Gemini CLI, GitHub Copilot, OpenCode, Antigravity, Goose, Amp, Cline, Roo Code, Augment, Qwen Code, Factory Droid, Kimi CLI, Trae, Aider and OpenHands, checked in a fixed order - Exclude variables that are set without an agent driving the process (e.g. CURSOR_TRACE_ID, COPILOT_GITHUB_TOKEN, REPL_ID) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T4ijpGHFpAqBBMhn5WKUq2
Map AI_AGENT to one of the known agent names instead of passing the raw value through as a user agent comment. Unrecognised values report as AIAgent/Other. The raw value is free-form and user-settable, so it is now only used for matching, which also removes the need to sanitise it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T4ijpGHFpAqBBMhn5WKUq2
zentron
force-pushed
the
robe/claude-ua
branch
from
November 12, 2026 22:57
0d73c0d to
3422651
Compare
Collapse runs of underscores and whitespace into a single hyphen before matching a self-reported agent identifier, so a name such as "Claude Code" maps the same way in all three clients. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T4ijpGHFpAqBBMhn5WKUq2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
AI coding agents increasingly drive the Octopus CLI, the Terraform provider and other tools built on this SDK, but none of that traffic is identifiable today. Agents don't change the headers of the tools they run; they only export environment variables to the processes they launch. Reading those variables here gives the server a signal for agent-driven API usage.
Results
The user agent gains an
AIAgent/<Name>token after the automation environment when an agent is detected:AI_AGENTfirst. This is the emerging cross-vendor convention (@vercel/detect-agent). Its value is mapped to a known name by prefix, e.g.claude-code_2-1-322_agent→ClaudeCode,github_copilot_vscode_agent→GitHubCopilot. The raw value is never sent, since it is free-form and user-settable. An unrecognised value reports asAIAgent/Other.CURSOR_TRACE_ID,COPILOT_GITHUB_TOKEN,GOOSE_PROVIDER,REPL_IDandZED_TERMare set in ordinary human sessions, so they would label people as agents.Claude Codeandclaude_codemap the same way.Testing
ai_agent_provider_test.gocover each agent's variables, value-matched rules, excluded variables, nested-agent ordering,AI_AGENTmapping and precedence, and that the rawAI_AGENTvalue never appears in the output. The existing CI detection tests still pass.AIAgent/ClaudeCode.How to review this PR
The logic is all in
pkg/services/api/ai_agent_provider.go, and theapi.gochange is the four lines that append the token. The agent list is the part most worth a second opinion: the variable names come from other detectors (.NET Aspire'sCodingAgentDetector,@vercel/detect-agent,is-ai-agent) and are mostly undocumented vendor internals. This file is the reference copy of the list: the TypeScript port (api-client.ts#294) and the .NET port point back to it in a comment.Caveats
Other(if it setsAI_AGENT) or not at all until it is added and an SDK release ships.AGENT=ampcomes from a secondary source. If Amp doesn't set it, that rule never fires.Generated by Claude Code