[BUG] Claude Code ingests massive tool outputs without truncation, causing context overflow
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
- Have a codebase with many TypeScript errors (e.g., from git
worktrees or legacy code)
- Run any command that outputs these errors: yarn run dev, npm run
build, etc.
- OR call mcp__ide__getDiagnostics without a specific uri
parameter
- Observe: Context immediately fills up, session becomes unusable
Expected Behavior
Claude Code should:
- Truncate large outputs: Limit to first/last N lines with summary
(e.g., "... 3000 errors omitted ...")
- Smart sampling: For repetitive errors, show a few examples +
count
- Warn before ingestion: Alert when output exceeds threshold
(e.g., ">50k tokens detected. Ingest? y/n")
- Token budgets per tool: Prevent single tool call from consuming
>20% of context
- Pattern detection: Recognize repeated error patterns and
summarize instead of listing all
- 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
- Add configurable output truncation (default: 10k tokens max per
tool call)
- Implement smart output summarization for known patterns
(TypeScript errors, test failures, etc.)
- Make getDiagnostics default to checking only recently modified
files
- Add --filter-output or similar flag to Bash tool for
pattern-based filtering
- 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:
- Truncate large outputs: Limit to first/last N lines with summary
(e.g., "... 3000 errors omitted ...")
- Smart sampling: For repetitive errors, show a few examples +
count
- Warn before ingestion: Alert when output exceeds threshold
(e.g., ">50k tokens detected. Ingest? y/n")
- Token budgets per tool: Prevent single tool call from consuming
>20% of context
- Pattern detection: Recognize repeated error patterns and
summarize instead of listing all
- 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
- 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
- Start Claude Code in the project directory
- Method 1 - Via Bash command:
- Ask Claude: "Run yarn dev and check for errors"
- Claude runs:
yarn run devoryarn build - TypeScript outputs 3000+ compilation errors to terminal
- Result: Context immediately fills up → "Context low" error
- 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
- 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗