Claude Code cost cheat sheet: settings, env vars and commands
Downshift by Tiago Vilas Boas. Updated
Downshift here is a Go tool for AI coding agents, not the React downshift autocomplete library and unrelated to any car transmission.
TL;DR
The biggest cost levers are /clear between tasks, the right model per job, a cheaper model for mechanical subagents, a lower effort level and a smaller auto-compact window. This page lists the exact command, settings key or variable for each, with the doc section that defines it, then shows the one gap the docs leave manual: choosing the subagent model per task.
Every cost lever in Claude Code that Anthropic documents, in tables, each with a link to the doc section. Names that are not in the official docs are not listed.
Checked on 2026-10-24 against code.claude.com/docs. Names, defaults and minimum versions change between releases, so confirm with the linked page.
Which Claude Code commands change cost?
Slash commands and shortcuts that change what you send, which model answers or how much context stays.
| Name | Effect | Docs |
|---|---|---|
/usage | Session token use and estimated cost, the Prompt cache (main) line, and on a plan the usage breakdown with recommendations. | costs: /usage |
/clear | Starts fresh. The docs say to use it when you switch to unrelated work, because stale context wastes tokens on every later message. | costs: manage context |
/compact [instructions] | Summarizes the conversation. Instructions such as 'Focus on code samples and API usage' steer what is kept. It is itself a large request on a big context. | costs: manage context |
/context | Shows what is consuming context space, for example MCP tool listings. | costs: MCP overhead |
/model [alias|name] | Switches the model mid-session. With no argument it opens the picker. Each model has its own cache, so a switch reads the history uncached. | model-config |
/effort [level|auto] | Sets the effort level. Lower effort for simple tasks reduces thinking tokens, which are billed as output. | model-config: effort |
/autocompact [size|auto] | Sets the auto-compact window for the current model. | model-config: auto-compact |
/mcp | Lists configured MCP servers so you can disable the ones you do not use. | costs: MCP overhead |
/rewind | Restores conversation and code to an earlier checkpoint. Rewinding hits an earlier cache entry instead of building a new prefix. | prompt-caching: rewind |
/insights | Writes an HTML report on how you work from recent sessions. The analysis itself uses tokens. | costs: insights |
Shift+Tab | Cycles to plan mode so Claude proposes an approach before it edits. | costs: complex tasks |
Which settings keys reduce Claude Code cost?
Keys for settings.json. Environment variables in the next section override some of them.
| Name | Effect | Docs |
|---|---|---|
model | Initial model when a session starts. It is a default, not enforcement. | model-config |
effortLevel | Default effort for models without a saved level: low, medium, high or xhigh. | model-config: effort |
modelSettings | Per-model saved values, including effort and the auto-compact window. | model-config: effort |
autoCompactWindow | Auto-compact token window for all models. | model-config: auto-compact |
alwaysThinkingEnabled | Saved global thinking toggle, set through /config. Thinking cannot be turned off on Opus 5.5, Sonnet 5.5, Haiku 5.5 or Fable. | costs: thinking |
availableModels | Allowlist of models users can select, so a team cannot drift to the most expensive one. | model-config: restrict |
promptCacheTtl | Main conversation cache lifetime: 5m or 1h (v2.1.242 or later). | prompt-caching: TTL |
subagentPromptCacheTtl | Cache lifetime for subagents and other non-main requests: 5m or 1h (v2.1.242 or later). | prompt-caching: TTL |
idleCompaction | Set to false to stop Claude Code compacting an idle long conversation before the cache expires (v2.1.290 or later). | prompt-caching: compaction |
Which environment variables control Claude Code cost?
Put these in your shell or in the env block of settings.json. The full list is on the official environment variables page.
Model and effort
| Name | Effect | Docs |
|---|---|---|
ANTHROPIC_MODEL | Session model. Overrides the model setting; --model and /model override it. | model-config |
ANTHROPIC_DEFAULT_OPUS_MODELANTHROPIC_DEFAULT_SONNET_MODELANTHROPIC_DEFAULT_HAIKU_MODEL | Model ID each alias resolves to. The haiku one also serves background functionality. | env-vars |
CLAUDE_CODE_EFFORT_LEVEL | Effort: low, medium, high, xhigh, max or auto. Overrides --effort, /effort and the settings. | model-config: effort |
MAX_THINKING_TOKENS | Fixed thinking budget on models that use one, for example 8000. 0 turns thinking off on most API models. Adaptive-reasoning models ignore nonzero values; use effort there. | costs: thinking |
CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING | Set to 1 on Opus 4.6 and Sonnet 4.6 only: falls back to the MAX_THINKING_TOKENS budget. | model-config: adaptive |
CLAUDE_CODE_DISABLE_1M_CONTEXT | Set to 1 to remove 1M-context variants; models that default to 1M drop to 200K. | model-config: 1M |
Subagents
| Name | Effect | Docs |
|---|---|---|
CLAUDE_CODE_SUBAGENT_MODEL | Default model for subagents and teammates. It ranks below the per-call model and the agent's model field, unless forced (next row). | sub-agents: choose a model |
CLAUDE_CODE_SUBAGENT_MODEL_FORCE | Set to 1 (v2.1.257 or later) to make CLAUDE_CODE_SUBAGENT_MODEL override every other source, including the model frontmatter. | sub-agents: one model |
CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS | Cap on concurrent subagents per session (default 20). | env-vars |
CLAUDE_CODE_MAX_TURNS | Caps agentic turns when --max-turns is not passed. | env-vars |
Compaction and output size
| Name | Effect | Docs |
|---|---|---|
CLAUDE_CODE_AUTO_COMPACT_WINDOW | Auto-compact window, 100000 to 1000000 tokens. Overrides /autocompact, --autocompact and autoCompactWindow. | model-config: auto-compact |
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE | Percentage (1 to 100) of the window at which compaction triggers. It can only lower the threshold, and it applies to subagents too. | env-vars |
CLAUDE_CODE_MAX_OUTPUT_TOKENS | Maximum output tokens per request. Higher values shrink the context left before auto-compaction. | env-vars |
BASH_MAX_OUTPUT_LENGTH | Characters of Bash output read back into a result (default 30000, max 150000). | env-vars |
CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS | Token limit for file reads (default 25,000). | env-vars |
Prompt cache
| Name | Effect | Docs |
|---|---|---|
CLAUDE_CODE_PROMPT_CACHE_TTL | Main conversation cache lifetime, 5m or 1h (v2.1.242 or later). | prompt-caching: TTL |
CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL | Cache lifetime for subagents, workflows, teammates and compaction requests, 5m or 1h. | prompt-caching: TTL |
DISABLE_PROMPT_CACHING | Set to 1 to disable caching for all models. The docs call this a debugging tool; for normal use leave caching on. | prompt-caching: disable |
How do I set the subagent model in Claude Code?
Claude Code picks a subagent's model in this order, per the docs: the model Claude passes for that call, then the agent's model frontmatter (where inherit means the main model), then CLAUDE_CODE_SUBAGENT_MODEL, then the main conversation's model. Before v2.1.251 the variable came first.
| Name | Effect | Docs |
|---|---|---|
model: haiku | Frontmatter field in an agent definition. Accepts sonnet, opus, haiku, fable, a full model ID or inherit. The cost page suggests haiku for simple subagent tasks. | sub-agents: choose a model |
model: inherit | Uses the main conversation's model. | sub-agents: choose a model |
Agent named Explore | A user or project agent with that name and model: haiku replaces the built-in Explore, which otherwise follows the main model. | sub-agents: choose a model |
| Env block with force | Set CLAUDE_CODE_SUBAGENT_MODEL and CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1 to run every subagent on one model. Setting the first alone does not change the built-in Explore or Plan. | sub-agents: one model |
Which habits cut Claude Code cost per task?
From the cost page, in the order that tends to matter.
| Name | Effect | Docs |
|---|---|---|
| Run focused tests, not the whole suite | Ask for the one test file or test name. Incremental testing catches problems early, and long output stays out of context. | costs: complex tasks |
| Smaller model for mechanical subagents | Renames, formatting and file lookups rarely need the main model. Use model: haiku on the agent, or CLAUDE_CODE_SUBAGENT_MODEL. | costs: right model |
| Delegate verbose work | Tests, doc fetches and log reading return a summary while the output stays in the subagent's context. The subagent's own requests still draw on your usage. | costs: subagents |
| Write specific prompts | Naming the file and function avoids broad scanning. | costs: prompts |
| Plan first on complex work | Plan mode prevents expensive rework when the first direction is wrong. | costs: complex tasks |
| Keep CLAUDE.md short | It loads at every session start. Move workflow-specific instructions to skills, which load on demand. The docs aim for under 200 lines. | costs: skills |
| Pick model and effort once | Changing the model or, on most models, the effort mid-session makes the next request read the whole history uncached. | prompt-caching: switching |
What does Downshift add to these settings?
Everything above is manual and uses no extra software. Downshift automates the one choice the tables leave to you, and it keeps the numbers honest.
| Part | What it does | Evidence and limits |
|---|---|---|
| Per-subagent routing | A PreToolUse hook scores each delegated task locally and rewrites the subagent's model, only when confident. Doubt keeps the model you asked for. No LLM runs in the routing loop. | Four-arm battery 2026-10-21, mechanical delegated tasks, 46 runs, one operator: about 24% fewer tokens per accepted task with routing (16% per run; 95% interval +2.1% to +46.7%). Not shown on natural complex tasks. |
| Compactor | downshift compact -- <command> cuts allowlisted test and build output to the pass or fail summary and keeps the real exit code. | Compaction corpus 2026-10-21, synthetic fixtures: 82.3% fewer bytes on the 26 of 248 files that compact, 23.7% across all 248. Bytes, not LLM tokens. |
| DCI (opt-in) | Packs only the code a change touches, under a byte budget. | Off until you enable it. Latency and output size are measured; answer quality is not validated. |
Full numbers: four-arm evidence file. One operator, mechanical tasks: treat it as a measurement, not a guarantee.
Frequently asked questions
What is the fastest way to reduce Claude Code cost?
Run /usage to see where tokens go, use /clear between unrelated tasks, pick Sonnet or Haiku where Opus is not needed, and lower the effort level for simple work. Set model: haiku on subagents that do mechanical tasks. All of this is in Anthropic's cost page.
Which environment variable sets the subagent model?
CLAUDE_CODE_SUBAGENT_MODEL sets a default for subagents. Since v2.1.251 it ranks below the model Claude passes for the call and the agent's model frontmatter. Add CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1 (v2.1.257 or later) to make it override every source.
How do I make auto-compact trigger earlier?
Set CLAUDE_AUTOCOMPACT_PCT_OVERRIDE to a percentage from 1 to 100; it can only lower the threshold. Or set the window directly with CLAUDE_CODE_AUTO_COMPACT_WINDOW, the autoCompactWindow setting or /autocompact.
Does switching model or effort mid-session cost extra?
Yes. Each model has its own cache, so /model makes the next request read the whole history uncached. On most models a mid-session effort change does too; the docs say Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable 5.1 keep the cache on an API key or subscription.
Is every variable on this page in the official docs?
Yes. Anything not found on code.claude.com/docs was left out, and each row links to its section. Checked on 2026-10-24. Defaults and minimum versions change, so confirm with the link before you rely on one.
Does Downshift replace these settings?
No. It adds per-task subagent model routing and output compaction on top of them. Its measured gain is about 24% fewer tokens per accepted task on mechanical delegated tasks (46 runs, one operator, 2026-10-21), and it was not tested combined with the other levers.
Install Downshift
Run downshift setup --dry-run first to preview every change. downshift setup --undo restores your backups.
curl -fsSL https://raw.githubusercontent.com/tiagovilasboas/downshift/main/install.sh | sh && downshift setupClaude Code plugin
/plugin install downshift --marketplace tiagovilasboas/downshiftRelated guides
- Claude Code token optimization: levers ranked by evidence
- Claude Code subagent models: how the model is chosen
- Claude Code prompt cache: TTL, cold sends and keeping warm
- Guia rápido de custo do Claude Code: settings, variáveis e comandosPortuguês
- Install Downshift: Claude Code, Codex and Cursor hook setup
Sources
- Anthropic docsofficial
code.claude.com/docs/en/costs
/usage, reduce token usage, thinking, subagents (fetched 2026-10-24) - Anthropic docsofficial
code.claude.com/docs/en/model-config
aliases, settings keys, effort, auto-compact window (fetched 2026-10-24) - Anthropic docsofficial
code.claude.com/docs/en/sub-agents
model field, precedence, CLAUDE_CODE_SUBAGENT_MODEL(_FORCE) (fetched 2026-10-24) - Anthropic docsofficial
code.claude.com/docs/en/prompt-caching
TTL controls, disable variables, model and effort switches (fetched 2026-10-24) - Anthropic docsofficial
code.claude.com/docs/en/env-vars
autocompact, effort, thinking, output limits, subagent caps (fetched 2026-10-24) - Downshift repomeasured
docs/evidence/four-arm-mechanical-2026-10-21.md
four-arm figures, interval, limits