Repository navigation
Conversation
…disk CLAUDE_CODE_SHELL=/bin/bash in managed settings: zsh-only behavior (NOMATCH, EQUALS, no word splitting, oh-my-zsh aliases) failed ~330 Bash calls across 63 sessions in one downstream project. prune-claude-disk, an async managed SessionStart hook, deletes other sessions' scratchpads idle > 1 day (keeping any with unpushed git work), npx installs > 7 days old and the npm cache above 1 GB. verify-image.sh checks the wiring and runs it against a clean and a dirty stale scratchpad.
…aude-disk prune-claude-disk deleted things it should keep (probed in the published image): - Claude Code's own temp dirs (bash-edit-diff/, the s/<hash> short scratchpad), as any second-level dir without a transcript counted as a stale session. Only <project>/<session-uuid>/ dirs with a scratchpad/ are considered now. - scratchpads of running sessions. It now skips sessions listed in $CLAUDE_CONFIG_DIR/sessions/*.json and dirs with a file or transcript newer than SCRATCH_DAYS, so a missing transcript no longer means stale. - detached-HEAD commits, stashes, repos nested deeper than four levels, and repos git can't read. The repo search has no depth limit (skipping node_modules), HEAD and refs/stash count as unsaved, and a git failure keeps the scratchpad. - the package of a running npx MCP server once its _npx entry is 7 days old. An entry named by a running `npm exec` is skipped. Also: the temp root honours CLAUDE_CODE_TMPDIR and TMPDIR, deleted linked worktrees are pruned from their main repo, the npm cache path comes from `npm config get cache`, and git runs with --no-optional-locks. CLAUDE_CODE_SHELL moves from managed env to an image ENV, because a managed env value overrides the user's settings and containerEnv. The async hook's timeout is dropped (Claude Code doesn't enforce it on async hooks), and it runs only on startup and resume. The README says Claude, not the user, gets the systemMessage. verify-image.sh runs the hook in a throwaway HOME and temp root, and adds a detached-HEAD case and a recent-session case. The old script fails it.
…claude-disk rm -rf can't empty a 0555 dir such as Go's module cache, so those scratchpads were retried and never freed; make the tree writable first. A running `npx -p <pkg> <bin>` shows as `npm exec <bin>`, so the running-guard also matches the entry's node_modules/.bin names. `npm config get cache --logs-max=0` stops a debug log per run.
…d-disk-prune # Conflicts: # claude-code/verify-image.sh
gatezh
changed the base branch from
master
to
claude-code/vendor-marketplace-autoupdate
November 27, 2026 20:22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
In
claude-codeandclaude-code-sandbox, Claude Code's Bash tool runs bash instead of zsh. A new managedSessionStarthook also removes disk space that earlier sessions left behind, without touching running sessions or unsaved git work.Why
Shell. The image sets
SHELL=/usr/bin/zsh, so the Bash tool ran zsh, while Claude writes bash. Across 85 session transcripts from one downstream project, about 330 Bash calls in 63 sessions failed on zsh-only behavior:no matches found: --include=*.mdNOMATCH)===== not found=becomes a command-path lookup (EQUALS)no such file or directory: git -c safe.directory=…$CMD argsdoesn't word-splitparse error near ()galias breaksg() { … }bad substitution$B:src/…is read as a:smodifierEach one cost a retry. The interactive terminal stays zsh.
Disk. The container's disk is the host's. In the same project, five sessions had each cloned the same CMS repo into their scratchpads and installed its packages (~730 MB each). npx had fetched the Sanity CLI twice, once as
sanityand once assanity@latest(555 MB each), and the npm cache held 1.6 GB. Claude Code's own sweep deletes a scratchpad only together with its transcript, aftercleanupPeriodDays(30 days by default; #173 proposes 365).Changes
Dockerfile:ENV CLAUDE_CODE_SHELL=/bin/bash, which Claude Code reads before$SHELL. It's set at the end of thesharedstage, so the Chromium and Claude Code layers stay cached. The script is installed as/usr/local/bin/prune-claude-disk.managed-settings.json:SessionStarthook,prune-claude-disk. It's async, with matcherstartup|resume.claudeMdparagraph: keep one checkout per other repo at~/src/<repo>, don't usenpx <pkg>@latest, and clear large scratchpad contents at the end of a task.prune-claude-disk.sh(new). It deletes:another session's scratchpad dir (
<tmp>/claude-<uid>/<project>/<session-uuid>/) when all of these hold:$CLAUDE_CONFIG_DIR/sessions/*.json.SCRATCH_DAYS(1).Kept scratchpads are named to Claude in a
systemMessage. Linked worktrees it deletes are pruned from their main repo, so their branch isn't left "already used by worktree".<tmp>followsCLAUDE_CODE_TMPDIR, then$TMPDIR, then/tmp. Claude Code's other dirs there (bash-edit-diff/, thes/<hash>short scratchpad) are skipped._npxentries unused forNPX_DAYS(7). npx bumps an entry's mtime on each use. An entry is skipped when a runningnpm execnames its package or one of its bins, such as the Playwright plugin's MCP server.the npm cache, once it passes
CACHE_MAX_MB(1024). The path comes fromnpm config get cache.The script prints only JSON.
verify-image.sh: checks the env value,/bin/bash, the hook wiring and theclaudeMdtext. It runs the script in a throwawayHOMEand temp root: a stale clean scratchpad must be deleted, while a stale one whose only commit is on a detached HEAD and a recent one must be kept.claude-code/README.md: new section "Claude Code shell and disk cleanup", including how to switch back to zsh.Notes
Why an image
ENV, not managedenv: a managedenvvalue overrides user settings, project settings andcontainerEnv(settings-reference,env). Nobody could switch back to zsh. With theENV, a settingsenvorcontainerEnvcan override it.CLAUDE_CODE_SHELLis documented on the env-vars page and isn't on the list of variables Claude Code ignores inenv.Why a setting, not a PreToolUse hook: a hook would have to recognize every zsh pattern, and each warning would cost a round trip. The setting removes the whole class of failures.
Async: the first run in a bloated container walks gigabytes. The async hook's
systemMessagereaches Claude on its next turn and isn't shown to the user. Claude Code doesn't enforcetimeouton async hooks, so none is set.Native options checked:
npm cache npx rmdeletes the same way, with no age filter.npm cache verifygarbage-collects but has no size cap.The script uses Claude Code's own
sessions/registry for liveness.npm cache clean --forceracing an install: probed. Four concurrentnpm install --prefer-offlineruns all succeeded while the cache was wiped, because npm refetches.Tested:
claude-code:latestwith the script mounted. It covers clean, detached HEAD, stash-only, a repo 6 levels deep, a dirty worktree, no remote, corrupt HEAD, a running session, a fresh session with no transcript, a clean worktree, and a read-only tree. Only the clean ones were deleted.npxserver's entry, backdated 10 days, was kept.verify-image.shblock passes there, and fails with this PR's first version of the script.bash -nare clean. Hadolint v2.12.0 shows no findings on master or the branch. All.shfiles are100755.Owner's call: the limit variables keep their unprefixed names (
SCRATCH_DAYS,NPX_DAYS,CACHE_MAX_MB).ralphex-feis left out: it has its own managed settings and runs unattendedclaude -p.Wiki: no page goes stale. After the merge,
Docker-Disk-Maintenancecould link to the new README section.