[BUG] Cascading Tool-Result Files with Exponential Formatting Overhead

Status Fixed / completed
Reported on v2.1.71
Maintainer reply None cached
Activity 5 comments · opened Mar 7, 2026 · closed Mar 30, 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?

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

  1. Configure file read limit to a low value or create a file exceeding the default limit (>32k tokens should work)
  2. Read a file exceeding this limit (~51KB XML tested)
  3. Model receives response: "Output too large (61.3KB). Full output saved to: [filepath].txt. Preview (first 2KB): [content]"
  4. Model re-reads the original file → same error with new persisted file
  5. Model reads new persisted file (now with doubled formatting) → same error with tripled formatting
  6. 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

View original on GitHub ↗

5 Comments

github-actions[bot] · 7 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/30448
  2. https://github.com/anthropics/claude-code/issues/20223
  3. https://github.com/anthropics/claude-code/issues/25274

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

thoeltig · 7 months ago

Not a duplicate. The provided tickets describe different problem areas:

  1. https://github.com/anthropics/claude-code/issues/30448
  • Here the model also reads from the tool use result folder but apparently from a previous session. Not sure how this can happen but it might be like the scenario described in my ticket that the file was too large, displayed the user success but returned a filepath to the model instead. if so and the returned filepath also had the wrong session id that would be even worse. But i cannot say for sure because the issue is missing information to verify this.
  1. https://github.com/anthropics/claude-code/issues/20223
  • This issue is about the formatting itself and that it generates a lot of overhead and wastes tokens. This issue and my ticket are related but not the same problem. My ticket is partially a cascading failure but can not completely be solved by solving the other issue.
  1. https://github.com/anthropics/claude-code/issues/25274
  • Seems like a problem with the edit tool result contains the full file content on lines changed. This is a different tool.
thoeltig · 6 months ago

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.

thoeltig · 6 months ago

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:

 {
                "type": "tool_result",
                "content": "File content (59557 tokens) exceeds maximum allowed tokens (40000). Use offset and limit parameters to read specific portions of the file, or search for specific content instead of reading the whole file.",
                "is_error": true,
                "tool_use_id": "[TOOL_USE_ID]"
}

Thanks I will close the issue now because that fixes the issue.

github-actions[bot] · 6 months ago

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.