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

Resolved 💬 5 comments Opened Mar 7, 2026 by thoeltig 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 ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗