[BUG] Claude Code consistently degrades in performance over long sessions
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 long sessions (Claude Max with several autocompacts), Claude Code becomes slower and slower to the point that it becomes so slow that takes several minutes between requests. The current solution is to shut it down and start fresh. It looks as if something accumulates (data structure or something) and causes a terrible performance issue. I have /rewind disabled (disabled it due to the performance issue) and nothing improoves that doesn't seems to be the cause. I am using streaming MCP.
What Should Happen?
Stay at the same performance level during long sessions by using performant O(nlogn) data structures and not slow to a crawl. Or not have some memory leak (could be the cause too)
Error Messages/Logs
No error, just heavy performance degradation.
Steps to Reproduce
Run during a very long session and several auto compacts. Monitor the performance with performance counters scattered around blocks of code to locate the culprit region.
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
v2.0.31
Platform
Anthropic API
Operating System
Windows 11
Terminal/Shell
Windows Terminal
Additional Information
_No response_
14 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
This is probably due to the 200K token budget limit related to the context window. I chatted with the support team and they confirmed that the 200K limit is shared across Pro and Max subscriptions. It can be increased up to 500K, but that requires an enterprise account.
In the meantime, you should migrate from output style (which will be deprecated on November 5th) to system prompt using --append-system-prompt-file, as this will help with caching. However, the performance degradation you're experiencing also depends on how large your projects are and how much context accumulates over long sessions
Plus one, after using Claude for hours, with many compacts, performance is TERRIBLE. I have to either lose context (very bad) or it's unusable.
I disagree. Longer context means more processing, not less. This seems to be some bug lurking around. I disabled MCP, appeared to improve but also happens without MCP. It consistently happens with native version too. I switched to native to delay this as much as possible.
Root Cause Analysis: Console History Accumulation After Compaction
_This analysis was performed by @tokoroten using Claude Code to investigate the compiled source._
I've investigated the performance degradation issue and identified the root cause by analyzing the compiled code in
@anthropic-ai/claude-code@2.0.35.The Bug
The terminal renderer fails to clear
fullStaticOutputbuffer, causing progressive performance degradation through two compounding mechanisms:Technical Details
1.
fullStaticOutputNever Gets ClearedUltra-thorough analysis confirms:
fullStaticOutputis initialized once but never reset.Occurrences in cli.js:
""inTG1constructor+=operatorreset()method exists but does NOT clearfullStaticOutput2. Dual Performance Degradation Mechanism
Problem 1: O(n) String Concatenation Cost
+=operation creates a new string object and copies all existing contentfullStaticOutputgrows (10KB → 100KB → 1MB), each append requires full memory copyProblem 2: Re-rendering Historical Data
3. Compaction Does Not Trigger Cleanup
Verification: Searched entire codebase for cleanup during compaction:
PreCompacthook that clearsfullStaticOutputPostCompacthook that clearsfullStaticOutputfullStaticOutputis reset to""The only assignment to
fullStaticOutput = ""is in the constructor (Line 202).Impact Analysis
This dual mechanism explains the reported symptoms:
TG1instance, reinitializes to"")Growth pattern:
fullStaticOutput = ""(fast)fullStaticOutput = 500KB(each+=copies 500KB, each render outputs 500KB)fullStaticOutput = 1.5MB(each+=copies 1.5MB, each render outputs 1.5MB)Proposed Fix
Option 1: Clear in reset() method (minimal change)
Option 2: Clear during compaction (proper lifecycle management)
Add cleanup hook after compaction completes:
Option 3: Use buffer with size limit (prevent unbounded growth)
Verification Method
To confirm this fix resolves the issue:
process.memoryUsage().heapUsedover long sessionsfullStaticOutput.lengthgrowth over timeEnvironment
@anthropic-ai/claude-code@2.0.35cli.js(compiled/bundled)---
_Analysis performed by @tokoroten using Claude Code (Sonnet 4.5) on 2025-11-08_
The symptom I'm experiencing is that the scrollback buffer gets fouled up, keeps jumping back to the top and jittering from top to bottom. I'm running stock Ubuntu 22 with default terminal.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
I moved to VS code extension due to the flickering. Seems to be degrading less but still does.
Experiencing Same Issue - WSL2
Environment:
Symptoms:
Onset: Started ~1.5 days ago. Never had this level of lag before.
Observed Memory Growth Pattern:
| Time | Elapsed | RSS Memory | Notes |
|------|---------|------------|-------|
| 0:00 | start | ~340MB | Fresh session |
| 0:09 | 9min | 490MB | Normal use |
| 0:09 | +30sec | 588MB | +98MB in 30 seconds |
| 0:10 | +30sec | 641MB | +53MB in 30 seconds |
| 0:11 | 11min | 716MB | CPU hit 190% |
Key observation: Memory grows ~50MB per 30 seconds during active tool use (bash commands, file reads). Older idle sessions stabilize around 400MB, but active sessions balloon rapidly.
System impact: When Claude Code spikes,
VmmemWSLon Windows side also shows high CPU - suggests bottleneck at WSL/Windows boundary, possibly from memory pressure or I/O.Workaround in use: Restarting sessions every 30-45 minutes before lag becomes severe.
Diagnostic data available: I have memory timeline CSVs and CPU spike logs if helpful for debugging.
Can confirm the progressive slowdown over long sessions on v2.1.14 (macOS). Restarting is still the only workaround.
Confirmation: Long sessions cause 80-100% idle CPU (macOS)
Adding data from a macOS environment that confirms this issue persists in v2.1.27-2.1.30.
Environment: MacBook Pro M3 Max, macOS 15.7.4
Observation: 10 concurrent sessions with
--continueflag, running 7h to 4 days, all showed 50-98% CPU while completely idle. The oldest session (3d 22h) used 92% CPU with 745MB memory.Immediate workaround: Running
/clearin a session drops CPU from 98% → 0% instantly and reduces memory ~10x. This is more practical than killing sessions since it preserves the session ID for--continue.This aligns with the root cause analysis in this thread about
fullStaticOutputbuffer accumulation. The/clearcommand appears to reset whatever state causes the continuous rendering/GC activity.Cross-ref: Detailed diagnostic data in #22509
Still waiting for a resolution. Why is no one picking this up? Every single person who has ever used claude code over a period must have faced this issue.
Instead of fixing the bug, it seems like even people at Anthropic has learned to live with it instead.
Additional data: Multi-instance orchestration scenario
Environment:
Symptoms:
top)Impact:
For users running multiple instances (e.g., AI agent orchestration systems), this compounds significantly. Total system CPU usage from idle Claude Code processes can exceed 500%.
Workaround discovered in this thread:
The
/clearcommand tip is valuable - will test dropping CPU from ~98% → 0%.This issue is blocking adoption for multi-agent use cases. Would appreciate prioritization.
Performance degradation over long sessions is caused by context inflation — the signal-to-noise ratio drops as bloat accumulates. Each compaction cycle helps briefly, then bloat re-accumulates.
Cozempic v1.4.1 keeps sessions lean continuously with a guard daemon. 17 strategies strip different bloat types: progress ticks (40-48%), stale reads, duplicate documents, old images. The new
compact-summary-collapseremoves 85-95% of pre-compaction content.pip install cozempic && cozempic initShould help maintain performance quality across long sessions. Feedback welcome.