claude-code - 💡(How to fix) Fix [Bug] Parallel sub-agents inherit full parent context, causing excessive token consumption without cost warnings [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#56068Fetched 2026-05-05 05:59:01
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×3commented ×1

Error Message

[{"error":"Error: NON-FATAL: Lock acquisition failed for /Users/diego/.local/share/claude/versions/2.1.122 (expected in multi-process scenarios)\n at x86 (/$bunfs/root/src/entrypoints/cli.js:2769:2177)\n at jw8 (/$bunfs/root/src/entrypoints/cli.js:2769:1257)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:22:46.717Z"},{"error":"MaxFileReadTokenExceededError: File content (39501 tokens) exceeds maximum allowed tokens (25000). Use offset and limit parameters to read specific portions of the file, or search for specific content instead of reading the whole file.\n at qm7 (/$bunfs/root/src/entrypoints/cli.js:4852:12789)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:47:43.655Z"},{"error":"AxiosError: Request failed with status code 403\n at Cn (/$bunfs/root/src/entrypoints/cli.js:115:1194)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:120:12716)\n at emit (node:events:92:22)\n at endReadableNT (internal:streams/readable:865:50)\n at processTicksAndRejections (native:7:39)\n at request (/$bunfs/root/src/entrypoints/cli.js:122:2467)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:48:33.470Z"},{"error":"AxiosError: Request failed with status code 403\n at Cn (/$bunfs/root/src/entrypoints/cli.js:115:1194)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:120:12716)\n at emit (node:events:92:22)\n at endReadableNT (internal:streams/readable:865:50)\n at processTicksAndRejections (native:7:39)\n at request (/$bunfs/root/src/entrypoints/cli.js:122:2467)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:48:52.329Z"},{"error":"AxiosError: timeout of 5000ms exceeded\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:120:13313)\n at emit (node:events:92:22)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:119:3321)\n at request (/$bunfs/root/src/entrypoints/cli.js:122:2467)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T21:08:49.760Z"},{"error":"Error: Failed to fetch version from https://downloads.claude.ai/claude-code-releases/latest: timeout of 30000ms exceeded\n at hj5 (/$bunfs/root/src/entrypoints/…

Root Cause

WHAT HAPPENED The model launched 4 parallel sub-agents (forks) for research without estimating or warning me about the cost. One of the forks was tasked with reading 24 local files with known keywords — work that a single grep command would have done at <20K tokens, but as a fork it consumed 106K tokens because forks inherit the full parent context (~120K tokens of system prompts + conversation history) on top of doing the task.

Code Example

[{"error":"Error: NON-FATAL: Lock acquisition failed for /Users/diego/.local/share/claude/versions/2.1.122 (expected in multi-process scenarios)\n    at x86 (/$bunfs/root/src/entrypoints/cli.js:2769:2177)\n    at jw8 (/$bunfs/root/src/entrypoints/cli.js:2769:1257)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:22:46.717Z"},{"error":"MaxFileReadTokenExceededError: File content (39501 tokens) exceeds maximum allowed tokens (25000). Use offset and limit parameters to read specific portions of the file, or search for specific content instead of reading the whole file.\n    at qm7 (/$bunfs/root/src/entrypoints/cli.js:4852:12789)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:47:43.655Z"},{"error":"AxiosError: Request failed with status code 403\n    at Cn (/$bunfs/root/src/entrypoints/cli.js:115:1194)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:120:12716)\n    at emit (node:events:92:22)\n    at endReadableNT (internal:streams/readable:865:50)\n    at processTicksAndRejections (native:7:39)\n    at request (/$bunfs/root/src/entrypoints/cli.js:122:2467)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:48:33.470Z"},{"error":"AxiosError: Request failed with status code 403\n    at Cn (/$bunfs/root/src/entrypoints/cli.js:115:1194)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:120:12716)\n    at emit (node:events:92:22)\n    at endReadableNT (internal:streams/readable:865:50)\n    at processTicksAndRejections (native:7:39)\n    at request (/$bunfs/root/src/entrypoints/cli.js:122:2467)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:48:52.329Z"},{"error":"AxiosError: timeout of 5000ms exceeded\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:120:13313)\n    at emit (node:events:92:22)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:119:3321)\n    at request (/$bunfs/root/src/entrypoints/cli.js:122:2467)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T21:08:49.760Z"},{"error":"Error: Failed to fetch version from https://downloads.claude.ai/claude-code-releases/latest: timeout of 30000ms exceeded\n    at hj5 (/$bunfs/root/src/entrypoints/
RAW_BUFFERClick to expand / collapse

Bug Description Hi — reporting a session-cost issue with Claude Code on Claude Opus 4.7 (1M context).

DATE: 2026-04-28 MODEL: claude-opus-4-7 (1M context) OUTCOME: 425K tokens consumed in a single session ($10 USD), hit 96% of my usage limit, blocked from Claude for ~4 hours. The session produced no usable deliverable for the task I requested.

WHAT HAPPENED The model launched 4 parallel sub-agents (forks) for research without estimating or warning me about the cost. One of the forks was tasked with reading 24 local files with known keywords — work that a single grep command would have done at <20K tokens, but as a fork it consumed 106K tokens because forks inherit the full parent context (~120K tokens of system prompts + conversation history) on top of doing the task.

TOKEN USAGE FROM THE 4 FORKS (numbers reported by the model itself):

  • Fork 1 (local file scan, replaceable by grep): 106,421 tokens
  • Fork 2 (web research, MLRR T-MEC): 70,062 tokens
  • Fork 3 (web research, labor reform): 82,057 tokens
  • Fork 4 (web research, Audi data): 68,890 tokens Subtotal forks: 327,430 tokens Parent conversation (estimated, no API to query): ~95–110K tokens

WHAT I'D LIKE

  1. Clarification on whether tokens consumed by sub-agent forks count against my user usage limit (they appear to).
  2. Consideration for partial restoration of my usage limit given the wasteful execution pattern.
  3. Forward the following product feedback to the Claude Code team.

PRODUCT FEEDBACK

  1. No warning when the user usage limit approaches 80/90/95%.
  2. No way for the model to query its own session cost in real time before launching expensive operations (no internal /cost equivalent).
  3. No automatic warning when a batch of parallel forks is about to replicate large amounts of inherited context.
  4. The model's documented heuristic ("forks are cheap because they share prompt cache") encourages over-forking even when a simple grep/Read would be both faster and cheaper. The cache-sharing claim is true for cache HIT cost, but does not eliminate the cost of replicated input on first use across N parallel forks.
  5. When a fork's transcript is in /private/tmp/... and the system prompt warns the model not to read it, the only way to preserve fork output across sessions is to write it to disk — which costs additional output tokens. Suggest an API to retrieve fork output as plain text.

I can share a full technical report from the session if helpful. Thank you

Environment Info

  • Platform: darwin
  • Terminal: Apple_Terminal
  • Version: 2.1.122
  • Feedback ID: 031a11b1-8a6e-46f3-8981-e108deda3570

Errors

[{"error":"Error: NON-FATAL: Lock acquisition failed for /Users/diego/.local/share/claude/versions/2.1.122 (expected in multi-process scenarios)\n    at x86 (/$bunfs/root/src/entrypoints/cli.js:2769:2177)\n    at jw8 (/$bunfs/root/src/entrypoints/cli.js:2769:1257)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:22:46.717Z"},{"error":"MaxFileReadTokenExceededError: File content (39501 tokens) exceeds maximum allowed tokens (25000). Use offset and limit parameters to read specific portions of the file, or search for specific content instead of reading the whole file.\n    at qm7 (/$bunfs/root/src/entrypoints/cli.js:4852:12789)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:47:43.655Z"},{"error":"AxiosError: Request failed with status code 403\n    at Cn (/$bunfs/root/src/entrypoints/cli.js:115:1194)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:120:12716)\n    at emit (node:events:92:22)\n    at endReadableNT (internal:streams/readable:865:50)\n    at processTicksAndRejections (native:7:39)\n    at request (/$bunfs/root/src/entrypoints/cli.js:122:2467)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:48:33.470Z"},{"error":"AxiosError: Request failed with status code 403\n    at Cn (/$bunfs/root/src/entrypoints/cli.js:115:1194)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:120:12716)\n    at emit (node:events:92:22)\n    at endReadableNT (internal:streams/readable:865:50)\n    at processTicksAndRejections (native:7:39)\n    at request (/$bunfs/root/src/entrypoints/cli.js:122:2467)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T20:48:52.329Z"},{"error":"AxiosError: timeout of 5000ms exceeded\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:120:13313)\n    at emit (node:events:92:22)\n    at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:119:3321)\n    at request (/$bunfs/root/src/entrypoints/cli.js:122:2467)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-04-28T21:08:49.760Z"},{"error":"Error: Failed to fetch version from https://downloads.claude.ai/claude-code-releases/latest: timeout of 30000ms exceeded\n    at hj5 (/$bunfs/root/src/entrypoints/…

Note: Content was truncated.

extent analysis

TL;DR

To mitigate the issue, consider optimizing the use of parallel sub-agents (forks) in Claude Code, especially when tasks can be achieved with simpler, less token-intensive methods like grep.

Guidance

  1. Review fork usage: Assess whether tasks assigned to forks can be simplified or replaced with more token-efficient methods.
  2. Estimate token costs: Before launching expensive operations, estimate the potential token cost, considering the inherited context and task requirements.
  3. Implement token-efficient alternatives: For tasks like file scanning, use methods like grep instead of launching a fork, which can significantly reduce token consumption.
  4. Monitor usage limits: Regularly check your usage limits to avoid unexpected blocks, and plan your tasks accordingly to stay within these limits.

Example

For file scanning tasks, using grep can be significantly more token-efficient than launching a fork. For instance, instead of:

# Launching a fork for file scanning (high token cost)
claude-code --fork scan-files --files /path/to/files

Use:

# Using grep for file scanning (lower token cost)
grep -r "keyword" /path/to/files

Notes

The provided solution focuses on optimizing the use of Claude Code's features to reduce token consumption. However, for a comprehensive fix, it's essential to address the underlying issues, such as the lack of warning mechanisms for approaching usage limits and the inefficiency of forked tasks. The user's product feedback highlights several areas for improvement in Claude Code.

Recommendation

Apply the workaround by optimizing fork usage and exploring token-efficient alternatives for tasks. This approach can help mitigate the issue until more comprehensive solutions or updates are available from the Claude Code team.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [Bug] Parallel sub-agents inherit full parent context, causing excessive token consumption without cost warnings [1 comments, 2 participants]