The Agentic Team Report

Why Task Isolation Is the Only Reliable Primitive for LLM Cost Attribution Across Claude Code and Codex Users

Task isolation is the only way to reliably track which agent owes which cost.

· 8 min read
Cover illustration for “Why Task Isolation Is the Only Reliable Primitive for LLM Cost Attribution Across Claude Code and Codex Users”
Parallel Agent Workflows · November 5, 2026 · 8 min read · 1,778 words

Reliable per-run agent cost attribution for engineering teams requires one agent run per sandboxed environment, linked to its task, user, team, harness, model, and credential. When Claude Code and Codex share environments, token totals measure consumption but cannot reliably establish responsibility.

Why token-level cost tracking fails when Claude Code and Codex share environments

A VP of Platform receives a Slack message asking for the AI cost breakdown by team for a Q2 budget meeting. The total is exact, but the attribution is zero. The missing information is a stable boundary between the work of different users, tasks, and agents.

Teams ship the first agent and defer attribution until “once we have traffic,” then spend a quarter retroactively joining logs to customer records to explain why margins moved. Within a shared API key or subscription seat, the billing layer does not distinguish the tasks responsible for consumption. Pooling those records across agents compounds the ambiguity because their execution boundaries differ. Codex cloud uses a sandbox per task, while Claude Code optionally uses a git worktree per agent through --worktree or its worktree isolation setting.

Metering changes do not repair that architectural mismatch. Codex moved to token-based credits on April 2, 2026, metering input, cached input, and output tokens on a rolling five-hour window. That removes a fixed pre-task cost estimate without supplying task-level responsibility. A small bug fix and a large multi-file refactor can therefore appear as consumption in the same billing category, even though their token totals differ. More detailed instrumentation can describe those totals, but it cannot reconstruct a task boundary that the execution environment never enforced.

Why Claude Code and Codex cannot be treated as a single line item

Claude Code’s prompt cache strategy has the biggest effect on its cost. By preserving prefix stability after compaction, it allows subsequent requests to reuse cached input during iterative agent loops. Cache hits can make up a large share of all input, so long-running, interactive workflows can cost less than the headline token price suggests. The way a session reuses its context helps determine what that duration costs.

Codex follows a different execution pattern, favoring throughput over duration. Its architecture is optimized for many agents running in parallel for shorter windows. Container state resets between tasks by design, and any cached state lasts only a limited time before expiry. This changes the relationship between task length, parallelism, and reuse. The two agents cannot be compared accurately by treating their sessions as equivalent units of work.

For teams running both, a single budget line suppresses these differences precisely where spend decisions require them. An increase could belong to one harness, one class of task, or work that failed. The pooled total cannot show which of those caused the increase. Nor can it show whether cache reuse made a longer Claude Code session cost less than a different execution pattern. The relevant comparison is the attributable cost of matched task types.

How context accumulation becomes an unattributed cost driver in shared environments

A session accumulates prompts, tool calls, file reads, diffs, and reasoning traces as work proceeds. As that context grows, performance can degrade and costs can spike, including when the agent restarts work already done. A shared token log records the additional consumption without identifying it as re-expenditure. Progress and repetition become difficult to separate.

The agents respond to context pressure differently. Claude Code uses three-tier progressive compaction, including tool result trimming or microcompact, session-memory compact, and a structured LLM summary. Prompt Cache-friendly strategies are used throughout that process, with no tier of their own. Codex CLI instead uses a single-layer handoff summary. These mechanisms produce different token footprints, but a pooled account does not explain which compaction behavior generated the spend.

Claude Code deliberately maintains prefix stability so later requests can reuse prior caches, while changes to Codex request content after compression can invalidate previous caches. Claude Code saves large successful outputs to a file and gives a 2KB preview and file path, but truncates failing command outputs at the head and tail without saving a file. Codex also truncates at the head and tail, dropping the middle entirely.

Missing context can require another attempt to recover information. That is why long-running agents whose context may reset need a record of their progress outside the context window. In a pooled log, however, an attempt to recover that information adds to the token count without showing why the task cost more.

What sandboxing actually does to the cost boundary — and what it does not do today

Sandboxing is usually discussed as a security control, but it also defines where a task’s execution begins and ends. For attribution, that boundary becomes useful when the environment belongs to one task and is not reused across tasks. Security isolation alone is not enough. When jobs share a sandbox one after another, it can still be unclear which costs belong to which job, just as an agent’s own credential can identify it without identifying each task in its session.

The distinction between cloud execution and CLI sandboxing is important here. Codex CLI has default-on isolation through bubblewrap and seccomp on Linux, with Landlock now a legacy opt-in fallback. Claude Code uses opt-in Bubblewrap and socat on Linux or Seatbelt on macOS. Most Claude Code deployments, including most CI/CD integrations, run completely unsandboxed. A worktree can separate local code changes, but it does not by itself establish the full ephemeral environment required for task-level cost isolation.

Per-agent credential scoping gives each agent its own identity and is a prerequisite for granular attribution. It still leaves task-boundary ambiguity inside a shared session. The recommended CI/CD pattern closes that gap by creating a sandbox for the specific PR or task with a snapshot of the relevant code. The agent runs there, and its diff, test results, and generated files are captured before destruction. The environment is then destroyed, wiping its state, and is never reused across tasks.

Task isolation as a first-class primitive — one agent run, one sandboxed environment, one cost unit

Diagram: One Run, One Sandboxed Environment, One Cost Unit. Visualizes: Visualize the structural requirement for reliable agent cost attribution as a linear flow of four linked primitives: (1) Ephemeral Environment — scoped to one task, never…

Each task runs in an ephemeral environment that cannot receive state from a prior or concurrent task, so its consumption has a stable execution boundary. That is the structural requirement behind reliable attribution. Credentials identify the agent, and task records connect the run to its user and team, while isolation prevents shared execution state from blurring those relationships.

Codex cloud’s container-per-task model supplies this boundary natively. Each container holds one task and counts as one cost unit, with no unrelated work in the same session. Claude Code requires deliberate provisioning to achieve the equivalent structure. A pre-loaded VM or container scoped to the task gives it the team’s dependencies and tooling, allowing it to install packages, run services, and verify its work without touching a shared environment. Both agents can then operate simultaneously without sharing the unit to which spend is assigned.

A Codex cloud run and a Claude Code session can each be associated with a specific harness, model, and credential, then compared on matched task types. They still differ in their cache strategies and how they manage context.

Isolation does impose costs of its own, including provisioning latency and container overhead. It also changes Claude Code’s local-filesystem advantage by moving execution into a task-scoped environment. Pre-loading dependencies and tooling at environment creation eliminates the repeated installation overhead that would otherwise accumulate across sequential tasks on the same repository.

What reliable attribution unlocks for teams running both agents at scale

Once each run has its own cost unit, engineering leaders can link the tokens used to what actually shipped. They can compare Claude Code and Codex on the same class of task rather than comparing undifferentiated account totals. Finance gains a record it can audit. The useful dimensions include the task’s source, harness, model, and credential, with user and team ownership attached to the run.

This is an architectural capability. The evidence of adoption used here came with no enterprise attribution data, so it does not show how much was saved or what each team spent based on audited records. The gap is significant. Running agents at scale does not, by itself, show that an organization can explain their spend. Isolation establishes the boundary needed for that explanation, while the associated records must still connect consumption to ownership and output.

Reliable attribution also allows teams to change harnesses without losing the cost history. When spend is pooled, a mid-quarter switch introduces another ambiguity into comparisons across time. When each run retains its task and harness identity, teams can swap agents task by task as better models ship. The environment remains the consistent unit even when the software inside it changes.

Cost and quality alerts become more actionable for the same reason. An alert routed through Slack, PagerDuty, or a custom HTTP endpoint can include the affected task, harness, model, and trace. That context gives the recipient a specific run to investigate. It connects the financial signal to the engineering work responsible for it.

How to track each engineer’s agent runs and costs in existing workflows

The practical upgrade path starts with per-task credential scoping, giving each agent its own API key or credential. Teams should then add ephemeral VM or container provisioning per task to close the environmental boundary. Task IDs must pass through to the billing layer so every token maps to a source, harness, model, and credential. Ownership must remain attached to that task.

Codex cloud’s documentation lists GitHub, Linear, and Slack integrations, with GitLab available in beta, allowing delegated tasks to start isolated containers. Claude Code integrates with GitHub through @claude mentions on PRs and issues and runs on GitHub-hosted runners. A runner is a natural isolation unit when provisioned fresh per job. The trigger identifies the work, while the fresh environment contains its execution.

For tasks assigned through Slack or Linear, cost and quality alerts should return to the same channels with the harness, model, task ID, and token spend. MCP connections to internal tools such as Linear, Sentry, and the deployment system can also be scoped per environment. That scope prevents one task’s tool calls from contaminating another’s context or cost boundary. Attribution then follows the work through assignment, execution, and reporting.

Teams that need both agents without committing to either can use a cloud agent platform that provisions isolated environments on demand, routes tasks to the appropriate harness, and exposes per-run attribution analytics. The selection criterion is whether every invocation receives a fresh environment, retains its ownership and billing identity, and ends with captured artifacts and destroyed state. That makes the environment the stable accounting primitive, independent of the model or harness running inside it.

Sources

  1. AI Coding Agents: Adoption Trends - The JetBrains Blog

More in Parallel Agent Workflows