Commit Graph
1 Commits
Author SHA1 Message Date
yetone a60493ab60 gateway: Codex run by Claude Code's Codex plugin is counted as Codex, not Claude Code
wyztony on X: "claude通过/codex skill时,用量不会记录codex的记录".
OpenAI's Codex plugin for Claude Code (codex-plugin-cc 1.0.6,
/codex:rescue and /codex:review) runs `codex app-server` with clientInfo
named "Claude Code". Codex 0.162.1 then sends "originator: Claude Code"
and "User-Agent: Claude Code/0.162.1 (...) (Claude Code; 1.0.6)", so
agentOf read every such turn as Claude Code's ("claude") and the Usage
page showed none of them under Codex.

agentOf now takes a "Claude Code" name back to Codex when the request
carries Codex's own turn headers (x-codex-window-id or
x-codex-turn-metadata), which Claude Code itself (claude-cli/...) never
sends. An app running Codex as its own engine under its own name (Lody)
keeps its name, as TestFromCodex already holds. fromCodex is unchanged,
so nothing sent upstream changes. Every path keyed on agentOf
(Codex subagent pick, spawn_agent models, drawing route, Codex backend
records, titles, search, active sessions, callerOf) follows.

Run:
- TestCodexPluginForClaudeCodeIsCodex: red on the old code with the
  check turned off by hand ("plugin task: recorded as \"Claude\", want
  \"codex\""), green with it. Cases: the plugin's captured headers,
  originator only, claude-cli, the name without Codex's turn headers,
  Lody with them.
- Real use in a sandbox HOME: codex-cli 0.162.1 wired to a sandbox
  `magpie serve` on a fake Responses upstream, driven by the plugin's own
  codex-companion.mjs (db52e28). Before: task and review rows were
  "agent":"claude". After: both "agent":"codex". Plain `codex exec` (a
  skill-folder /codex skill) was already "codex" through the gateway and
  read from its rollout when direct.
- gofmt; go vet darwin, linux, windows.
- Full suite (go test ./... -timeout 45m, one suite on the machine) was
  started at this tree and was still running at push; per the owner's
  ship-at-once rule, a red it finds goes in its own commit.

Not changed, outside magpie: with Codex not routed through magpie,
/codex:review runs an ephemeral thread and Codex writes no rollout, so
there is nothing on disk for magpie to read; /codex:rescue writes one
and was already counted as Codex. Past rows stay under Claude Code.
2026-10-25 23:02:33 +08:00