[BUG] Memory leak from excessive [ToolSearch:optimistic] calls causing session crash
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?
Description
Claude Code sessions crash due to memory exhaustion after ~8 minutes of use. Debug logs show a pathological number of [ToolSearch:optimistic] calls accumulating - 2,341 calls in an 8-minute session, with bursts of 100+ calls within 2 milliseconds.
Environment
- Claude Code version: 2.1.17
- OS: Linux 6.17.0-8-generic (Ubuntu)
- Terminal: Tilix
Possible Trigger
A MaxFileReadTokenExceededError occurred at 21:54:04 (file with 26,691 tokens). The ToolSearch spam intensified after this, though the error itself was handled gracefully.
What Should Happen?
ToolSearch should not be called on every render cycle or in explosive bursts. Memory usage should remain stable during normal sessions.
Error Messages/Logs
1. **Excessive ToolSearch calls**: 2,341 `[ToolSearch:optimistic]` messages in 8 minutes
2. **Burst pattern**: At 21:55:49, over 100 identical calls logged within 2ms:
2026-01-23T21:55:49.847Z [DEBUG] [ToolSearch:optimistic] mode=tst-auto, ENABLE_TOOL_SEARCH=undefined, result=true
2026-01-23T21:55:49.847Z [DEBUG] [ToolSearch:optimistic] mode=tst-auto, ENABLE_TOOL_SEARCH=undefined, result=true
... (repeated 100+ times in same millisecond)
3. **High write ratio warnings**: Consistent `High write ratio: blit=X, write=Y (75-80% writes)` messages suggesting heavy screen repainting
Steps to Reproduce
- Start a fresh Claude Code session
- Perform typical development work (in my case, QEMU kernel testing with Bash commands)
- Session becomes unresponsive after ~8-10 minutes
- Requires
kill -9to terminate
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.17
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗