Coding agents
Claude Code, Codex and Antigravity
Coding agents already record every model call they make. AgentCost reads that record, so their sessions show up next to the rest of your LLM spend with no instrumentation, and your guardrails can stop a call before it runs instead of reporting it afterwards.
Connect a machine
One command per agent, once per machine. It imports the last 30 days and installs a hook, so each finished turn is sent as it happens, from any folder, in the terminal, the IDE extension or the desktop app.
pip install agentcost
agentcost sync --dry-run # look first: no key, nothing sent
agentcost connect claude-code --api-key sk_your_project_api_key
agentcost connect codex
agentcost connect antigravityCodex asks you to trust a new hook: open Codex and run /hooks once. Antigravity has no hooks, so its usage is sent whenever another connected agent syncs, or when you run agentcost sync on a schedule.
What you get
A session is a run. Open one to see every call in it, or group spend by model, tool, subagent, session or developer.
| Claude Code | Codex | Antigravity | |
|---|---|---|---|
| Cost per session, model and developer | Yes | Yes | Estimated |
| Cost per tool | Yes | Yes | No |
| Subagents as their own agents | Yes | When the log names them | No |
| Syncs by itself after every turn | Yes | Yes, once the hook is trusted | With another agent, or on a schedule |
| OpenTelemetry, nothing installed | Yes | Yes | No |
| Tool and model boundaries enforced | Yes | Yes | No |
| Per-run limits and budget enforced | Yes | Yes | No |
Subscriptions are not spend
On a Claude or ChatGPT plan, or in Antigravity, nothing is billed per token. Those calls are still priced, so you can see what the usage is worth at API rates, but each one is marked billing: subscription and is left out of your budget, its alerts and its hard cap. The overview shows the two apart. Usage on an API key is metered and counts as spend.
Enforce guardrails
Add --enforce and a second hook, the gate, runs before every tool call and every prompt. It refuses what the project does not allow and tells the agent why.
agentcost connect claude-code --enforceIt enforces the guardrail you declare for the agent named claude-code or codex on the Guardrails page. A subagent answers to claude-code/<type> if you declare one, and to the main agent otherwise.
- Allowed tools
- A tool that is not on the list is refused.
- Read-only
- A tool tagged as writing is refused.
- Allowed models
- Tool calls and prompts are refused while the session is on a model that is not on the list.
- Max tool calls per run
- Further tool calls in that session are refused.
- Max cost per run
- Further tool calls and prompts in that session are refused.
- Monthly budget, hard cap
- New prompts are refused once it is spent. Metered usage only, never a subscription.
The gate never calls the network. It decides from a policy the sync keeps current and from the session's own log, adds about a fifth of a second to a tool call, and applies a changed guardrail from the next turn. When it cannot decide, it allows the call.
A whole organisation, with nothing installed
Claude Code and Codex can export their own telemetry. Point it at AgentCost from managed settings and every session reports in, including ones that run in the cloud and leave no local log. Only the per-call usage records are read; prompts, tool results and everything else in the export are discarded unread.
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_METRICS_EXPORTER": "none",
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
"OTEL_EXPORTER_OTLP_ENDPOINT": "https://api.agentcost.tech/v1/otlp",
"OTEL_EXPORTER_OTLP_HEADERS": "Authorization=Bearer sk_your_project_api_key",
"OTEL_RESOURCE_ATTRIBUTES": "agentcost.billing=subscription"
}
}[otel]
exporter = { otlp-http = {
endpoint = "https://api.agentcost.tech/v1/otlp/v1/logs",
protocol = "json",
headers = { "Authorization" = "Bearer sk_your_project_api_key" }
}}State how the usage is paid for with agentcost.billing=subscription or api; Claude Code does not say, and unstated usage counts as metered. A machine that reports both ways is counted once. This path tracks only: enforcement needs the hook.
Let the agent read its own spend
Add the MCP server with your project key and the agent can check the budget, or what a run cost, before it starts something expensive.
claude mcp add --transport http agentcost https://agentcost.tech/api/mcp \
--header "Authorization: Bearer sk_your_project_api_key"What leaves the machine
Token counts, model, tool names, session id and timestamps. Prompts, replies, tool arguments and tool output are never sent or kept. The working folder's name and git branch are sent only if you pass --include-repo, and never the path or the remote URL.
Related: CLI reference · MCP server · Data & privacy