[BUG] Automatic Context Compaction Fails After Large Codebase Analysis, Causing Excessive Token Usage
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?
When using the Claude Windows desktop application, I have been experiencing issues with automatic context compaction. Specifically, context windows do not appear to compact automatically in certain sessions.
In multiple instances, I have used tools/plugins to analyze a codebase before beginning development work. This understandably causes a significant increase in token usage. However, after this initial spike, the context window appears to become "stuck" and never compacts, allowing the conversation to grow far beyond the expected limits—sometimes exceeding them by more than 5x.
As a result, once the 5-hour usage limit resets, a single prompt can immediately consume the entire allowance again because the oversized context window is still being included. In many cases, this prompt performs little or none of the actual work I intended to accomplish before the limit is reached.
I have also attempted to manually compact the conversation using the /compact command. However, this either fails to execute or never completes, as the 5-hour token limit is hit immediately before the compaction process can run.
This issue first appeared late last week and has persisted through the weekend and into the present day. I am unsure whether it is related to the initial codebase analysis that caused the large context increase, or if it is a broader issue with the automatic compaction system itself. There are currently no clear indicators that would help determine which of these is the underlying cause.
What Should Happen?
The context window should automatically compact once the conversation reaches the applicable context threshold.
Before filing this issue, I attempted to verify whether this behavior was expected or the result of user error. During a conversation with the "Fin AI Agent" support chat, I was informed that automatic compaction may not occur immediately if a single message causes the context window to exceed the threshold. However, the explanation provided also indicated that compaction should occur automatically as the conversation continues through subsequent prompts.
In the cases I am reporting, the initial codebase analysis may have caused a significant increase in context usage, but the conversations then continued for an additional 5–20 prompts. Based on the information provided by the "Fin AI Agent," automatic compaction should have occurred during that period. Instead, the context window remained uncompressed for the remainder of the session, continuing to grow and consume tokens.
Because of this, the behavior I am observing appears to be inconsistent with the expected behavior described by the "Fin AI Agent" support chat, which is why I believe this may be a bug rather than an issue with how I am using the application.
Error Messages/Logs
Steps to Reproduce
- Create a new session using a larger, existing codebase with multiple directories and subdirectories.
- Ask the agent (observed with Sonnet 4.6; unknown whether model-specific) to debug an issue or analyze the project. The specific prompt does not appear to matter.
- Observe the agent using tools to scan and understand the codebase. A message is displayed indicating that the codebase is being analyzed.
- Allow the scan to complete and the agent to finish its initial task.
- Continue using the session normally. At this point, the Context Window indicator may reach 100% utilization and remain there. In my case, it has shown values exceeding 500,000 tokens against a 200,000-token limit.
- Continue the conversation for several additional prompts. Based on guidance provided by the "Fin AI Agent" support chat, automatic context compaction should occur after subsequent prompts, even if the initial codebase analysis caused the context window to exceed the threshold.
- Observe that no automatic compaction occurs. The context window remains significantly oversized, causing token consumption to increase rapidly.
- Attempt to manually compact the conversation using
/compact(or/compress, if applicable). Instead of compacting the conversation, the command either fails to execute or immediately triggers the 5-hour usage limit message due to the oversized context window.
Observed Result:
- Context window remains well above the configured limit.
- Automatic compaction never occurs.
- Token consumption becomes extremely high, with individual prompts rapidly exhausting the 5-hour allowance.
- Manual compaction commands are unable to complete.
Expected Result:
- The conversation should automatically compact after the threshold is exceeded and additional prompts are exchanged.
- Manual compaction commands should be able to execute successfully, even when the context window is oversized.
- Token consumption should return to normal levels once compaction has occurred.
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.160
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Other
Additional Information
This issue has been consistently observed within the Claude Desktop Application on Windows.
At this time, I have not been able to determine whether the same behavior occurs when using Claude Code through the CLI, so I cannot confirm whether the issue is specific to the desktop application or affects both environments.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗