Task-Level LLM Cost Tagging When Claude Code and Codex Share the Same Team Account

Separate per-task AI spend when models share team credentials.

· 8 min read
Cover illustration for “Task-Level LLM Cost Tagging When Claude Code and Codex Share the Same Team Account”
Cloud Agent Licensing · November 3, 2026 · 8 min read · 1,826 words

Per-run agent cost attribution for engineering teams requires a task-level identity before the first model call. When Claude Code and Codex share a team account, request metadata records ownership, a proxy enforces tagging and records consumption, and harness hooks connect calls to task boundaries. Together, these layers show the per-task spend that provider billing hides behind shared credentials.

Why provider billing hides per-task spend when Claude Code and Codex share a team account

A VP of Platform Engineering sees one billing row showing a large total against a single shared key powering 50-plus engineers across four teams and a dozen applications. The number is exact but reveals nothing about origin. It does not distinguish a code review from a feature implementation, or one team’s work from another’s experiments. The credential identifies who pays.

That distinction is built into the accounting model. Anthropic’s Admin API groups usage by API key, workspace, model, and other fields such as service tier and actor. OpenAI’s Usage API shows usage for the organization, with filters for project and API key. These controls help separate consumption where credentials or projects already separate ownership, but they cannot resolve tasks that share the same route to a model.

The billing architectures also differ between agents. Codex shares the ChatGPT plan’s usage allowance across its local CLI, cloud tasks, web, and IDE surfaces. A team using both agents therefore has different billing paths with no native join key to link them. More detailed provider reports can describe consumption, but they do not supply the missing engineering context.

Why the attribution gap has become a day-two operating problem, not an edge case

Agentic workloads turn that missing context into an operating problem because a prompt is no longer a useful proxy for consumption. A single request can start a loop of thinking, searching, and refinement, with repeated model calls before the agent finishes. Agent teams running in plan mode use far more tokens than standard sessions.

At the scale of the shared-key account, those loops accumulate across engineers, teams, and applications. Managing AI spend becomes a routine engineering and finance responsibility. Yet the aggregate bill cannot distinguish a costly task that delivered useful work from repeated calls that failed to advance it. Without that distinction, a higher total says little about what to change.

Vector database retrievals can cost several times more than the inference they support, while appearing on a separate vendor’s invoice. The provider total is therefore not necessarily the task total. As agent usage grows, attribution must link work across systems as well as split one model bill among teams.

Where attribution actually breaks across the request lifecycle

Attribution breaks at four distinct hops, beginning in the application layer. Neither Claude Code nor Codex adds task or team metadata to API calls by default, so a runtime can send a prompt and model without any ownership fields. The request leaves without its engineering identity. Downstream accounting cannot recover that identity from token counts alone.

The second hop is the gateway, where metadata may be added but then lost if the router or runtime does not preserve it through asynchronous sub-calls. The third is the fan-out itself. A parent task that spawns three tool-call loops can produce three provider invocations whose rewritten payloads lack a stable link to the originating task.

The fourth break is between billing and traces. Provider consumption lands in the billing system, while execution details land in the observability stack. Without a trace ID spanning the lifecycle, the two records have no stable join key. The minimum useful contract consists of that ID, an owner team, a workflow ID, a feature label, and a non-PII user or tenant handle, established before the first provider call and propagated into every child span.

Request metadata as the lightest-weight and least complete attribution layer

Request metadata is the fastest way to attach ownership to model consumption. The calling application can supply a workflow or feature label, while a session ID groups multi-turn exchanges. However, this layer records only what the runtime explicitly passes, and neither agent supplies the full attribution contract automatically.

The first limitation appears when an agent delegates work. Child spans inherit no ownership metadata unless the harness explicitly propagates it, so a tagged parent request does not establish a complete cost tree. Background consumption creates another gap. Conversation summarization and internal commands such as /usage can consume tokens outside the main task loop, where a label attached only to foreground requests provides incomplete coverage.

Ownership labels also do not explain the composition of a charge. A warm cache read costs roughly one-tenth, or as little as one-twentieth, of a fresh input read, depending on the model. Token-type tagging is needed to distinguish cache reads from cache writes and fresh input. Otherwise, similarly sized sessions can appear comparable while their cost components differ.

Local session tools serve a narrower purpose. Claude Code’s /cost gives a local estimate of token usage and session spend, while /usage shows plan-level limits and rate-limit status. Local session figures can differ from the authoritative record in the Claude Console for API key users or Settings > Usage on claude.ai for subscription users. They cover only the current machine, so shared-account attribution must also account for other devices and claude.ai sessions.

Proxy-side tagging for provider calls the harness does not surface

A proxy supplies the enforcement point that request metadata lacks. It can tag and record outbound provider calls passing through it, including fan-out calls that the harness does not expose in its main task record. Coverage depends on the route. RAG retrievals and tool invocations also need to pass through that enforcement path if they are to appear in the same accounting view.

At the gateway, a stable parent span ID links child calls to root attribution. Per-request audit trails then record the provider, model, input tokens, output tokens, cache reads, cache writes, and calculated cost components. This separates ownership from measurement. Metadata answers whose work the request serves, while the proxy records what that request consumed.

The same boundary makes budget policy enforceable. Virtual key caps can constrain per-user or per-team consumption rather than leave every developer with unrestricted access to production API keys. The four-tier hierarchy has Customer above Team, Team above Virtual Key, and Virtual Key above Provider Config. Each tier can have its own budget cap, with attribution rolling up through the hierarchy.

Central logging also supports compliance review for SOC 2, HIPAA, or ISO 27001 requirements, without making the proxy alone a guarantee of compliance. Agents do not centrally log their requests by default. Without a gateway, teams can also lack automatic rerouting when a provider becomes unavailable. The proxy is therefore an operational control point as well as an accounting layer.

Agent harness hooks connect attribution to the task lifecycle

Harness hooks supply engineering intent by connecting the start, delegation, and completion of work to the requests generated along the way. A task is more than an API call. Its accounting record needs to group the full execution tree as well as show the price of each request.

Those fields are derived from a shared key that previously exposed only an opaque monthly total. The row now connects consumption to an identifiable engineering workflow.

The Linear agent loop illustrates a more primitive task record. Its bash-based loop connects Claude Code to Linear and GitHub, using PROGRESS.md as cross-session memory that the agent reads at the beginning and updates at the end. That record preserves task continuity independently of provider accounting. It does not, by itself, establish the billing join.

For cost attribution, the corresponding hooks need explicit lifecycle responsibilities. A task-start event mints the trace ID and sets owner_team, workflow_id, feature, and the user handle before the first call. A fan-out event propagates that identity into sub-agent calls, and a task-end event closes the parent span and rolls up child costs. Claude Code’s session context, MCP server breakdowns, and subagent attribution provide instrumentation surfaces, while Codex’s environment lifecycle offers another surface through container-cache invalidation on setup-script, maintenance-script, environment-variable, or secrets changes.

How do teams track each Claude Code or Codex run and its cost?

Request metadata defines ownership, harness hooks preserve task boundaries, and the proxy enforces the contract while measuring consumption. Each addresses a different failure point. Metadata without propagation loses delegated work, while gateway records without task context remain a detailed account at the call level.

In this operating model, task creation establishes the shared identity before execution begins. Harness hooks preserve that identity through fan-out, and the proxy captures input, output, cache-read, and cache-write consumption for the requests it handles. The task-end event provides the boundary for the rollup. Billing and execution records can then join on a stable trace rather than depend on matching times or aggregate totals.

Cloud agent environments are a natural deployment point because an isolated VM gives each run its own execution context. That context is the place to mint and propagate the trace ID before any provider call. Pre-loaded dependencies and tooling also make setup reproducible and hookable. Codex makes internet access available during the setup-script phase, while agent-phase access is off by default but can be configured.

Environment-level analytics can then retain the source, harness, model, and credential for every minute an agent runs. Claude Code and Codex can have different profiles for completion time, tool use, and cost per successful task, so lower latency does not necessarily mean lower spend. Attribution by harness makes those trade-offs measurable without treating either agent as the universal choice.

What attribution at the task layer actually changes for engineering teams

Task-level attribution changes the unit of discussion from a shared credential to completed work. Chargeback can connect spend and cache savings to a team and workflow, with request counts and error rates providing execution context. Finance gains a defensible allocation of consumption. Engineering gains a way to distinguish expensive useful work from costs that warrant investigation.

That distinction makes anomaly detection more specific. A spike can be traced to an agent fan-out, a cache-miss pattern, or an Opus session that should have routed to Sonnet. The corrective action can then target the source, leaving the rest of the organization unrestricted. Virtual key caps also stop runaway loops before their full cost reaches the invoice.

With cost attached to successful tasks and identified by harness and model, teams can compare agents on measured efficiency. An agent that is economical for one class of work need not be the preferred choice for every task.

The governance hierarchy makes that flexibility sustainable. Customer, Team, Virtual Key, and Provider Config provide budget boundaries that do not depend on a particular harness, while per-request audit trails preserve the evidence beneath each allocation. A new agent can enter the same ownership and accounting contract. The team that builds attribution at the task layer can change its agents without rebuilding its cost model or accepting a new billing blind spot.

More in Cloud Agent Licensing