ANTHROPIC_MODEL env var and --model flag overridden by settings.json mid-session

Resolved 💬 4 comments Opened Mar 25, 2026 by scottyoungwon Closed Apr 24, 2026

Bug

When launching Claude Code with ANTHROPIC_MODEL env var + --model flag to pin a model for a specific terminal tab, the pin does not hold. Another session's /model command writes to ~/.claude/settings.json, and the pinned session re-reads that file and switches its actual API model — even though the env var is still set.

Steps to Reproduce

  1. Open two terminal tabs
  2. Tab A: ANTHROPIC_MODEL="opus[1m]" claude --model "opus[1m]"
  3. Tab B: ANTHROPIC_MODEL="sonnet" claude --model "sonnet"
  4. In Tab B, run /model opus
  5. In Tab A, ask "what model are you?"

Expected: Tab A still uses Sonnet (env var pin holds)
Actual: Tab A reports claude-opus-4-6 — the model changed

Additional Observed Behavior

The /model display and the actual model desync:

  • /model (the autocomplete hint) shows the launch-time model from the env var (e.g., "currently Opus 4.6")
  • But the actual API model switches to whatever was last written to settings.json by any session

So after the steps above, Tab A shows:

  • /model display: "currently Sonnet" (from env var — correct)
  • Assistant self-report: claude-opus-4-6 (from settings.json — wrong)

Why This Matters

Per-tab model isolation is a common workflow: run Opus in one tab for architecture work, Sonnet in another for quick edits. The --model flag is documented as "Model for the current session," implying session-level scope. But settings.json re-reads override it, making per-tab pinning impossible.

Expected Fix

--model flag and ANTHROPIC_MODEL env var should take precedence over settings.json for the entire session, not just at launch. If a user launches with --model sonnet, no external change to settings.json should alter that session's model.

Environment

  • Claude Code v2.1.83
  • macOS (Darwin 23.6.0)
  • zsh

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗