Context Limit Reached error should auto-compact and queue user message instead of failing
Status Closed — not planned
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 9 comments · opened Feb 11, 2026 · closed Mar 19, 2026
Description
When running long sessions with multiple parallel background agents (Task tool with run_in_background: true), sending a user message (especially with a screenshot attachment) while agents are still running throws a "Context Limit Reached" error instead of gracefully handling it.
This is on a Max plan — not a billing or rate limit issue. The model's context window is exhausted by accumulated agent results.
Expected Behavior
- User sends a message while agents are running
- System detects context is near/at limit
- System auto-compacts (summarizes prior messages)
- User's message is queued and processed after compaction
- Session continues seamlessly
Actual Behavior
- User sends a message while agents are running
- System throws "Context Limit Reached" error
- User cannot send any further messages
/compactmay also fail with the same error- Only option is
/clear— which loses all conversation history, agent results, and work in progress
Reproduction Steps
- Start a Claude Code session (Opus 4.6, Max plan)
- Launch 4-6 parallel background agents using the Task tool (e.g., SEO audit with 6 specialist subagents)
- While agents are running and returning results, send a new user message with a screenshot attachment
- Observe "Context Limit Reached" error
Root Cause Analysis
From investigating a crashed session (46MB JSONL transcript):
- 274 user messages averaging 164KB each
- 12 messages over 1MB, 39 over 100KB
- 97.5% of context came from subagent results returned as user messages
- The Task tool returns agent output as user-visible messages, which accumulate rapidly
Impact
- Loss of work: Hours of multi-agent analysis lost when
/clearis the only recovery - No recovery path:
/compactfails with the same error, creating a dead-end state - Session state destroyed: TaskList, agent results, conversation history — all gone
- Workaround burden on users: Must manually track when to
/compact, which defeats the purpose of autonomous agent workflows
Suggested Solutions
Priority 1: Graceful degradation
When context limit is approaching:
- Auto-trigger compaction before the hard limit is hit
- Queue the user's pending message
- Process the queued message after compaction succeeds
Priority 2: Pre-emptive compaction
- Add a threshold (e.g., 80% of context window) that triggers automatic compaction
- Or add a hook event like
PreContextLimitthat fires before the hard limit
Priority 3: Agent result management
- Task tool results from background agents should not expand into full user messages
- Consider: agent results as compressible system messages, or file-based result passing where agents write to disk and parent reads files
Current Workarounds
We've implemented partial mitigations via hooks and CLAUDE.md instructions:
SubagentStophook reminds to/compactafter agent workPreCompacthook preserves critical context- All custom skills use file-based result passing (agents write to files, return only brief summaries)
- But none of these prevent the hard crash when a user message arrives during heavy agent work
Environment
- Plan: Claude Max (Opus 4.6)
- Platform: macOS (Darwin 25.2.0)
- Claude Code version: Latest as of Feb 2026
- Model: claude-opus-4-6
9 Comments
<img width="974" height="161" alt="Image" src="https://github.com/user-attachments/assets/1ab49493-3d56-4ef8-aeb2-b8d3864be5d2" />
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
these are not duplicates, and or different issues.
I can confirm this bug and currently working with claude code as an agenting development is just impossible.
Agents context window is shared between agents and main claude code context:
● Agent "Create Certifications migration+model" completed
⎿ Context limit reached · /compact or /clear to continue
● Agent "Add CRS org settings migration" completed
⎿ Context limit reached · /compact or /clear to continue
● Agent "Create CRS models and migration" completed
⎿ Context limit reached · /compact or /clear to continue
● Agent "Add Authorization access matrix" completed
⎿ Context limit reached · /compact or /clear to continue
● Agent "Auth routes, controller, sidebar" completed
⎿ Context limit reached · /compact or /clear to continue
This I got in same moment.
i have been getting these msg in prompts over the past couple of days
Since losing conversation history was a recurring problem for me, I built a bash dashboard to track all Claude Code operational files (CLAUDE.md, MEMORY.md, conversation logs) across projects. It helps you see what Claude knows per project and clean up old session logs.
Zero dependencies, single script: https://github.com/sarob/claude-ops
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
Please re-open as not confirmed to be fixed.
+1
Last occurred 03/21/2026 version 2.1.81
## Bug Description
Auto-compaction does not trigger before reaching the context limit when using
the 1M token context window. The session abruptly stops with "Context limit
reached" instead of auto-compacting to free up space.
## Environment
## Steps to Reproduce
## Expected Behavior
Auto-compaction should trigger at some threshold (e.g., 80-90% of context
limit) to free up context space and allow the session to continue without
interruption. This behavior previously worked when the context window was
smaller (pre-1M expansion).
## Actual Behavior
No auto-compaction occurs. The session hits the context limit and stops
abruptly. Observed on multiple occasions:
bar) without auto-compaction
auto-compaction
In both cases, manual
/compactwas required. Prior to the 1M tokencontext window expansion, auto-compaction would trigger automatically.
## Impact
/compactproactively
interactive walkthroughs) where pausing to compact is disruptive
## Workaround
Manually run
/compactbefore reaching the limit. However, this requiresconstant monitoring of the context percentage in the status bar.
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.