Agent subprocesses always get 200K context instead of 1M — --model flag bypasses plan entitlement

Status Closed — not planned
Reported on v2.1.87
Maintainer reply None cached
Activity 15 comments · opened Mar 30, 2026 · closed May 28, 2026

Description

When the orchestrator spawns agent subprocesses (teammates/subagents), Claude Code always passes --model claude-opus-4-6 to the subprocess command. This selects the explicit 200K Opus variant instead of the "Default (recommended)" option which is Opus 4.6 with 1M context.

The main/orchestrator session correctly gets 1M context through plan entitlement auto-detection (when no "model" is set in settings.json). But agent subprocesses never get a chance to auto-detect because --model is always injected.

Environment

  • Claude Code v2.1.87
  • Team plan with premium seat
  • macOS (Darwin)

Steps to Reproduce

  1. Remove "model": "opus" from .claude/settings.json (this fixes the main session — it correctly shows "Opus 4.6 (1M context)")
  2. Start a session with Agent Teams enabled (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1)
  3. Spawn any agent (teammate or subagent)
  4. Check the subprocess command — it always includes --model claude-opus-4-6
  5. Run /model inside the agent pane — it shows "Opus 4.6" (option 5) selected, NOT "Default (recommended)" (option 1, which has 1M context)

Subprocess Command

env CLAUDECODE=1 CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 /Users/zain/.local/share/claude/versions/2.1.87 --agent-id alpha\@demo-team --agent-name alpha --team-name demo-team --agent-color blue --parent-session-id 938a1938-a6ed-4df4-a07e-998c7d04c520 --model claude-opus-4-6

Note: --model claude-opus-4-6 is the 200K variant. The 1M variant would be claude-opus-4-6[1m].

/model Menu Inside Agent Pane

1. Default (recommended)    Opus 4.6 with 1M context · Most capable for complex work
2. Sonnet                   Sonnet 4.6 · Best for everyday tasks
3. Sonnet (1M context)      Sonnet 4.6 with 1M context · Billed as extra usage
4. Haiku                    Haiku 4.5 · Fastest for quick answers
5. Opus 4.6 ✓               Newer version available · select Opus for Opus 4.6 (with 1M context)

Option 5 (200K) is selected instead of option 1 (1M).

Related: Settings.json Has the Same Bug (With Known Fix)

Setting "model": "opus" in .claude/settings.json also forces the main session to 200K. Removing the model key entirely fixes it — the main session then auto-detects the plan entitlement and gets 1M. This is documented in #34435.

The agent subprocess issue is the same root cause but has no workaround — Claude Code always injects --model claude-opus-4-6 regardless of whether the orchestrator passes a model parameter.

Expected Behavior

When no explicit model override is requested, agent subprocesses should either:

  • Not pass --model to the subprocess (let it use "Default" = Opus 4.6 with 1M)
  • Pass the 1M-aware model ID (claude-opus-4-6[1m]) when the parent session has 1M context

Workaround Attempted (Did Not Work)

  • Setting ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-6[1m] in settings.json env block — not passed through to subprocess
  • Omitting model parameter in Agent tool calls — Claude Code still injects --model claude-opus-4-6 into subprocess command
  • Removing model from agent definition frontmatter — same result

View original on GitHub ↗

15 Comments

github-actions[bot] · 5 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/34421
  2. https://github.com/anthropics/claude-code/issues/36670
  3. https://github.com/anthropics/claude-code/issues/39047

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

ZainnQureshii · 5 months ago

This is NOT a duplicate of the suggested issues. Here's why:

Tested on v2.1.87 (latest) — all three suggested duplicates are on older versions (v2.1.76, v2.1.80, v2.1.81). The bug persists on the latest version.

Community patches don't work on v2.1.87 — the binary patch from #34421 (gist by keyur2maru) targets minified function names that have changed in v2.1.87. No working workaround exists for the current version.

Additional finding from testing:

  • Standalone subagents (Agent tool without team_name) DO inherit 1M correctly — confirmed claude-opus-4-6[1m] via system prompt
  • Teammates (Agent tool with team_name, spawned via TeamCreate) get 200K — subprocess command always has --model claude-opus-4-6 without [1m]
  • This matches #34421's finding but confirms it's still broken 16 days and 11 versions later

Unique evidence in this issue:

  • Actual subprocess command showing --model claude-opus-4-6 (without [1m])
  • /model menu inside teammate pane showing option 5 (Opus 4.6, 200K) selected instead of option 1 (Default, 1M)
  • Settings.json "model": "opus" also caps the main session to 200K (related but separate angle)
  • All env var workarounds tested and confirmed non-functional (ANTHROPIC_DEFAULT_OPUS_MODEL, CLAUDE_CODE_SUBAGENT_MODEL)

If this is still considered a duplicate of #34421, that issue needs attention — it's been open for 16 days with no official response while the community writes binary patches to work around it.

ZainnQureshii · 5 months ago

Additional testing: all known workarounds fail on v2.1.87

I reviewed all three suggested duplicate issues (#34421, #36670, #39047) in detail and tested every workaround mentioned across their threads. None work on the current version.

Workarounds tested and results:

| Workaround | Source | Result on v2.1.87 |
|------------|--------|-------------------|
| Binary patch (gist by @keyur2maru) | #34421 | Failed — minified function names changed between v2.1.76 and v2.1.87, patch targets don't exist |
| ANTHROPIC_DEFAULT_OPUS_MODEL=claude-opus-4-6[1m] env var | #36670 | Failed — env var is not passed through to teammate subprocess |
| CLAUDE_CODE_SUBAGENT_MODEL=opus[1m] env var | #36670 | Failed — only works for standalone subagents, not teammates |
| "model": "opus[1m]" in settings.json | #36670 | Failed — teammate spawn command still strips [1m] |
| Omitting model parameter in Agent tool calls | Own testing | Failed — Claude Code still injects --model claude-opus-4-6 into teammate subprocess regardless |
| Removing model from agent definition frontmatter | Own testing | Failed — same result |

What DOES work (for reference):

| Scenario | Context Window | How |
|----------|---------------|-----|
| Main session | 1M | Remove "model" from settings.json entirely — plan entitlement auto-detects |
| Standalone subagents (Agent tool, no team_name) | 1M | Inherits from parent correctly — confirmed claude-opus-4-6[1m] in system prompt |
| Teammates (TeamCreate + Agent with team_name) | 200K | No fix available — --model claude-opus-4-6 is always hardcoded in the tmux spawn command |

Root cause (confirmed via subprocess inspection):

The teammate spawn path always constructs the command with --model claude-opus-4-6 (200K). The [1m] suffix is stripped during model resolution before the tmux command is built. This is the same root cause as #34421 but confirmed still present through v2.1.87.

The standalone subagent path (in-process) correctly inherits the full model ID including [1m]. The teammate path (out-of-process via tmux) does not. The divergence is in how these two spawn paths resolve the model string.

Impact:

Agent Teams is the recommended way to run multi-agent work with visible tmux panes — but every teammate is silently running at 1/5th the context window. Users paying for 1M context on Team/Max plans don't get it on teammates, with no indication that context was downgraded.

yurukusa · 5 months ago

This is a significant issue for Team plan users. While the root cause needs a fix upstream (subprocesses should inherit the plan's context entitlement), there are a couple of workarounds:
1. PreToolUse hook to warn on thin subagent prompts:
If subagents get 200K instead of 1M, they need more focused prompts. A hook can catch this:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Agent",
        "hooks": [
          {
            "type": "command",
            "command": "INPUT=$(cat); PROMPT=$(echo \"$INPUT\" | jq -r '.tool_input.prompt // empty'); LEN=${#PROMPT}; if [ \"$LEN\" -lt 200 ]; then echo \"WARNING: Agent prompt is ${LEN} chars. Subagents only get 200K context (not 1M). Include all necessary context in the prompt.\" >&2; fi; exit 0"
          }
        ]
      }
    ]
  }
}

2. Use CLAUDE.md instruction to compensate:
Add to your project's CLAUDE.md:

When spawning subagents via the Agent tool:
- Include ALL relevant context in the prompt (subagents don't share your context)
- Keep prompts focused — subagents have ~200K context, not 1M
- Prefer specific file paths over broad exploration

Neither workaround gives subagents 1M context, but they help mitigate the quality impact by ensuring subagents receive sufficient context in their prompts.

keyur2maru · 5 months ago

I've just updated the patch gist and tested it on v2.1.81 and v2.1.87. Only thing to keep in mind is that you must instruct team lead to spawn teammates without specifying model so that it inherits model name from the team lead
https://gist.github.com/keyur2maru/0d2e4e728d7537aa7c36cbc936b2b6b4

yurukusa · 5 months ago

Thanks for the updated patch — confirming it works on v2.1.87 is valuable since older patches broke with minified name changes between releases.

ZainnQureshii · 5 months ago

Tested both workarounds on v2.1.89, sharing results:

@Reasonably "teammateDefaultModel": null in ~/.claude.json — no dice on v2.1.89. Teammates still spawn with 200K.

@keyur2maru your patch approach works. Adapted it for v2.1.89 and teammates are getting 1M now. Thanks for the gist 👊

Minified names changed again (shocker). Updated mappings for anyone patching v2.1.89:

| Component | v2.1.81 | v2.1.87 | v2.1.89 |
|-----------|---------|---------|-------------|
| Default model fn | Wg7() | Ex7() | $__() |
| Model table | sY_ | cD_ | LXH |
| Lead session model fn | mh() | Gh() | yG() |

# v2.1.89 patch (32 bytes, 2 occurrences)
OLD: function $__(){return LXH[y8()]}
NEW: function $__(){return yG()     }

Don't forget codesign -f -s - after patching on macOS. Gets nuked on every update obviously.

Reasonably · 5 months ago
Tested both workarounds on v2.1.89, sharing results: @Reasonably "teammateDefaultModel": null in ~/.claude.json — no dice on v2.1.89. Teammates still spawn with 200K. @keyur2maru your patch approach works. Adapted it for v2.1.89 and teammates are getting 1M now. Thanks for the gist 👊 Minified names changed again (shocker). Updated mappings for anyone patching v2.1.89: Component v2.1.81 v2.1.87 v2.1.89 Default model fn Wg7() Ex7() $__() Model table sY_ cD_ LXH Lead session model fn mh() Gh() yG() `` # v2.1.89 patch (32 bytes, 2 occurrences) OLD: function $__(){return LXH[y8()]} NEW: function $__(){return yG() } ` Don't forget codesign -f -s -` after patching on macOS. Gets nuked on every update obviously.

<img width="1655" height="78" alt="Image" src="https://github.com/user-attachments/assets/3166aaac-d673-47ed-999e-2e879a99175d" />

I think you maybe instruct to orchestrator spawn specific models.
Claude code don't modify model param only if "teammateDefaultModel": null and use default(inherit from orchestrator)

Edited

  • I missed a setting about models. You should set opus[1m] models explicitly(/model opus[1m])
regimantasm · 5 months ago

Workaround found (Claude Code v2.1.90): Setting CLAUDE_CODE_SUBAGENT_MODEL to claude-opus-4-6[1m] successfully gives subagents/teammates the full 1M context window.

Critical detail: Do NOT pass the model parameter on the Agent tool invocation. When Claude passes model: "opus" explicitly, it overrides the env var and resolves to standard 200K Opus. The env var only takes effect when no explicit model is passed.

Tested with Agent Teams (teammates spawned via CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1) - confirmed 1M context on the spawned teammate.

anascleaning · 4 months ago

Confirmed still broken on v2.1.91 — teammate tmux path never checks CLAUDE_CODE_SUBAGENT_MODEL

Traced the minified CLI binary on v2.1.91 to confirm the root cause. The teammate (tmux) model resolution and the standalone subagent (in-process) model resolution are two completely separate code paths, and only the in-process path checks the env var.

v2.1.91 model resolution paths

In-process subagents (standalone Agent tool, no team_name):

Iy6() → checks process.env.CLAUDE_CODE_SUBAGENT_MODEL FIRST → works ✓

Tmux teammates (TeamCreate + Agent with team_name):

j17(q.model, mainLoopModel)
  ├── if q.model === "inherit" → return mainLoopModel (has [1m]) ✓
  ├── if q.model is set → return q.model
  └── if q.model is null → jDK(mainLoopModel)
                              ├── if teammateDefaultModel === null → return mainLoopModel ✓
                              ├── if teammateDefaultModel is set → resolve it
                              └── else → D78() → "claude-opus-4-6" (200K!) ✗

jDK() / j17() never call Iy6() and never check CLAUDE_CODE_SUBAGENT_MODEL. The env var is completely bypassed for tmux teammates.

Why @regimantasm's env var fix may be a false positive

The CLAUDE_CODE_SUBAGENT_MODEL env var only works through Iy6(), which is the in-process runner path. If @regimantasm tested with a standalone Agent call (no team_name), it would work. Tmux teammates spawned via TeamCreate will still get 200K.

Minified function name mapping (v2.1.91)

| Concept | v2.1.89 | v2.1.91 |
|---------|---------|---------|
| Teammate default model resolver | eXK() | jDK() |
| Teammate model resolver | U67() | j17() |
| Base model ID (200K) | J18() | D78() |
| Model table (returns "claude-opus-4-6") | vZ6 | same |
| Subagent model resolver (has env var check) | oN6() | Iy6() |
| Lead session model getter | gx() | same pattern |

Suggested fix

jDK() (teammate default model) should check CLAUDE_CODE_SUBAGENT_MODEL the same way Iy6() does, or j17() should delegate to Iy6() instead of having a separate resolution chain.

Community workaround — regex-based binary patch (works on v2.1.87 through v2.1.91)

Unlike patches that target hardcoded minified function names (which break every release), this regex approach finds the --model ${FUNC([VAR])} pattern regardless of what the minified names are, and injects a ternary to force [1m]:

#!/bin/bash
# Patch Claude Code CLI to pass [1m] context to tmux teammate spawns
# Run after every: npm install -g @anthropic-ai/claude-code

CLI="/opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js"
# Adjust path for your platform:
#   Linux: ~/.local/share/claude/node_modules/@anthropic-ai/claude-code/cli.js
#   npm global (Linux): /usr/lib/node_modules/@anthropic-ai/claude-code/cli.js

if [ ! -f "$CLI" ]; then
    echo "CLI not found at $CLI"
    exit 1
fi

# Check if already patched
if grep -q 'claude-opus-4-6"?' "$CLI" 2>/dev/null; then
    echo "Already patched ✓"
    exit 0
fi

cp "$CLI" "${CLI}.orig"

python3 -c "
import re, sys

with open('$CLI', 'r') as f:
    content = f.read()

# Match: --model \${FUNC([VAR])}
# Replace with: --model \${FUNC([VAR==\"claude-opus-4-6\"?VAR+\"[1m]\":VAR])}
def patch(m):
    func, var = m.group(1), m.group(2)
    return '--model \\\${' + func + '([' + var + '==\"claude-opus-4-6\"?' + var + '+\"[1m]\":' + var + '])}'

patched = re.sub(r'--model \\\\\\\$\{(\w+)\(\[(\w+)\]\)\}', patch, content)
count = len(re.findall(r'claude-opus-4-6\"\?', patched))

if count == 0:
    print('No patterns found — CLI format may have changed')
    sys.exit(1)

with open('$CLI', 'w') as f:
    f.write(patched)

print(f'Patched {count} agent spawn points')
"

# macOS only — re-sign after patching
if [ "$(uname)" = "Darwin" ]; then
    codesign -f -s - "$CLI" 2>/dev/null || true
fi

echo "Done ✓"

Tested across v2.1.87, v2.1.89, and v2.1.91 — patches 6 tmux spawn points each time without needing to update minified variable names. Must re-run after every npm install -g @anthropic-ai/claude-code.

jonleung · 4 months ago

Confirming @Reasonably's workaround works on v2.1.92 (latest). Steps:

  1. \"teammateDefaultModel": null\ in \~/.claude.json\
  2. \/model opus[1m]\ in the lead session (NOT "Default")
  3. Don't pass \model\ when spawning teammates

Teammates correctly show "Opus 4.6 (1M context)" in tmux after this. Posted full details with before/after on #34421.

Also noting: this bug is tmux-specific. In-process mode (iTerm2 without tmux, Ghostty) gives teammates 1M without any workaround.

oconnorjoseph · 4 months ago

Same behavior on our end at BluMint — orchestrator-spawned subagents land on the 200K variant regardless of configuration attempts. Our parent session auto-resolves to claude-opus-4-7[1m] correctly via Max plan entitlement, but subagent subprocesses never get that inheritance because --model claude-opus-4-X is always injected into the spawn command.

Our workflow is multi-agent research/planning across a large monorepo — 200K subagents compact mid-investigation and lose their reasoning chain. The context-window delta is load-bearing for us.

Both your proposed fixes would work — ideally "don't inject --model" so subagents inherit the same entitlement-based auto-detection the parent uses, or at minimum pass through the [1m] suffix when the parent has it. Would very much appreciate movement here; this is a recurring blocker.

github-actions[bot] · 3 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] · 1 month ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.