[BUG] Compaction fails with "context window limit" error even when context usage is low (e.g., 20%) — regression in v2.1.153
Status Fixed / completed
Reported on v2.1.140
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 8 comments · opened May 28, 2026 · closed May 29, 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 updating from v2.1.140 to v2.1.153, automatic compaction no longer triggers. Manually running /compact fails with a context window limit error, even though the displayed context usage is only around 20%. This creates an unrecoverable dead-end where the
conversation cannot continue and /clear is the only way out, losing all progress.
What Should Happen?
- Automatic compaction should trigger during extended conversations, as it did in v2.1.140
- Compaction should succeed when context usage is low (20%)
- If compaction fails, there should be a fallback mechanism rather than leaving the session unrecoverable
Error Messages/Logs
Error: Error during compaction: API Error: The model has reached its context window limit.
This error appears both when automatic compaction attempts to run and when manually executing /compact.
Steps to Reproduce
- Today I Update Claude Code from v2.1.140 to v2.1.153
- Start a conversation and work normally for an extended period
- During normal usage, an error suddenly appears: API Error: The model has reached its context window limit.
- Observe that automatic compaction never triggered on its own
- Notice that context usage remains low (around 20%)
- Manually run /compact → fails with the same error
- Session is now unrecoverable — only /clear works
Claude Model
Other
Is this a regression?
Yes, this worked in a previous version
Last Working Version
2.1.140
Claude Code Version
2.1.153
Platform
Other
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
- This is a regression — compaction worked correctly in v2.1.140
- No large files were read during the session — context grew through normal conversation and tool usage
- The error message claims "context window limit" but usage is only ~20%, suggesting hidden context (system prompts, tool definitions, etc.) may be inflating the actual token count beyond what the usage indicator shows
- Claude Code CLI, macOS (Darwin 25.5.0)
Showing cached comments. Read the full discussion on GitHub ↗
7 Comments
same problem
Problem: When using Claude Code with GLM-5.1 via Zhipu's Anthropic-compatible API (open.bigmodel.cn/api/anthropic), context compaction fails at ~20% usage with the error: Error during compaction: API Error: The model has reached its context window limit. The /compact command also fails, leaving /clear as the only option.
Root Cause: Zhipu's API incorrectly reports the model's context window as 1M tokens instead of the actual 200K. Claude Code trusts this value and believes 20% = 200K of 1M, when in reality 200K is already the full context. When compaction sends the full conversation for summarization, it exceeds GLM-5.1's actual limit.
Resolution: Add the following to ~/.claude/settings.json under the env section:
"CLAUDE_CODE_DISABLE_1M_CONTEXT": "true"
This forces Claude Code to fall back to the default 200K context window, matching GLM-5.1's actual capability. After restart, the model no longer shows [1m] suffix and compaction works correctly.
same problem
感谢大佬,今天更新发现了问题,来社区找方法
Can confirm the workaround works. Setting
CLAUDE_CODE_DISABLE_1M_CONTEXT=1correctly forces the 200K context window and compaction succeeds.Thanks for tracking down the root cause — the mismatch between the reported and actual context size is a subtle one to catch.
For anyone finding this later: this fix resolves the manual
/compactpath, but auto-compact remains broken due to a separate regression in v2.1.161+. See #65585 for the full analysis.Tried this but i just get "Prompt is too long"
Thanks for the update and the detailed analysis.
I'd like to add a couple of points:
1. I can confirm that setting CLAUDE_CODE_DISABLE_1M_CONTEXT=1 only resolves the manual /compact path — it doesn't fix auto-compact, as you noted.
2. As a side note, I'm now using the glm-5.2 model, which officially supports a 1M token context window. After this change, I removed the CLAUDE_CODE_DISABLE_1M_CONTEXT setting, and the context size calculation now appears to be correct. I haven't encountered the
auto-compact issue yet, and my Claude Code hasn't been upgraded either, so I'll keep using it for a while and follow up with anything I find.
Thanks again for sharing the information about the auto-compact bug.
郝忠华
@.***
原始邮件
发件人:stig-weard @.*>
发件时间:2026年6月11日 01:50
收件人:anthropics/claude-code @.*>
抄送:haozhongh @.>, State change @.>
主题:Re: [anthropics/claude-code] [BUG] Compaction fails with "context window limit" error even when context usage is low (e.g., 20%) — regression in v2.1.153 (Issue #63197)
stig-weard left a comment (anthropics/claude-code#63197)
Can confirm the workaround works. Setting CLAUDE_CODE_DISABLE_1M_CONTEXT=1 correctly forces the 200K context window and compaction succeeds.
Thanks for tracking down the root cause — the mismatch between the reported and actual context size is a subtle one to catch.
For anyone finding this later: this fix resolves the manual /compact path, but auto-compact remains broken due to a separate regression in v2.1.161+. See #65585 for the full analysis.
Tried this but i just get "Prompt is too long"
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you modified the open/close state.