CLAUDE_CODE_MAX_TURNS
Updated by Alex Sorokoletov
CLAUDE_CODE_MAX_TURNS is a Claude Code environment variable: Hard cap on conversation turns. The single most important variable in this release for anyone running unattended agents. Set it to 50, 100, or whatever your budget allows — when the session hits the cap, it stops. No more overnight runs that went way further than intended. Added between v2.1.138 and v2.1.143 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.138 and v2.1.143 |
| Category | Other |
| Official docs | Listed |
How to set it
For one session, export it in the shell that starts Claude Code:
export CLAUDE_CODE_MAX_TURNS=<value>
claudeTo apply it to every session, add it to the env object of a settings file:
// ~/.claude/settings.json
{
"env": {
"CLAUDE_CODE_MAX_TURNS": "<value>"
}
}Release notes that mention it
- Claude Code v2.1.143 — 27 New Env Vars, /goal, Agent View, and a Free Model Upgrade
- Claude Code Version Tracker: Undocumented Env Vars, Feature Gates & Models
Related variables
TASK_MAX_OUTPUT_LENGTH: Max output length for Task tool results.CLAUDE_CODE_SILENT_TURN_REMINDER_TURNSANTHROPIC_BETAS: Comma-separated beta feature headers.ANTHROPIC_CUSTOM_HEADERS: Custom HTTP headers (newline-separated Key: Value).ANTHROPIC_FEDERATION_RULE_IDANTHROPIC_ORGANIZATION_IDANTHROPIC_WORKSPACE_IDBETA_TRACING_ENDPOINT: Custom endpoint for beta tracing.
Frequently asked questions
What does CLAUDE_CODE_MAX_TURNS do?
Hard cap on conversation turns. The single most important variable in this release for anyone running unattended agents. Set it to 50, 100, or whatever your budget allows — when the session hits the cap, it stops. No more overnight runs that went way further than intended.
Which Claude Code version has CLAUDE_CODE_MAX_TURNS?
Added between v2.1.138 and v2.1.143 and still present in v2.1.294.
How do I set CLAUDE_CODE_MAX_TURNS?
Export it before starting Claude Code (export CLAUDE_CODE_MAX_TURNS=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.