[BUG] REPL-level context limit check uses stale post-compact token accounting, blocks input despite 73% free context (1M window)

Resolved 💬 4 comments Opened Apr 14, 2026 by adii800 Closed Jun 12, 2026

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?

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
  1. Work in a long session until context approaches the limit
  1. Run /compact — compaction succeeds, top-line drops to ~265k
  1. Attempt to send any message (e.g., "hi!")
  1. Observe "Context limit reached · /compact or /clear to continue" despite 27% usage
  1. Run /context — top-line shows 265.8k/1m but breakdown shows 869.9k Messages
  1. Kill and re-resume with claude -r <session-id> — same result, stale accounting persists
  1. 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.

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗