CLAUDE_CODE_SUBAGENT_MODEL
Updated by Alex Sorokoletov
CLAUDE_CODE_SUBAGENT_MODEL sets the fallback model for subagents, agent team teammates and workflow agents that get no model from the Agent call or their definition. Default: unset, so subagents inherit the main conversation's model. Values: an alias (sonnet, opus, haiku, fable) or a full model ID; inherit is the same as unset. Present since v2.1.69 or earlier and still present in v2.1.332. It is listed in the official reference.
| Status | Present in v2.1.332 |
|---|---|
| Added | Present since v2.1.69 or earlier |
| Default | unset, so subagents inherit the main conversation's model |
| Values | an alias (sonnet, opus, haiku, fable) or a full model ID; inherit is the same as unset |
| Category | Agents and subagents |
| Official docs | Listed |
| Checked against | v2.1.330 |
How to set it
For one session, export it in the shell that starts Claude Code:
export CLAUDE_CODE_SUBAGENT_MODEL=haiku
claudeHaiku runs subagents that set no model of their own on Haiku to cut cost.
To apply it to every session, add it to the env object of a settings file:
// ~/.claude/settings.json
{
"env": {
"CLAUDE_CODE_SUBAGENT_MODEL": "haiku"
}
}Known issues
- Since v2.1.251 a model Claude passes on the Agent call and a model field in the agent definition, including inherit, both win over this variable. Set CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1 (v2.1.257+) to force one model on every subagent. Source: docs: subagents.
- Setting it alone does not change the built-in Explore and Plan subagents, which name their own model. Source: docs: subagents.
- An open report says the value from the settings env block was ignored in a v2.1.263 -p run while the same value from the shell worked; check the subagent transcript's model field to confirm. Source: issue #43869.
Release notes that mention it
- Claude Code v2.1.85 — 6 New Environment Variables: MCP Server Config and a 7 MB Diet
- Claude Code v2.1.84 — 6 New Environment Variables: Idle Management and Stream Resilience
- 83 Undocumented Claude Code Environment Variables (v2.1.19)
Related variables
CLAUDE_CODE_SUBAGENT_MODEL_FORCECLAUDE_CODE_WORKFLOW_SUBAGENT_MODEL: Runs every workflow agent on the named model while other subagents keep their own.CLAUDE_CODE_COORDINATOR_FORCE_WORKER_INHERIT_MODEL: When set, subagent workers ignore any model parameter and inherit the session model; the model option is dropped before launch.CLAUDE_CODE_DISABLE_SUBAGENT_HANDBACK: When set, turns off subagent handback; when unset, the value falls back to CLAUDE_CODE_SENDMESSAGE_HANDBACK and then to a server-side setting.CLAUDE_CODE_ENABLE_APPEND_SUBAGENT_PROMPT: Authorizes SDK callers to append a custom string to a subagent's system prompt via options.appendSubagentSystemPrompt.CLAUDE_CODE_FORK_SUBAGENT: Fork subagents (subagent_type "fork") start with the full parent conversation and are on by default: in the terminal, and from v2.1.302 in claude -p, the Agent SDK, the desktop app and VS Code.CLAUDE_CODE_FORWARD_SUBAGENT_TEXT: Includes subagent text and thinking in stream-json output, paired with a new --forward-subagent-text flag.CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH: Nesting-depth cap on delegation, default 1 — subagents no longer spawn their own subagents, and the team roster stays flat.
Frequently asked questions
What does CLAUDE_CODE_SUBAGENT_MODEL do?
Sets the fallback model for subagents, agent team teammates and workflow agents that get no model from the Agent call or their definition.
What is the default value of CLAUDE_CODE_SUBAGENT_MODEL?
Unset, so subagents inherit the main conversation's model.
What values does CLAUDE_CODE_SUBAGENT_MODEL accept?
An alias (sonnet, opus, haiku, fable) or a full model ID; inherit is the same as unset.
Which Claude Code version has CLAUDE_CODE_SUBAGENT_MODEL?
Present since v2.1.69 or earlier and still present in v2.1.332.
How do I set CLAUDE_CODE_SUBAGENT_MODEL?
Export it before starting Claude Code (export CLAUDE_CODE_SUBAGENT_MODEL=haiku), or add it to the "env" object in ~/.claude/settings.json to apply it to every session. Haiku runs subagents that set no model of their own on Haiku to cut cost.
All variables, searchable: Claude Code environment variables.