[BUG] Cascading Tool-Result Files with Exponential Formatting Overhead
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 Read tool output exceeds read tool limit ( default or CLAUDE_CODE_FILE_READ_MAX_OUTPUT_TOKENS), the response includes a filepath to the persisted content but returns only 2KB inline. This design intends to signal the model to selectively read specific parts. However, models typically re-read the original file (which exceeds the limit again) or read the persisted tool-result file directly. The persisted file contains the original file with added formatting (line numbers, arrows, whitespace). Re-reading this formatted file triggers the same "output too large" error, creating a new persisted file with doubled formatting. This cycle repeats, causing exponential overhead and file proliferation.
Current Behavior
- First Read: file + formatting = 62,784 chars (+21.24% overhead)
- Re-read of tool-result: formatting applied again = exponential growth
- Multiple sub-agents in background compound the problem
- Example observed: 4 levels of cascading formatting (1→ 2→ 3→ 4→)
Impact
- Infinite cascade of tool-result files with exponential formatting overhead
- Sub-agents processing files simultaneously, each creating duplicate persisted files
- Token waste and performance degradation
- File system pollution with duplicate persisted content
What Should Happen?
- Model receives a directive that explicitly suppresses re-reading (not just a filepath)
- Or: persisted files are saved without formatting; formatting only applied on final agent display
- Or: inline response includes metadata instructing model how to read persisted content (e.g., "read lines 100-200 from file" or "ask user which lines to read")
Error Messages/Logs
Main and sub agent transcript:
...
{
"tool_use_id": "[TOOL_USE_ID]",
"type": "tool_result",
"content": "<persisted-output>\nOutput too large (61.3KB). Full output saved to: C:\\Users\\[USERNAME]\\.claude\\projects\\[PROJECT]\\[SESSION_ID]\\tool-results\\[TOOL_USE_ID].txt\n\nPreview (first 2KB):\n 1→<?xml version=\"1.0\" encoding=\"utf-8\"?>\n 2→<products>\n 3→ <product>\n 4→ <productId>PROD-000001</productId>\n 5→ [...couple lines XML content omitted...]\n...\n</persisted-output>"
}
...
Steps to Reproduce
- Configure file read limit to a low value or create a file exceeding the default limit (>32k tokens should work)
- Read a file exceeding this limit (~51KB XML tested)
- Model receives response: "Output too large (61.3KB). Full output saved to: [filepath].txt. Preview (first 2KB): [content]"
- Model re-reads the original file → same error with new persisted file
- Model reads new persisted file (now with doubled formatting) → same error with tripled formatting
- Cycle continues indefinitely
Claude Model
Not sure / Multiple models
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.71 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Windows Terminal
Additional Information
Related but no duplicate
- Connects to formatting overhead issue (the 20% overhead per read)
- Cascading is prevented if formatting is removed from persisted files
5 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Not a duplicate. The provided tickets describe different problem areas:
Still an issue in Claude Code v2.1.81.
Only possible workaround to reduce the reoccurring overhead to a single number is converting files to compact (no new lines or consecutive whitespaces). This is beneficial for token usage but is really annoying if files actually need formatting or only small changes should be done because the diff is inline. Removing the numbered lines from the read tool output and providing a good warning to the model would be a better approach.
In Claude Code 2.1.87 there is a new message if the file exceeds read token max. It is more helpful and the prompt for the model to read the file in parts actually works:
Thanks I will close the issue now because that fixes the issue.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.