Repository navigation
π janitor: prune idle Claude CLI session scratch under the temp directory - #18349
Conversation
β¦tory The Claude CLI keeps per-session scratch in <tmp>/claude-<uid>/<project>/ <session>/ and never removes it. It lives in the container's writable layer, not on /data, so no existing janitor class saw it. On one Docker host two spokes reached 17 GiB and 22 GiB and filled the root disk. PruneClaudeTmp removes each session directory whose newest write anywhere inside is older than 24 hours, reusing the home sweep's symlink-safe newest-write rule, and runs on the janitor's existing 6-hour tick. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: James Reilly <jreilly1821@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
Mutation testingHead 6 mutant(s) in changed files are not reached by any test (NOT COVERED). A maintainer may apply the
Verdict: |
There was a problem hiding this comment.
Correctness review at 3c1fa0b: no blocker. The prune reuses pruneHomeTarget and newestModTime (homeprune.go:128, prune.go:123), which are symlink-safe and keep the directory on any walk error. Depth is limited to claude-*/<project>/<session>.
Two low advisories:
tmpprune.go:71-72deletes any idle directory at session depth.IsSessionDirName(prune.go:148) already exists, so an optional guard narrows this to real session UUIDs:
if !session.IsDir() || !IsSessionDirName(session.Name()) {
- A live session with no writes for 24h is indistinguishable from a finished one and loses its scratch. The PR documents this trade-off, so it is advisory only.
β hive: agent=adjudicator backend=claude model=claude-sonnet-5-5 claude=2.1.325
Problem
The Claude CLI keeps per-session scratch in
<tmp>/claude-<uid>/<project>/<session>/: task output, scratchpads, and whatever an agent clones or builds there. Nothing removes it when the session ends.It lives in the container's writable layer, not on
/data, so none of the janitor's existing classes see it, and it fills the node's root disk rather than the data volume.On a Docker Compose host running two v6 spokes:
schoolgrew 17 GiB andreefgrew 22.6 GiB of container writable layer, almost all of it/tmp/claude-*/-data-agents-<agent>/<session>.Change
sessionprune.PruneClaudeTmp(tmpRoot, maxAge, now, logger)removesclaude-*/<project>/<session>directories whose newest write anywhere inside is older thanmaxAge.pruneHomeTarget, so it never follows symlinks, keeps a directory on any stat or walk failure, and only looks at that exact depth./tmp.DefaultTmpRetentionHours = 24. A resumed session loses only its scratch; its transcript lives under the agent home.runAgentHomePrune. It logsclaude tmp prune completeonly when it removed something.docs/diskpressure-recovery-runbook.md.Tests
tmpprune_test.gocovers:claude-*/<project>/<session>shape are kept.maxAge <= 0are no-ops.go test ./pkg/sessionprune/ ./cmd/hive/,go vet,gofmtandgo build ./cmd/hive/all pass.π€ Generated with Claude Code