Add sandbox-git-write guard hook#10
Open
technicalpickles wants to merge 1 commit into
Open
Conversation
A PreToolUse/Bash hook (bin/claude-sandbox-guard) that denies sandboxed git-write and srb commands up front, telling Claude to retry with dangerouslyDisableSandbox=true instead of eating a cryptic EPERM and retrying. Both classes reliably fail under the command sandbox and are safe to run unsandboxed: - git writes hit .git/worktrees/.../index.lock and the hardcoded blocked paths (.claude/, .vscode/, .gitmodules) inside pt worktrees - sorbet (srb) wants to write its mdb / rubocop cache Read-only git (log/show/diff/status, worktree/stash/submodule list) is left sandboxed, so the common path is untouched. claudeconfig.sh now concatenates hooks.<event> arrays across base + active role. The previous deep merge replaced same-event arrays, which would silently drop a base-level PreToolUse hook whenever the active role also defined PreToolUse (work.jsonc does). Behaviour is locked down by a bats suite (test/): hand-written edge cases (env prefixes, git -C, compound chains, read-form list commands, already-unsandboxed calls) plus a data-driven sweep over 90 real commands pulled from the session corpus. 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.
Summary
bin/claude-sandbox-guard, a PreToolUse/Bash hook that denies sandboxed git-write andsrbcommands and tells Claude to retry withdangerouslyDisableSandbox=true. Both reliably fail under the sandbox (git writes hit.git/worktrees/.../index.lockand the blocked.claude/.vscode/.gitmodulespaths in pt worktrees; sorbet wants its mdb/rubocop cache) and are safe to run unsandboxed. Read-only git stays sandboxed, so the common path is untouched.claudeconfig.shto concatenatehooks.<event>arrays across base + active role instead of deep-merging them. The old merge replaced same-event arrays, so a base-levelPreToolUsehook got silently dropped whenever the active role also definedPreToolUse(work.jsonc does).srbas the clear "always retry unsandboxed" patterns./tmpwrites were deliberately left out, since the fix there is$TMPDIR, not loosening the sandbox.Test plan
npm test(lint + bats). The bats suite covers hand-written edge cases (env prefixes,git -C, compound chains, read-formlistcommands, already-unsandboxed calls, non-Bash tools) plus a sweep over 90 real commands pulled from the corpus.Activating it
Dormant until
claudeconfig.shregenerates~/.claude/settings.json. Heads up first: the live settings hasbowerbird/rtk/plannotatorhooks that aren't tracked in any role, so a regen drops them. Pre-existing drift, worth sorting out separately.