Repository navigation
Conversation
AI_AGENT is the cross-agent marker that Claude Code, Copilot in VS Code, Pi, Crush and others set for child processes, and gh, Stripe and Netlify read first. cf ignored any value it had no detector for, so agents without a dedicated detector looked like humans. Treat any AI_AGENT value that no detector explains as harness `unknown`, and record the announced name in telemetry when it matches the format gh accepts, bounded to 64 characters. Also recognise Claude Code from its AI_AGENT value and record the version it embeds as `agentVersion`.
commit: |
| }; | ||
|
|
||
| // Claude Code announces itself as `claude-code_<major>-<minor>-<patch>_agent`. | ||
| const CLAUDE_CODE_ANNOUNCEMENT = /^claude-code(?:_(\d+(?:-\d+)*))?(?:_|$)/; |
There was a problem hiding this comment.
CLAUDE_CODE_ANNOUNCEMENT accepts values outside the documented Claude Code announcement format, such as claude-code_1-2-3-4_agent and claude-code_1-2-3_agentic. With no other signal those are classified as Claude Code and their arbitrary numeric suffix is sent as agentVersion, instead of remaining an unknown AI_AGENT value. Restrict the matcher to the three-component, _agent-terminated form while retaining the existing versionless claude-code_agent case.
| const CLAUDE_CODE_ANNOUNCEMENT = /^claude-code(?:_(\d+(?:-\d+)*))?(?:_|$)/; | |
| const CLAUDE_CODE_ANNOUNCEMENT = | |
| /^claude-code(?:_(\d+-\d+-\d+)_agent|_agent)?$/; |
|
Review: 1 findings. Posted 1 inline suggestion. |
There was a problem hiding this comment.
💬 Approved with comments — No correctness, security or performance problems. The only note is an INFO about the changeset wording, which overstates which AI_AGENT values count as an agent.
Findings: 1 info (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
📝 Documentation: 💬 1 info
The changeset title overstates which AI_AGENT values count as an agent.
Recommendation: 💬 Optional Nits
- [INFO] Changeset title says any AI_AGENT value marks an agent, but false-like values are ignored and names are recorded only when they match the allowed format. (
.changeset/detect-unknown-agents.md:5)
View full review
The changeset says "any" AI_AGENT value is treated as an agent, and that the name it gives is recorded. Empty and false-like values are ignored, and the name is recorded only when it matches the allowed format.
✅ All other checks passed
🚀 Release: ✅ LGTM
Overall risk: Low. The pull request adds unknown-agent detection and Claude Code version telemetry. It includes a minor changeset and updates packages/cli/telemetry.md.
🔒 Security: ✅ LGTM
No security issues. The announced name is checked against a strict, length-limited pattern before it reaches telemetry, and the header keeps a closed set of values.
📖 AGENTS.md: ✅ LGTM
The pull request follows the repository conventions. It includes a minor changeset for the user-facing change and updates the telemetry disclosure.
📋 Code Quality: ✅ LGTM
I found no correctness or convention problems.
- Fallback:
detectUnknownAgentruns after every detector, so it only claimsAI_AGENTvalues that no detector explains. A recognised agent stays primary. - Announced name: a name is recorded only if it matches the 64-character
[A-Za-z0-9_-]format. TheX-CF-CLI-Agentheader always sends the fixed valueunknown. - Tests: they cover version parsing, unknown agents, withheld names, values a detector already explains, and a recognised agent staying primary over an unknown one.
⚡ Performance: ✅ LGTM
No performance issues.
Reviewed commit: 6c706a65
| "cf": minor | ||
| --- | ||
|
|
||
| Treat any `AI_AGENT` value as an AI coding agent. |
There was a problem hiding this comment.
ℹ️ INFO · Documentation
Changeset title says any AI_AGENT value marks an agent, but false-like values are ignored and names are recorded only when they match the allowed format.
This changelog entry says any AI_AGENT value is treated as an AI coding agent. The code ignores empty and false-like values (0, false, no, off), and it records the announced name only when the name is at most 64 characters of [A-Za-z0-9_-]. Consider qualifying the title and body, for example "Treat unrecognised AI_AGENT values as an AI coding agent", and saying that the name is recorded only when it is in the accepted format.
|
| mean | stddev | min | max | |
|---|---|---|---|---|
| PR | 281.0 ms | 3.6 ms | 275.4 ms | 286.3 ms |
| base | 279.6 ms | 3.7 ms | 275.6 ms | 286.7 ms |
Δ (PR vs base): ↑ +1.3 ms (+0.5%)
Measured with hyperfine on ubuntu-latest (3 warmup runs, 20 timed runs). CI numbers carry ±a few ms of runner jitter; treat small deltas as noise.
AI_AGENTis becoming the shared way for coding agents to identify themselves to the tools they run. Claude Code, Copilot in VS Code, Pi and Crush set it for child processes, and gh, the Stripe CLI and the Netlify CLI read it before any vendor-specific variable (agents.md#136 tracks the proposal). At this point cf ignores anyAI_AGENTvalue it has no detector for, so those agents look like human use.Changes
AI_AGENTvalue that no detector explains now marks the run as agentic, with harness IDunknown. That covers agent help,whoamidefaults, theX-CF-CLI-Agentheader and telemetry'sagentfield. A detector explains a value when it readAI_AGENTitself, or when the value equals its harness ID or starts with that ID plus_(for example, OpenCode'sopencode). False-like values (0,false,no,off) are still ignored.agentAnnouncedName, but only when it matches the format gh accepts ([A-Za-z0-9_-]), limited to 64 characters. Other values still count as an unknown agent, but their name is not sent. The header keeps the fixedunknownvalue, so it stays a closed set.AI_AGENT=claude-code_<major>-<minor>-<patch>_agent(since 2.1.120). cf now recognises Claude Code from that value and records the version it contains asagentVersion.packages/cli/telemetry.mddescribes both new properties.When a recognised agent and an unrecognised one are both present (for example, an outer agent's
AI_AGENTinherited by Codex), the recognised agent stays primary. The unknown match is kept inmatches, and its name is still recorded.Notes for reviewers
properties_residualcolumn.agentVersionandagentAnnouncedNamecan be read in the rawsparrow_eventstable, but not infct.eventsuntil the data model gives them their own columns.AI_AGENTnow read, a test that setsCLAUDECODE=""to simulate a human user still detects Claude Code when run inside a Claude Code session. Only the dispatcher test relies on that, and it now sets both variables.Testing
pnpm testinpackages/cli, with agent variables removed from the environment as in CI, passes.pnpm checkpasses.