Skip to content

fix(worktree-guard): always allow writes to system temp dirs#661

Merged
bborn merged 1 commit into
mainfrom
fix/worktree-guard-allow-tmp
Jul 17, 2026
Merged

fix(worktree-guard): always allow writes to system temp dirs#661
bborn merged 1 commit into
mainfrom
fix/worktree-guard-allow-tmp

Conversation

@bborn

@bborn bborn commented Jul 17, 2026

Copy link
Copy Markdown
Owner

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:

git show …:PLAN_REVIEW_A.md > /tmp/review_a.md → "would write outside your isolated worktree… the user must approve it."

Worse, in bypassPermissions mode the guard denies out-of-worktree writes (no human to ask), so an autonomous step would be trapped retrying a /tmp write 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/null exemption.

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 — structured Write to /tmp and to os.TempDir(), and a Bash redirect to /tmp in bypass mode, are all allowed.
  • Updated TestWorktreeWriteGuardBash/tmp, /private/tmp, /var/tmp redirects now allowed; main-checkout / $HOME / sibling-worktree writes still ask.

Full suite green (18 packages), clean build.

🤖 Generated with Claude Code

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>
@bborn
bborn merged commit 146f2b3 into main Jul 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant