claude-code - 💡(How to fix) Fix [BUG] REPL-level context limit check uses stale post-compact token accounting, blocks input despite 73% free context (1M window) [2 comments, 2 participants]

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…
GitHub stats
anthropics/claude-code#47855Fetched 2026-04-15 06:40:25
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×4commented ×2

Error Message

Error Messages/Logs

Root Cause

The root cause: /compact successfully reduced the actual message payload, but the "Estimated usage by category" breakdown retains the pre-compact token counts (Messages: 867.5k). The REPL-level input gate uses this stale breakdown sum rather than the accurate top-line figure, blocking input before the query loop ever executes.

Code Example

Context limit reached · /compact or /clear to continue

/context output:
claude-opus-4-6[1m] · 265.8k/1m tokens (27%)

Estimated usage by category:
  System prompt: 6k tokens (0.6%)
  System tools: 13.1k tokens (1.3%)
  Memory files: 659 tokens (0.1%)
  Skills: 631 tokens (0.1%)
  Messages: 869.9k tokens (87.0%)STALE, pre-compact value
  Free space: 76.7k (7.7%)           ← computed from stale breakdown
  Autocompact buffer: 33k tokens (3.3%)
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 (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

After /compact on a 1M context session (Opus 4.6, Claude Max, v2.1.107), the REPL blocks all input with "Context limit reached · /compact or /clear to continue" despite /context reporting only 27% usage (265.8k/1m tokens).

The root cause: /compact successfully reduced the actual message payload, but the "Estimated usage by category" breakdown retains the pre-compact token counts (Messages: 867.5k). The REPL-level input gate uses this stale breakdown sum rather than the accurate top-line figure, blocking input before the query loop ever executes.

Key evidence:

  • Top-line: 265.8k/1m tokens (27%) — accurate post-compact count

  • Breakdown: Messages: 867.5k tokens (86.8%) — stale pre-compact count

  • Free space: 79k (7.9%) — computed from stale breakdown, not top-line

  • The breakdown sum (~920k) is consistent with the 1M window, but the individual Messages line was never updated after compact

  • Each resume attempt increments the stale counter slightly (867.5k → 869.9k), confirming it's live-appending to the stale base

  • CLAUDE_CODE_BLOCKING_LIMIT_OVERRIDE=950000 does not fix this — the env var is only checked in lMH() inside the query loop, but the REPL blocks input submission before the query loop runs (the gx constant match in the OH7 UI renderer)

  • No s1mAccessCache or env var override is present — the 1M plumbing is working correctly

NOTE: Both Terminal.app and VS Code integrated terminal are impacted.

What Should Happen?

After /compact, the breakdown accounting should reflect the actual post-compact message token count, not the pre-compact count. The REPL input gate should use the same token count as the top-line /context display. CLAUDE_CODE_BLOCKING_LIMIT_OVERRIDE should also be respected at the REPL input layer, not just the query loop.

Error Messages/Logs

Context limit reached · /compact or /clear to continue

/context output:
claude-opus-4-6[1m] · 265.8k/1m tokens (27%)

Estimated usage by category:
  System prompt: 6k tokens (0.6%)
  System tools: 13.1k tokens (1.3%)
  Memory files: 659 tokens (0.1%)
  Skills: 631 tokens (0.1%)
  Messages: 869.9k tokens (87.0%)    ← STALE, pre-compact value
  Free space: 76.7k (7.7%)           ← computed from stale breakdown
  Autocompact buffer: 33k tokens (3.3%)

Steps to Reproduce

  1. Start Claude Code v2.1.107 with Opus 4.6 (1M context) on Claude Max

  2. Work in a long session until context approaches the limit

  3. Run /compact — compaction succeeds, top-line drops to ~265k

  4. Attempt to send any message (e.g., "hi!")

  5. Observe "Context limit reached · /compact or /clear to continue" despite 27% usage

  6. Run /context — top-line shows 265.8k/1m but breakdown shows 869.9k Messages

  7. Kill and re-resume with claude -r <session-id> — same result, stale accounting persists

  8. Set CLAUDE_CODE_BLOCKING_LIMIT_OVERRIDE=950000 and re-resume — still blocked (env var not checked at REPL layer)

Claude Model: Opus 4.6 (1M context)

Claude Code Version: 2.1.107

Platform: macOS (native install)

Operating System: macOS (Apple Silicon, M3 Max)

Additional context: Related to #34158, #19018, #20455, but distinct — those were caused by s1mAccessCache or env var issues. This is a post-compact accounting desync where the REPL input gate uses a stale token sum that was never refreshed after compaction.

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.107

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Related to #34158, #19018, #20455, but distinct — those were caused by s1mAccessCache or env var issues. This is a post-compact accounting desync where the REPL input gate uses a stale token sum that was never refreshed after compaction.

extent analysis

TL;DR

The issue can be temporarily worked around by using the /clear command instead of /compact to free up space, but a proper fix requires updating the REPL input gate to use the accurate post-compact token count.

Guidance

  • The root cause is the desync between the top-line token count and the breakdown accounting after compaction, causing the REPL input gate to block input prematurely.
  • To verify the issue, compare the top-line token count with the breakdown accounting after running /compact and attempting to send a message.
  • The CLAUDE_CODE_BLOCKING_LIMIT_OVERRIDE environment variable does not fix the issue because it is only checked inside the query loop, not at the REPL input layer.
  • Setting CLAUDE_CODE_BLOCKING_LIMIT_OVERRIDE to a higher value may not work as expected due to the stale token sum used by the REPL input gate.

Example

No code snippet is provided as the issue is related to the internal workings of the Claude Code REPL and requires changes to the underlying logic.

Notes

The issue is specific to the Opus 4.6 model with 1M context and Claude Code version 2.1.107. The problem is a regression, and the last working version is not specified.

Recommendation

Apply a workaround by using /clear instead of /compact until a proper fix is available, as updating the REPL input gate to use the accurate post-compact token count is necessary to resolve the issue.

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] REPL-level context limit check uses stale post-compact token accounting, blocks input despite 73% free context (1M window) [2 comments, 2 participants]