[BUG] Agent teams: in-process members get wrong context window in 2.1.70/2.1.71, causing immediate auto-compaction
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When using experimental agent teams (CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1) with backendType: "in-process", agent team members receive an incorrect context window calculation in versions 2.1.70 and 2.1.71. This causes them to auto-compact almost immediately after spawning — typically right after receiving the initial prompt from the team lead and doing minimal work (a few file reads).
The team lead's context window is correct, but in-process agent team members appear to use a default/fallback context window instead of inheriting the team lead's model context window. With CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=40, this results in a compaction threshold of roughly 72K tokens, which agents exceed almost immediately from their initial system prompt + team instructions alone.
What Should Happen?
In-process agent team members should inherit the team lead's model and its full context window. Auto-compaction should only trigger when agents actually approach the correct context limit, not immediately after spawning.
This works correctly in version 2.1.58 — agent team members get the correct context window and operate normally without premature compaction.
Error Messages/Logs
No error messages — agents silently auto-compact. The only observable symptom is seeing
"Auto-compact" appear in agent team member outputs immediately after they spawn and receive
their prompt, before doing meaningful work. Token counts displayed for agent team members
also appear incorrect/understated compared to the team lead.
Steps to Reproduce
- Set
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 - Optionally set
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=40(makes the threshold more visible, but the bug exists regardless) - Create a team with a team lead using Opus and multiple in-process dev agents (
backendType: "in-process") that inherit the lead's model - Start the team with a non-trivial prompt that includes task instructions for each dev agent
- Observe that in-process agent team members auto-compact almost immediately after spawning — often after just reading a few files — while the team lead's context is fine
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.58
Claude Code Version
2.1.71 (bug present), 2.1.70 (bug present), 2.1.58 (works correctly)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
The issue appears to be in how in-process agent team members resolve their model context window. In 2.1.58, the agent team member's team config correctly resolves the model (e.g., "opus"), and the context window calculation matches the team lead's. In 2.1.70/2.1.71, the model resolution for in-process members seems to fail, falling through to a default 200K context window instead of the team lead's actual model context window. The compaction threshold is then calculated against this wrong baseline.
This was tested with teams of 2-3 in-process dev agents. The team lead (same model, same session) never prematurely compacts — only the in-process agent team members are affected.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗