maintenance(shell): guard against unwritable inherited TMPDIR in headless contexts#51
Merged
Merged
Conversation
…less contexts A headless / launchd-launched agent (the 24/7 Mac mini) inherits the generic macOS fallback temp dir (TMPDIR=/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T, owned root:wheel mode 0700) instead of the per-user temp, because launchd never set up the DARWIN_USER_TEMP_DIR bootstrap. Any tool that writes to $TMPDIR then fails with EACCES — e.g. `vitest run` (its coverage provider mkdir's under $TMPDIR), npm, and esbuild. Add a guard to .zprofile that points TMPDIR/TMP/TEMP at ~/.claude/tmp ONLY when the inherited value is unset or not writable, so healthy interactive machines keep the system temp dir untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds a guarded TMPDIR/TMP/TEMP override in the shell profile to ensure a writable temp directory in headless or launchd-launched contexts while leaving normal interactive shells untouched. Flow diagram for guarded TMPDIR override in .zprofileflowchart TD
A[Shell startup
.zprofile] --> B[Check TMPDIR is set]
B -->|unset| D[Override TMPDIR TMP TEMP to ~/.claude/tmp]
B -->|set| C[Check TMPDIR is writable]
C -->|not writable| D
C -->|writable| E[Keep inherited TMPDIR]
D --> F[mkdir -p ~/.claude/tmp]
F --> G[Continue shell init]
E --> G
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Problem
The 24/7 headless Mac mini agent (and any launchd-launched shell) inherits the generic macOS fallback temp dir:
instead of the per-user temp — because a launchd-less/headless context never sets up the
DARWIN_USER_TEMP_DIRbootstrap. That directory is not writable by the user, so any tool that writes to$TMPDIRfails withEACCES:vitest run— its coverage providermkdirs a working dir under$TMPDIRnpm,esbuild, and other temp-writing tooling, intermittentlyIt is not a sandbox/permissions issue — the bad
TMPDIRis inherited from the launch environment.Fix
Add a guard to
shell/.zprofilethat repointsTMPDIR/TMP/TEMPat~/.claude/tmponly when the inherited value is unset or not writable. Healthy interactive machines (which get a proper writable per-user temp) are left untouched.Testing
bash -nandzsh -npass.zzfallback → override; writable dir / real per-user temp → keep system temp.Relates to the Mac mini agent hardening (WR-18897). Claude Code itself is already covered live via
env.TMPDIRin~/.claude/settings.json; this extends the fix to the whole shell-launched agent context.🤖 Generated with Claude Code
Summary by Sourcery
Enhancements: