CLAUDE_CODE_MAX_CONTEXT_TOKENS
Updated by Alex Sorokoletov
CLAUDE_CODE_MAX_CONTEXT_TOKENS is a Claude Code environment variable: Sets an explicit ceiling on the context window size used during a session. Rather than relying on the model's default maximum, this variable lets operators cap token consumption — useful for cost-conscious teams, rate-limited API plans, or environments where shorter context windows improve latency. Added between v2.1.96 and v2.1.100 and still present in v2.1.294. It is listed in the official reference.
| Status | Present in v2.1.294 |
|---|---|
| Added | Added between v2.1.96 and v2.1.100 |
| Category | Authentication |
| Official docs | Listed |
How to set it
For one session, export it in the shell that starts Claude Code:
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=<value>
claudeTo apply it to every session, add it to the env object of a settings file:
// ~/.claude/settings.json
{
"env": {
"CLAUDE_CODE_MAX_CONTEXT_TOKENS": "<value>"
}
}Release notes that mention it
- Claude Code v2.1.100 — 3 New Environment Variables: Context Token Limits, Perforce VCS, and Script Capability Controls
- Claude Code Version Tracker: Undocumented Env Vars, Feature Gates & Models
Related variables
CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS: Max tokens for file read output.CLAUDE_CODE_MAX_OUTPUT_TOKENS: Maximum output tokens; validated per-model.MAX_MCP_OUTPUT_TOKENS: Max tokens for MCP tool output.MAX_THINKING_TOKENS: Likely controlled via API settings now.CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS: Sets the minimum conversation size, in tokens, before idle compaction runs.CLAUDE_BG_SOCKET_TOKENS_PATHCLAUDE_CODE_TOTAL_TOKENS_REMINDERCLAUDE_CODE_TOTAL_TOKENS_REMINDER_AFTER_USER_TURN
Frequently asked questions
What does CLAUDE_CODE_MAX_CONTEXT_TOKENS do?
Sets an explicit ceiling on the context window size used during a session. Rather than relying on the model's default maximum, this variable lets operators cap token consumption — useful for cost-conscious teams, rate-limited API plans, or environments where shorter context windows improve latency.
Which Claude Code version has CLAUDE_CODE_MAX_CONTEXT_TOKENS?
Added between v2.1.96 and v2.1.100 and still present in v2.1.294.
How do I set CLAUDE_CODE_MAX_CONTEXT_TOKENS?
Export it before starting Claude Code (export CLAUDE_CODE_MAX_CONTEXT_TOKENS=value), or add it to the "env" object in ~/.claude/settings.json to apply it to every session.
All variables, searchable: Claude Code environment variables.