langwatch/langwatch/coding-agent-cost
- community
Checking that the SKILL.md file is still in the repository.
Reads your Claude Code sessions in LangWatch and recommends the settings that cut their cost and context, each with the evidence from your own data, the exact settings.json change and the expected saving marked as measured or estimated. Covers older model versions, the auto-compact window, the prompt cache lifetime for API-key and subscription users, the model your built-in sub-agents run on, and sessions that should have been split. Use when someone asks why their coding agents cost so much, how to make a Claude Code plan last longer, or which Claude Code settings to change.
Install
npx vskill@latest install langwatch/langwatch/coding-agent-costSKILL.md
Cut Your Coding Agent's Cost and Context
This skill reads the user's own Claude Code sessions from LangWatch, runs one check per recommendation below, and reports only the recommendations their data supports. Every recommendation names the evidence, the exact setting and an expected saving, and says whether that saving was measured in a controlled run or estimated from token counts. It is read-only on the platform and leaves one report file behind.
Step 1: Set up the LangWatch CLI
Use the langwatch CLI for everything: documentation (langwatch docs ..., langwatch scenario-docs ...) and platform operations (prompts, scenarios, evaluators, datasets, monitors, traces, analytics). Install it once with npm install -g langwatch, then run the langwatch binary directly; an unpinned npx langwatch re-resolves the package from the registry on every run.
Coding-agent sessions live in the user's personal LangWatch workspace by default. langwatch login --device signs this machine in; add --project <slug> on every read command when the sessions live in a team project instead.
Step 2: Find Out How the User Pays
The same tokens mean different things to different users, so settle this before any number goes in the report.
- Claude subscription (Pro, Max, Team, Enterprise seats): no per-token bill. A saving means more work before the plan's usage limits, not cash. Show USD as "API-equivalent usage" in brackets.
- API key, Amazon Bedrock, Google Cloud, Microsoft Foundry, or a subscription drawing on usage credits: every token is billed. A saving is cash.
Ask the user, or check on their machine: run claude -p "hello" --output-format json and read usage.cache_creation. One-hour writes (ephemeral_1h_input_tokens above zero) on that main-conversation request mean a subscription within plan usage. Five-minute writes (ephemeral_5m_input_tokens) mean an API key, a cloud provider or usage credits. Check 5 below also reads this from the data.
Step 3: Pull the Data
Every query below is LangWatchQL, run with langwatch query run "<sql>" -o json. Run langwatch query schema once to confirm the column names. Use one window everywhere, 30 days unless the user names another, and aggregate in SQL: a result is capped at 10,000 rows.
langwatch.coding_session_events holds one row per event. Model calls have EventKind = 'model_call' with Model, InputTokens, OutputTokens, CacheReadTokens, CacheCreationTokens, CostUsd, TimeUnixMs and QuerySource. QuerySource tells threads apart: repl_main_thread% or sdk is the main conversation, agent:builtin:<type> and agent:custom are sub-agents, agent_summary is a sub-agent's final report, compact is a compaction. The context a call carried is InputTokens + CacheReadTokens + CacheCreationTokens.
Without --project, a query reads every project the login can reach, so check the scope first:
If more than one project comes back, ask whether the report covers the user's own sessions or the whole team. For one project, add AND TenantId = '<id>' to every query below; the user's own id is personal_project.id in langwatch whoami; if that field is missing, ask the user which project id to use.
If the report window has no model_call rows, run SELECT count() AS events, max(TimeUnixMs) AS newest FROM langwatch.coding_session_events WHERE EventKind = 'model_call' inline (not a sql fence) for the newest event in any window, adding AND TenantId = '<id>' when the report covers one project. events = 0 means no Claude Code model call is stored for the report's scope (one project, or the whole team), so there is no cost data; otherwise report the age (the newest Claude Code event is from <time>, <age> ago). Name what to check in the Claude Code telemetry setup: CLAUDE_CODE_ENABLE_TELEMETRY=1, OTEL_EXPORTER_OTLP_ENDPOINT pointing at LangWatch, and the project API key in OTEL_EXPORTER_OTLP_HEADERS (Authorization=Bearer <key>). Report that gap instead of the cost checks.
langwatch.coding_sessions holds one row per session, with Title, PeakContextTokens, Compactions, Models, SubAgentTypes, CostUsd, StartedAt and UserId. Use it to name example sessions.
Start with the spend mix:
Fetch Anthropic's current price list (https://platform.claude.com/docs/en/about-claude/pricing) before repricing anything, and cite it with the fetch date. Never price from memory. The multipliers to check there: a five-minute cache write costs 1.25x the base input price, a one-hour write 2x, a cache read 0.1x on most models and less on some newer ones.
Step 4: Run the Checks
Run each check, keep the ones that fire, and price each saving on the user's own tokens. The expected ranges below come from 105 organisations' Claude Code data on LangWatch (30 days, API-equivalent USD). Each is labelled measured (a controlled A/B run on the same tasks) or estimated (the same tokens repriced or re-simulated). Say which one in the report.
1. Older model version
Fires when 1% or more of spend is on a model that has a cheaper successor in the same tier: Opus 5 or Opus 4.5 to 4.8 (successor Opus 5.5), Sonnet 5 or Sonnet 4.x (Sonnet 5.5), Fable 5 (Fable 5.1). Use the spend mix from Step 3.
Saving: reprice the same input, output, cache-read and cache-write tokens at the successor's prices. Cache reads usually dominate coding-agent spend, so the read price difference drives the result. Across organisations where this fires (88% of them) the estimated median is 24% of Claude Code spend, p90 42%. Models from Opus 4.6 back use an older tokenizer that counts fewer tokens for the same text, so the gap for those is smaller than repricing shows.
Measured in a controlled run: on 5 bug-fix tasks (15 runs per model, every hidden test passed with both), Opus 5.5 cost 63% less than Opus 5 per task (95% CI 56 to 69%). The price list explains about 33 points; the rest came from fewer tokens, with half the cache reads, a third of the output and a median of 17 s per task against 51 s.
Setting: in ~/.claude/settings.json (or managed settings for a team), use the alias instead of a pinned id, and check that no ANTHROPIC_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL or ANTHROPIC_DEFAULT_SONNET_MODEL in the env block pins the old one:
2. Main conversation past 400k tokens of context
Fires when main-thread calls carry more than 400,000 tokens of context. Every call re-reads the whole history from cache, so cost per call grows with context.
Saving: simulate compaction at 400k per session: after compacting, the thread restarts at about 40k tokens and grows again, so a call at context c above 400k would carry about 40000 + ((c - 400000) mod 360000). Saving = removed tokens x read price, minus each compaction (one read of 400k plus about 40k output and 40k write). Estimated median 7% of spend (p90 23%) where it fires, and about 29% on threads that pass 800k.
Measured in a controlled run (4 runs per arm): a session that read 145 files one per turn and peaked at 488k tokens cost 51% less with a 150k window than with the default, with 73% fewer cache reads. The agent then answered 0 of 6 questions about early files, against 6 of 6 without compaction, so do not set the window far below 400k, and expect details from before a compaction to need re-reading.
Setting: in settings.json, and remove any CLAUDE_CODE_AUTO_COMPACT_WINDOW from env blocks first, because the environment variable wins over the setting:
Also: /compact at the end of a task, /clear before an unrelated one.
3. Sub-agents past 600k tokens of context
Fires when sub-agent calls (QuerySource LIKE 'agent%') carry more than 600,000 tokens. Use check 2's query with that filter and the threshold changed. The data has no sub-agent id, so count calls, not threads.
Saving: the same simulation. Estimated 35% of what those sub-agents cost, but only 18% of organisations that use sub-agents have any, median 2% of total spend. Say "these sub-agents", not "your bill".
Setting: the same autoCompactWindow applies to sub-agents. The other fix is narrower sub-agent tasks, for example one sub-agent per module instead of one for the whole repository.
4. Opus or Fable on built-in sub-agents
Fires when agent:builtin:Explore, agent:builtin:general-purpose or agent_summary calls run on an Opus or Fable model.
Saving: reprice those calls at Sonnet 5.5. Estimated median 4% of spend (p90 19%) where it fires (73% of organisations). Overlaps with check 1 when the sub-agents run an old Opus, so do not add the two. Searching and reading code rarely needs the top model, but say that the user should watch the quality of the sub-agents' reports for a week.
Setting: there is no top-level settings key for this. Set the CLAUDE_CODE_SUBAGENT_MODEL variable in the env block of settings.json. On its own it moves general-purpose and any custom agent without a model: line; Explore and Plan stay on the main conversation's model:
To move Explore and Plan too, add "CLAUDE_CODE_SUBAGENT_MODEL_FORCE": "1" to the same block (Claude Code v2.1.257 or later). It also overrides custom agents' model: lines and the model Claude picks for a single call, so suggest it only when no custom agent needs a stronger model. To move only Explore, the user can define an agent named Explore with model: sonnet in ~/.claude/agents/.
5. API key: the five-minute cache is rebuilt after pauses
Applies only to users who pay per token (Step 2). On an API key, Bedrock, Google Cloud or usage credits, Claude Code caches every request for five minutes. A pause of 5 to 60 minutes (reading a diff, a meeting, a long test run) expires the cache, and the next call writes the whole context again.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/_compiled/native/coding-agent-cost/SKILL.md
Popularity
- Repository stars
- 4,975
- Repository forks
- 416
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/langwatch/langwatch/coding-agent-cost)