[BUG] Claude Code ingests massive tool outputs without truncation, causing context overflow

Resolved 💬 3 comments Opened Nov 20, 2025 by malani-saurav Closed Nov 24, 2025

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?

Summary

Claude Code ingests all output from tool calls without intelligent
truncation or safeguards, leading to frequent "context low" errors
when tools return large responses. This affects multiple tools
including Bash, mcp__ide__getDiagnostics, and potentially any tool
that can produce large outputs.

Problem Details

When tools return large outputs, Claude Code ingests the entire
response into context, regardless of size:

Example 1: getDiagnostics

  • Single call to mcp__ide__getDiagnostics() without URI parameter

returned ALL workspace diagnostics

  • Result: 3,003 diagnostic issues, ~580,700 tokens, 65,474+ lines
  • This single tool call consumed almost the entire remaining

context

Example 2: Bash commands

  • Running yarn run dev which outputs TypeScript compilation errors
  • TypeScript found 3,003 errors from scanning git worktrees
  • All terminal output ingested into context → immediate "context

low" error

  • Even after creating tsconfig.local.json to exclude worktrees,

testing the fix triggered the same issue again

Steps to Reproduce

  1. Have a codebase with many TypeScript errors (e.g., from git

worktrees or legacy code)

  1. Run any command that outputs these errors: yarn run dev, npm run

build, etc.

  1. OR call mcp__ide__getDiagnostics without a specific uri

parameter

  1. Observe: Context immediately fills up, session becomes unusable

Expected Behavior

Claude Code should:

  1. Truncate large outputs: Limit to first/last N lines with summary

(e.g., "... 3000 errors omitted ...")

  1. Smart sampling: For repetitive errors, show a few examples +

count

  1. Warn before ingestion: Alert when output exceeds threshold

(e.g., ">50k tokens detected. Ingest? y/n")

  1. Token budgets per tool: Prevent single tool call from consuming

>20% of context

  1. Pattern detection: Recognize repeated error patterns and

summarize instead of listing all

  1. Targeted diagnostics: Agents should default to checking only

modified files, not entire workspace

Actual Behavior

All output is ingested without limits, making multi-agent workflows
unusable in codebases with pre-existing errors or verbose build
outputs.

Impact

  • Breaks multi-agent workflows: Agents complete work successfully,

but diagnostic checks crash the session

  • Prevents testing fixes: Can't verify solutions without triggering

the same issue

  • Wastes user context: Pre-existing unrelated errors consume tokens

meant for actual work

  • Poor UX: Users forced to manually fix unrelated issues (like

excluding worktrees) just to use Claude Code

Suggested Fixes

  1. Add configurable output truncation (default: 10k tokens max per

tool call)

  1. Implement smart output summarization for known patterns

(TypeScript errors, test failures, etc.)

  1. Make getDiagnostics default to checking only recently modified

files

  1. Add --filter-output or similar flag to Bash tool for

pattern-based filtering

  1. Show token cost preview before ingesting large responses

Environment

  • Claude Code version: v2.0.46
  • Model: Sonnet 4.5
  • OS: macOS (Darwin 24.6.0)
  • Codebase: Large TypeScript monorepo with git worktrees

What Should Happen?

Claude Code should:

  1. Truncate large outputs: Limit to first/last N lines with summary

(e.g., "... 3000 errors omitted ...")

  1. Smart sampling: For repetitive errors, show a few examples +

count

  1. Warn before ingestion: Alert when output exceeds threshold

(e.g., ">50k tokens detected. Ingest? y/n")

  1. Token budgets per tool: Prevent single tool call from consuming

>20% of context

  1. Pattern detection: Recognize repeated error patterns and

summarize instead of listing all

  1. Targeted diagnostics: Agents should default to checking only

modified files, not entire workspace

Error Messages/Logs

⎿  Found 3003 new diagnostic issues in 1 file (ctrl+o to expand)
  ⎿  Context low · Run /compact to compact & continue

Steps to Reproduce

Steps to Reproduce

  1. Set up a TypeScript project with many existing errors (3000+)
  • Option A: Create git worktrees in your repo
  • Option B: Use any large legacy codebase with pre-existing TS

errors

  1. Start Claude Code in the project directory
  1. Method 1 - Via Bash command:
  • Ask Claude: "Run yarn dev and check for errors"
  • Claude runs: yarn run dev or yarn build
  • TypeScript outputs 3000+ compilation errors to terminal
  • Result: Context immediately fills up → "Context low" error
  1. Method 2 - Via getDiagnostics:
  • Start a multi-agent workflow (e.g., implementing a feature)
  • Agents complete their work successfully
  • Agent calls mcp__ide__getDiagnostics() without URI parameter

to check for errors

  • Result: Returns ALL workspace diagnostics (~580k tokens) →

"Context low" error

  1. Observe: Session becomes unusable, all context consumed by error

output

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

Claude Code v2.0.46

Platform

Other

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

this is happening in claude code.

View original on GitHub ↗

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