fix(worktree-guard): always allow writes to system temp dirs#661
Merged
Conversation
The write-guard asked for permission on ANY write resolving outside the task's worktree — including /tmp. Agents routinely stage scratch files there (e.g. `git show …:PLAN_REVIEW_A.md > /tmp/review_a.md`), so a pipeline step would stall on a permission prompt for a harmless temp write, and in bypassPermissions mode the guard denied it outright, trapping the agent. Temp dirs are shared, ephemeral scratch space: a write there can't corrupt the main checkout or a sibling worktree, which is the only boundary this guard protects. Exempt /tmp, /private/tmp, /var/tmp, and $TMPDIR (os.TempDir) — resolved through symlinks so macOS /tmp == /private/tmp — the same way /dev/null is already exempt. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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 & why
The worktree write-guard prompted for permission on any write resolving outside a task's worktree — including
/tmp. Agents routinely stage scratch files there, so a pipeline step stalled on a permission prompt for a harmless temp write:Worse, in
bypassPermissionsmode the guard denies out-of-worktree writes (no human to ask), so an autonomous step would be trapped retrying a/tmpwrite it can never make.Fix
Exempt the system temp dirs —
/tmp,/private/tmp,/var/tmp, and$TMPDIR(os.TempDir()) — from the guard, resolved through symlinks so macOS/tmp==/private/tmp. Same mechanism as the existing/dev/nullexemption.This doesn't weaken the guard's actual threat model: temp dirs are shared, ephemeral scratch space, and a write there can't corrupt the main checkout or a sibling worktree — the only boundary this guard exists to protect. Reads were, and remain, always allowed.
Tests
TestWorktreeWriteGuardAllowsTempDirs— structuredWriteto/tmpand toos.TempDir(), and a Bash redirect to/tmpin bypass mode, are all allowed.TestWorktreeWriteGuardBash—/tmp,/private/tmp,/var/tmpredirects now allowed; main-checkout /$HOME/ sibling-worktree writes still ask.Full suite green (18 packages), clean build.
🤖 Generated with Claude Code