claude-code - 💡(How to fix) Fix [BUG] Hook output and tool-result capture files in /tmp/claude-{uid}/<cwd>/tasks/ accumulate ~19MB null padding per file (missing ftruncate) [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#56876Fetched 2026-05-07 03:43:05
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×5commented ×1

Fix Action

Fix / Workaround

Environment

  • OS: Linux 6.17 (Ubuntu 24.04)
  • Claude Code: VS Code extension (anthropic.claude-code 2.1.131-linux-x64)
  • Auth: claude.ai OAuth (subscription)
  • maxOutputTokens: was 128000 (now lowered to 32000 as a workaround)

Workaround we deployed locally

Code Example

du -sh /tmp/claude-$(id -u)/-home-*/tasks/

---

od -c /tmp/claude-$(id -u)/<project>/<session>/tasks/hook_<pid>.output | head -5

---

stat <file>

---

0000000  \0  \0  \0  \0  \0  \0  \0  \0  ...   (continues for ~19.55 MB)
*
0112520374   m   (   p   e   r   -   s   t   e   p ...   (real stdout starts at offset ~19.55 MB)
0112526337
RAW_BUFFERClick to expand / collapse

Environment

  • OS: Linux 6.17 (Ubuntu 24.04)
  • Claude Code: VS Code extension (anthropic.claude-code 2.1.131-linux-x64)
  • Auth: claude.ai OAuth (subscription)
  • maxOutputTokens: was 128000 (now lowered to 32000 as a workaround)

Summary

Files written to /tmp/claude-{uid}/<cwd-slug>/<session-id>/tasks/hook_<pid>.output (the path used to capture hook stdout that exceeds the documented 10K char inline cap, and the same path used for large tool-subagent results per #26911) are observed at ~19,562,240 bytes each, of which only ~9 KB is the actual captured output. The remainder is a contiguous tail of NULL bytes.

Math: 19,562,240 / 128,000 ≈ 153 bytes per maxOutputToken — strongly suggests the runtime pre-allocates a buffer sized to maxOutputTokens × bytes-per-token-upper-bound, then writes the actual (much smaller) captured output without subsequently calling ftruncate(fd, real_size) or opening with O_TRUNC. This is the same bug class documented in #51435 for the skill-upload writer.

Reproduction

  1. Configure a SessionStart:compact hook that emits >10K chars of stdout (e.g., the user's compact-context-reinject.sh which cats a CONTEXT_STATE.md-style file).
  2. Use Claude Code in the project for several sessions.
  3. du -sh /tmp/claude-$(id -u)/-home-*/tasks/
    Accumulates ~19 MB per stdout-capturing hook fire (~80–100 MB per project per session in heavy use).
  4. od -c /tmp/claude-$(id -u)/<project>/<session>/tasks/hook_<pid>.output | head -5
    Confirms NULL prefix (\\0 \\0 \\0 ...).
  5. stat <file>
    Blocks * 512 ≈ apparent size — file is real on disk, NOT sparse.

Local file shape (verified on user's machine):

0000000  \0  \0  \0  \0  \0  \0  \0  \0  ...   (continues for ~19.55 MB)
*
0112520374   m   (   p   e   r   -   s   t   e   p ...   (real stdout starts at offset ~19.55 MB)
0112526337

File size: 19,570,940 bytes. Real content: last ~8.7 KB. Prefix: ~19.55 MB of NULLs.

Impact

  • Disk leak: ~19 MB per stdout-capturing hook fire; 80–100+ MB per project per session.
  • Compounds existing #26911 (no cleanup of tasks/.output files at all).
  • Possibly contributes to GUI freeze symptoms of #23053 / #51560 when the runtime later reads these files back for context injection (extra MB of NULLs to scan/skip).

Suggested fix

After the captured output is written and before the file is closed, call ftruncate(fd, actualBytesWritten). Alternatively open with O_TRUNC on each new capture. Same fix shape proposed for #51435.

Relation to other issues

  • Same path as #26911 (no cleanup) — fixing this would not remove the need for cleanup, but it would reduce per-file size by ~99.95%, making the existing accumulation far less harmful.
  • Same bug class as #51435 (missing ftruncate in another writer).
  • Possibly contributes to symptoms of #23053 / #51560 (large-payload streaming freeze) by inflating bytes the runtime later re-reads from these files into the chat stream.

Workaround we deployed locally

SessionStart/Stop hook that runs find /tmp/claude-$(id -u) -path '*/tasks/hook_*.output' -size +1M -delete. Real hook stdout is always tiny so the 1 MB threshold is safe.

Additional observation

The user's project-level maxOutputTokens: 128000 may be unusually high (default is lower). Lowering it to 32000 reduces the per-file disk waste by 4×. Worth documenting that this setting affects disk usage in /tmp until the underlying truncation bug is fixed.


Investigation report (private to user, but happy to share excerpts): the bloated null-padded files were initially suspected to cause the "Transmuting…" GUI freeze, but on closer reading the freeze itself is more likely the streaming-time main-thread stall already documented in #23053 / #51560. The disk leak documented here is a separate, real bug.

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] Hook output and tool-result capture files in /tmp/claude-{uid}/<cwd>/tasks/ accumulate ~19MB null padding per file (missing ftruncate) [1 comments, 2 participants]