`--model` CLI flag silently ignored when ~/.claude/settings.json has a model key
Summary
When ~/.claude/settings.json contains a "model" key, the --model CLI flag is silently ignored. The settings.json model takes priority, which is the opposite of the documented precedence order.
Documented behavior
From the settings documentation, the precedence order (highest to lowest) is:
- Managed policy
- Command line args (
--model) - Local (
.claude/settings.local.json) - Project (
.claude/settings.json) - User (
~/.claude/settings.json) — lowest
Actual behavior
~/.claude/settings.json overrides --model. The CLI flag is accepted without error but has no effect.
Reproduction
# 1. Set model in global settings
# (or use /model in any session, which writes to settings.json)
cat ~/.claude/settings.json | jq '.model'
# => "claude-opus-4-6"
# 2. Run with --model specifying a different model
claude --model claude-sonnet-4-6 -p "What model are you?" --output-format stream-json
# 3. Check the init event in the output
# Expected: "model": "claude-sonnet-4-6"
# Actual: "model": "claude-opus-4-6"
Additional note: /model writes globally
The /model slash command updates ~/.claude/settings.json, which affects all sessions — not just the current one. Combined with the priority bug above, changing your model in one interactive session silently changes the model for every other running or future session, including programmatically spawned agents using --model.
Impact
We run an orchestrator that spawns Claude Code agents with --model claude-sonnet-4-6. Because ~/.claude/settings.json had "model": "claude-opus-4-6" (set via /model in an interactive session), every spawned agent silently used Opus instead of Sonnet. This went undetected because:
- The
--modelflag was accepted without warning - The agent's
system/initJSON event showed the actual model (claude-opus-4-6), but the caller had no reason to check — it trusted the flag it passed - The result was ~330 agents running on Opus in 5 hours, exhausting the 5-hour rate limit
Suggested fix
- Primary:
--modelCLI flag should overridesettings.json, matching the documented precedence - Nice to have:
/modelshould only affect the current session, not write to the globalsettings.json(or offer a--session-onlyoption) - Nice to have: If
--modelis passed but overridden by settings, emit a warning in the output stream
Workaround
Setting the ANTHROPIC_MODEL environment variable before spawning appears to work as an override, but it's unclear where this falls in the documented precedence order.
Environment
- Claude Code version: 2.1.70
- Platform: macOS (Darwin 25.3.0)
- Auth: OAuth
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗