statusline-command.sh: /tmp leak from pai-parallel-$$ dirs that are never cleaned up
Observed behavior
On a headless Linux VM (Ubuntu, ext4, 45 GB disk), /tmp accumulated ~350,000 pai-parallel-* directories over ~17 days, consuming ~8 GB of filesystem block metadata and pushing the disk to 97% full.
Each directory contained 5 small shell variable files (git.sh, location.sh, weather.sh, counts.sh, usage.sh) or was completely empty.
What I can confirm
statusline-command.sh creates a per-invocation working directory at /tmp/pai-parallel-$$ (line 490 in v5.0.0) and has rm -rf cleanup near the end of the script (line 793 in my copy). Despite the cleanup code existing:
- Directories accumulate — so the cleanup line is not being reached on a significant proportion of invocations
- There is no
set -eor earlyexitthat would skip the cleanup - A
trap '..' EXIT INT TERM HUPdoes not help — Claude Code invokes the script via/bin/sh -c, and when that parent shell is terminated, the child bash process (blocked inwaitcollecting the parallel subshells) never receives the signal. Tested empirically: the trap does not fire under this termination pattern
The most likely explanation is that Claude Code kills the statusline process externally before it completes, but I have not confirmed this from the Claude Code side.
Working fix
Replace exit-path cleanup with entry-path cleanup. Keep per-PID dirs for concurrency safety (a fixed-name dir causes a race condition — concurrent sessions clobber each other's files mid-source, dropping statusline sections). Each invocation background-cleans dirs older than 1 minute:
_parallel_tmp="/tmp/pai-parallel-$$"
find /tmp -maxdepth 1 -name 'pai-parallel-*' -type d -mmin +1 -exec rm -rf {} + 2>/dev/null &
mkdir -p "$_parallel_tmp"
Steady state after this fix: ~150 dirs (~600 KB) instead of unbounded accumulation. Verified stable over multiple minutes across concurrent sessions.
Environment
- PAI v5.0.0
- Ubuntu 22.04 (headless VM), ext4, 45 GB disk
- Claude Code running via SSH, multiple concurrent sessions common
- Statusline invoked continuously over ~17 days
macOS note: the recommended find /tmp … fix is a silent no-op on macOS
Hit this same leak on macOS (Apple Silicon) — ~28k pai-parallel-* dirs. Applied the suggested entry-path cleanup verbatim and it removed nothing; the count didn't move.
Root cause: on macOS /tmp is a symlink to /private/tmp. find /tmp … (no trailing slash, no -L) treats the symlinked start point as a symlink and doesn't descend into it, so -name 'pai-parallel-*' never matches — the cleanup silently does nothing (ironically the same "looks like it ran, didn't" failure mode as the original leak).
Fix — add a trailing slash (forces traversal) or -L:
# cross-platform (Linux + macOS)
find /tmp/ -maxdepth 1 -name 'pai-parallel-*' -type d -mmin +1 -exec rm -rf {} + 2>/dev/null &
mkdir -p "$_parallel_tmp"
Verified on macOS (with ~28k dirs present):
find /tmp -maxdepth 1 -name 'pai-parallel-*' -type d→ 0 matches (symlink not traversed)find /tmp/ …(trailing slash),find -L /tmp …, andfind /private/tmp …→ each matches all ~28k- After the corrected sweep: ~28k → a handful of live (<1 min) dirs, exactly the intended steady state.
So the proposed fix is correct — it just needs the trailing slash (or -L) to also work on macOS. 🙏
Hey @tzioup, thank you for the PR and the work that went into it.
We're changing how LifeOS ships: from a full ~/.claude directory you run as-is, to a skill installed by an agentic installer that has your own AI integrate the pieces into your setup. That reworks the parts of the codebase this change touches, so it won't apply cleanly to where we're headed.
We're closing it for that reason, not because the idea was wrong. If the need still stands against the new model, we'd love a fresh PR once it lands. Thanks again for contributing.