Skip to content

Attribute CLI and MCP calls to the coding agent that made them - #2087

Open
mernit wants to merge 1 commit into
mainfrom
eli/agent-attribution
Open

mernit wants to merge 1 commit into
mainfrom
eli/agent-attribution

Conversation

@mernit

@mernit mernit commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Every request already carries x-beta9-caller and, when BETA9_AGENT_SESSION is set, x-beta9-agent-session, and the gateway stamps both on stub events. Nothing set the session, though, and the caller never said which coding agent ran the CLI.

CLI. It now reads the variables coding agents export to the commands they run: CLAUDECODE, CURSOR_AGENT, CODEX_THREAD_ID or CODEX_SANDBOX, GEMINI_CLI, COPILOT_CLI, and AI_AGENT for everything else. The caller becomes cli/<version> (<agent>). When BETA9_AGENT_SESSION is unset, the agent's own session id (CLAUDE_CODE_SESSION_ID, CURSOR_CONVERSATION_ID, CODEX_THREAD_ID) fills it. Explicit BETA9_CALLER and BETA9_AGENT_SESSION values still win.

MCP bridge. It sent neither header, so the gateway couldn't tell which agent made an MCP call. It now attributes its requests to the client that connected, as mcp/<version> (<clientInfo.name>/<version>), with one session id per server process. Both go in its environment, so the CLI processes its deploy and run tools start share them.

Checked from a Cursor agent: the caller arrived as cli/0.1.292 (cursor), with the conversation id as the session.

beam feedback (beam-cloud/beam-client#102) sends these headers to internal-api, which stores them with each report, so once this ships, feedback names the agent that sent it. Neither PR depends on the other.

Every request already carries x-beta9-caller and, when BETA9_AGENT_SESSION
is set, x-beta9-agent-session, and the gateway stamps both on stub events.
Nothing set the session, though, and the caller never said which agent ran
the CLI.

The CLI now reads the variables coding agents export to the commands they
run (CLAUDECODE, CURSOR_AGENT, CODEX_THREAD_ID/CODEX_SANDBOX, GEMINI_CLI,
COPILOT_CLI, and AI_AGENT for the rest). The caller becomes
`cli/<version> (<agent>)`, and the agent's own session id
(CLAUDE_CODE_SESSION_ID, CURSOR_CONVERSATION_ID, CODEX_THREAD_ID) fills
the session when BETA9_AGENT_SESSION is unset. Explicit values still win.

The MCP bridge sent neither header, so the gateway could not tell which
agent made an MCP call. It now attributes its requests to the client that
connected, `mcp/<version> (<clientInfo.name>/<version>)`, with one session
id per server process. Both go in its environment, so the CLI processes
its deploy and run tools start share them.

Co-authored-by: Cursor <cursoragent@cursor.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant