claude-code - 💡(How to fix) Fix [BUG] Resume session overwrites settings.json model[1m] with API-returned model ID — loses 1M context window

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

Root cause (from binary reverse-engineering of v2.1.146):

Fix Action

Fix / Workaround

Workaround

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report
  • I am using the latest version of Claude Code

What's Wrong?

When resuming a session, Claude Code extracts message.model from the last assistant message in the conversation history. The API naturally returns model IDs without the [1m] context window suffix (e.g. claude-opus-4-6 instead of claude-opus-4-6[1m]). This bare model ID is then set as mainLoopModelOverride, overriding the [1m] variant configured in settings.json.

Root cause (from binary reverse-engineering of v2.1.146):

The function responsible is Bk_ (decompiled name), called during session restore:

// Pseudocode reconstructed from binary
function Bk_(messages) {
  // Guard: only skip if runtime override OR env var is set
  if (getMainLoopModelOverride() || process.env.ANTHROPIC_MODEL ||
!isFirstParty()) return;

  // Walk messages backwards, find last assistant message's model
  for (let i = messages.length - 1; i >= 0; i--) {
    let msg = messages[i];
    if (msg?.type !== "assistant" || msg.isMeta) continue;
    let model = msg.message.model;  // ← API returns "claude-opus-4-6" (no
[1m])
    // ... validity checks ...
    return model;  // Returns bare model ID
  }
}

// Caller in session restore:
let model = Bk_(savedMessages);
if (model) setMainLoopModelOverride(model);  // ← Overwrites settings [1m]
variant

v2.1.144 regression: The guard was changed from "skip if any model setting
exists" to "skip only if CLI --model was passed". This was part of the /model
session-only change. Side effect: settings.json model with [1m] suffix is no
longer protected from being overwritten by the API's bare model ID on resume.

A separate normalizer function ZX(H) = H.replace(/\[(1|2)m\]/gi, "") strips
context window suffixes during canonical comparison, so Bk_ considers
claude-opus-4-6 and claude-opus-4-6[1m] as "the same model" and happily
overwrites.

What Should Happen?

When resuming a session, if settings.json specifies a model with [1m] suffix
and the API-returned model is the same base model (just without [1m]), the
settings value should be preserved. The [1m] suffix should not be silently
dropped.

Suggested fix options:
1. Bk_ guard should also check settings.modelif settings already specifies
a model, don't override from message history
2. Or: when Bk_ returns a model, check if the configured model (from
settings/initialMainLoopModel) has a [1m] suffix for the same canonical model,
 and preserve the [1m] variant
3. Or: restore the pre-v2.1.144 guard behavior for the [1m] suffix case
specifically

Steps to Reproduce

1. Set "model": "claude-opus-4-6[1m]" in ~/.claude/settings.json
2. Start a new session, verify 1M context with /context
3. Close the session
4. Resume the session with --resume or --continue
5. Run /context — observe model is claude-opus-4-6 (200k), not
claude-opus-4-6[1m] (1M)

Workaround

Set ANTHROPIC_MODEL environment variable — Bk_'s guard checks it and skips the
 override:

// ~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_MODEL": "claude-opus-4-6[1m]"
  },
  "model": "claude-opus-4-6[1m]"
}

Claude Model

Opus 4.6 (1M context)

Is this a regression?

Yes — introduced in v2.1.144

Last Working Version

v2.1.143

Claude Code Version

2.1.146

Platform

Anthropic (First Party)

Operating System

macOS (Darwin 24.5.0)

Terminal/Shell

zsh

Additional Information

Related issues (all closed as duplicate or stale, none fixed):

- #50803[1m] suffix stripped by --model flag (still open, stale)

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] Resume session overwrites settings.json model[1m] with API-returned model ID — loses 1M context window