[BUG] Token Limit Hard-Stop Without Warning or Auto-Compaction

Status Open
Reported on v2.1.9
Maintainer reply None cached
Activity 15 comments · opened Jan 17, 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?

Claude Code reaches the 200k token limit and abruptly stops mid-conversation without any proactive warnings or automatic compaction. The conversation hits a hard-stop displaying "Context limit reached · /compact or /clear to continue" with no prior indication that the limit was approaching.

Current problematic behavior:

  1. No proactive warnings - Users receive no notification when approaching the token limit (e.g., at 80%, 90%, or 95% usage)
  2. No automatic compaction - The conversation does not auto-compact to preserve recent context and continue working
  3. Hard-stop mid-task - Work stops immediately, potentially in the middle of complex multi-step operations
  4. Poor visibility - Token usage appears only in <system_warning> tags within tool results, not in user-facing output
  5. Data loss risk - Users may not know to /export before the limit is reached
  6. Workflow disruption - Requires manual intervention (/compact or /clear) to continue, losing momentum on active development tasks

This is a serious bug in Claude Code CLI's token management system that breaks the user experience during extended development sessions.

What Should Happen?

Claude Code should implement graceful degradation with progressive warnings and automatic compaction:

Progressive Warning System

At 80% token usage (160k/200k):

⚠️  Token usage: 160000/200000 (80%)
Consider running /compact to free up context, or save your work soon.

At 95% token usage (190k/200k):

⚠️  Token usage: 190000/200000 (95%) - Approaching limit!
Please run /compact now to continue working, or conversation will auto-compact in 30 seconds.

Automatic Compaction

At 98% token usage (196k/200k):

  • Automatically compact the conversation to preserve recent context
  • Display progress: "Auto-compacting conversation to free up tokens..."
  • Continue working seamlessly without user intervention
  • Preserve:
  • Current task details
  • Recent tool outputs
  • User's original request
  • Active file contents

Never Hard-Stop Mid-Conversation

The current hard-stop behavior should only occur as an absolute last resort, and if necessary, should happen gracefully at a task boundary (not mid-operation).

User Control

Provide settings to:

  • Configure warning thresholds (default: 80%, 95%)
  • Enable/disable auto-compaction (default: enabled)
  • Set auto-compaction trigger point (default: 98%)

Error Messages/Logs

### Current Hard-Stop Message


⎿  Context limit reached · /compact or /clear to continue

✻ Cogitated for 33m 34s


### Token Usage in System Warnings (not visible to users in normal output)


<system_warning>Token usage: 48278/200000; 151722 remaining</system_warning>
[... many interactions later ...]
⎿  Context limit reached · /compact or /clear to continue


**Key issue:** Token usage warnings appear only in XML tags within tool results, not in user-facing conversational output. Users have no visibility into approaching limits.

### No Error Logs

The hard-stop does not generate error logs or stack traces - it simply displays the "Context limit reached" message and halts all interaction.

Steps to Reproduce

  1. Start a long development session with Claude Code CLI in any project:

``bash
claude-code
``

  1. Engage in extended multi-step work that generates high token usage:
  • Complex debugging sessions with multiple file reads
  • Multi-file refactoring tasks
  • Test generation workflows (multiple test files)
  • Long implementation plans with review cycles
  1. Continue working without manually checking token usage - rely on the tool to warn you
  1. Observe: No warnings appear as token usage climbs (80%, 90%, 95%)
  1. Observe: At ~200k tokens, conversation hits hard-stop:

``
⎿ Context limit reached · /compact or /clear to continue
``

  1. Observe: No prior warnings were given in user-facing output
  1. Observe: No automatic compaction occurred
  1. Result: User must manually /export to save context, then /compact or /clear to continue

Minimal Reproduction Example

Since this requires reaching 200k tokens, here's an accelerated test scenario:

# 1. Start Claude Code
claude-code

# 2. Execute a token-heavy workflow (example)
# Ask Claude to read and analyze multiple large files repeatedly:
"Please read all TypeScript files in the src/ directory and provide detailed analysis of each"
"Now read all test files and compare them to the source files"
"Now generate comprehensive tests for each source file"
[Continue with similar requests until approaching 200k tokens]

# 3. Monitor token usage in system warnings (developer mode)
# Look for <system_warning>Token usage: X/200000; Y remaining</system_warning>

# 4. Observe no user-facing warnings at 80%, 90%, 95% thresholds

# 5. Observe hard-stop at 200k tokens with no auto-compaction

Environment Details

  • Claude Code Version: Latest as of 2026-01-16
  • Model: claude-sonnet-4-5-20250929
  • OS: macOS (Darwin 25.2.0)
  • Shell: GNU bash 5.3.9
  • Session Type: Interactive CLI development session

Contributing Factors

This issue is particularly critical for:

  • Power users with rigorous testing/review protocols (high token usage per task)
  • Complex multi-file refactoring tasks
  • Test generation workflows (multiple test files)
  • Long debugging sessions with extensive file exploration
  • Multi-step implementation plans with review cycles

Users following best practices (comprehensive testing, code review, documentation) naturally generate high token usage, making this bug a significant barrier to productive extended development sessions.

---

Additional Context

Workarounds (Current):

Users must manually:

  1. Monitor token usage in <system_warning> tags (requires knowing where to look)
  2. Periodically run /compact preemptively (disruptive to workflow)
  3. Use /export before hitting limit to save context (requires anticipating the limit)
  4. Run /clear to hard-reset after hitting limit (loses all context)

Priority: High - This affects usability during extended development sessions and can cause data loss. The fix would significantly improve the user experience for power users working on complex tasks.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.9

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

_No response_

View original on GitHub ↗

15 Comments

barrowes · 7 months ago

Also, as of like version 2.1.6 you could use all of the tokens up to 200k, where as of 2.1.7, you are now locked out of using the remaining 25k-ish tokens, because of this new "Context limit reached" behavior. I have autocompact off, and understand I assume the risk of context exhaustion, but I'd rather have access to those 25k tokens to finish a package of work.

github-actions[bot] · 7 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/18211
  2. https://github.com/anthropics/claude-code/issues/14274
  3. https://github.com/anthropics/claude-code/issues/16349

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

solangerainha · 7 months ago

Auto compaction isn't working in Claude.ai either since yesterday.

stephanepericat · 7 months ago

same thing in the VS code plugin

luyufan498 · 7 months ago
Auto compaction isn't working in Claude.ai either since yesterday.

Yes, broken now.

chuenthe · 7 months ago

Yes, same issue for a few days now (not sure which version, probably started around 2.1.7, now running 2.1.12).
Autocompact is on, yet claude happily runs into 100% crash.

<img width="254" height="131" alt="Image" src="https://github.com/user-attachments/assets/885e50a8-24fa-4e7b-ab4e-347fe8c8a63e" />
<img width="350" height="145" alt="Image" src="https://github.com/user-attachments/assets/407f6191-6607-4ad8-8ae1-540aa4f7bd75" />

chrisguillory · 7 months ago
I'd rather have access to those 25k tokens to finish a package of work.

I'm loosing access to more than 25k because of this issue. Here's a Reddit thread detailing similar behavior that I am seeing.
https://www.reddit.com/r/ClaudeAI/comments/1qczpzg/anyone_else_getting_context_limit_reached_in/

I run with auto-compact = off. In previous versions, this allowed me to go all the way to 200k tokens with no issues. Now, on 2.1.7, Claude is hitting “Context limit reached” at ~165k–175k tokens, even though the limit is 200k. I'm having a problem with Claude Code. I’m using version 2.1.7 and I keep getting this error: Context limit reached · /compact or /clear to continue Opus 4.5 | v2.1.7 | 83% | 166145/200000 | >200k:false
barrowes · 7 months ago

The issue of getting locked out of the last 35k-ish tokens even with autocompact off seems to have been fixed as of 2.1.14, even though the terminal warnings still are calculating the remaining context percent based on whatever the arbitrary cutoff amount was before. The release notes for 2.1.15 seem to say that the context-warning messages have been adjusted, but mine still act like they want to cut me off like what was happening when the bug was active. Thank you for the fix.

andreszs · 7 months ago

This behavior is catastrophic in a code-editing context. An assistant that modifies files must never abandon an edit halfway through execution. Doing so actively corrupts the user’s codebase and can waste significant time or cause real damage in production environments.

Claude must not:

  • Stop editing files mid-operation
  • Leave code in an inconsistent or uncompilable state
  • Abort silently due to token exhaustion

Explicitly refuse to start the edit if it cannot be completed safely

Allowing partial edits to be written and then abandoned is grossly negligent behavior for a coding agent. It breaks the core trust assumption that automated code tools must be safe by default.

It is genuinely alarming that this has not been addressed earlier. In its current state, this behavior makes Claude unsafe for any non-trivial code editing workflow.

What Should Happen?

At an absolute minimum, the agent must:

  • Finish the current edit atomically, or
  • Revert all partial changes, or
  • Explicitly refuse to start the edit if it cannot be completed safely
lexabu · 6 months ago

Adding my voice — I'm using Claude Code for autonomous task execution and this is a blocker.

Issues I'm encountering:

  • No unattended operation — Hard-stop requires manual /compact, defeating automation
  • Partial edit corruption — As @andreszs noted, mid-task failures leave code in broken states
  • No graceful recovery — Agents have no way to self-heal before hitting limits

I've also encountered the behavior where auto-compact fails to trigger even when enabled. Until this is resolved, any workflow relying on Claude Code for unattended, multi-step operations risks producing corrupt output or stalling entirely.

👍 on the progressive warning system and auto-compaction proposals. Atomic edit guarantees (finish current operation or rollback) would also be critical for safe automation.

Closed my ticket (#23966) as a duplicate of this issue.

jpangelle · 6 months ago

Bump

andreszs · 6 months ago

Even worse: Claude 4.6 now takes the liberty of reverting to a previous commit without even asking, and just like that, your recent work is gone. This happened yesterday:

Note: the git checkout I ran earlier reverted your uncommitted about.js changes (the badge URL additions like kofiBadgeUrl, paypalBadgeUrl, usdcBadgeUrl and the restructured support section). You may need to re-apply those separately.

“You may need to re-apply those.” Right. Thanks for the heads-up, Claude — incredibly helpful after the fact. I had to manually restore everything, including changes that were built through a mix of unlimited GPT (web) research plus careful manual editing. Net result: over an hour of work burned because the tool decided to time-travel my repo without permission.

junaidtitan · 4 months ago

The hard-stop without warning happens when context silently fills past the limit. The guard daemon in Cozempic v1.4.1 monitors token usage continuously and fires pruning at configurable thresholds (gentle at 45%, hard at 75%) well before the limit.

17 strategies across 3 tiers keep sessions lean. Auto-starts via SessionStart hook — install once:

pip install cozempic && cozempic init

Also shows real-time token count and context usage % via cozempic diagnose.

smartwatermelon · 4 months ago

@junaidtitan and the award for best project name goes to...

junaidtitan · 4 months ago

😅

Regards,
Junaid Ali Qureshi

On Fri, 3 Apr 2026 at 8:26 PM Andrew Rich @.***> wrote:

smartwatermelon left a comment (anthropics/claude-code#18705) <https://github.com/anthropics/claude-code/issues/18705#issuecomment-4184156268> @junaidtitan <https://github.com/junaidtitan> and the award for best project name goes to... — Reply to this email directly, view it on GitHub <https://github.com/anthropics/claude-code/issues/18705?email_source=notifications&email_token=AFVALNPBGSOUZI7AVSIUCL34T7Q5BA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIMJYGQYTKNRSGY4KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4184156268>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AFVALNJQHQZLP7PJV6NXVTL4T7Q5BAVCNFSM6AAAAACR7COVPKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DCOBUGE2TMMRWHA> . You are receiving this because you were mentioned.Message ID: @.***>