diff --git a/.claude/settings.json b/.claude/settings.json index caf79c0ab..6804c4d46 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -1,5 +1,8 @@ { "$schema": "https://json.schemastore.org/claude-code-settings.json", + "env": { + "PREK_HOME": "~/.cache/prek-sandbox" + }, "sandbox": { "enabled": true, "excludedCommands": [ @@ -106,6 +109,7 @@ "Edit(~/.claude/plugins/cache/apache-magpie/magpie-vetted-ops/**)", "Edit(~/.claude/magpie/**)", "Edit(~/.config/uv/**)", + "Edit(~/.cache/prek/**)", "Edit(~/.claude/plugins/cache/apache-magpie/magpie-adversarial-review/**)", "Edit(~/.claude/scripts/**)", "Bash(curl *)", diff --git a/docs/setup/sandbox-troubleshooting.md b/docs/setup/sandbox-troubleshooting.md index 5dd1466a7..5d66c7471 100644 --- a/docs/setup/sandbox-troubleshooting.md +++ b/docs/setup/sandbox-troubleshooting.md @@ -1131,6 +1131,10 @@ uv tool install prek Do not add `~/.local/share/uv` back to `allowWrite`: `sandbox-lint` rejects it. +The same switch moved sandboxed prek to its own home, `~/.cache/prek-sandbox` +(`env.PREK_HOME`), so the first sandboxed `prek run` after it rebuilds its hook +environments once; that is expected, not a failure. + --- ## Git hooks silently skipped for commits made inside the sandbox diff --git a/docs/setup/secure-agent-setup.md b/docs/setup/secure-agent-setup.md index cfb6ba690..d9536b16a 100644 --- a/docs/setup/secure-agent-setup.md +++ b/docs/setup/secure-agent-setup.md @@ -1050,6 +1050,10 @@ uv tool upgrade --all --reinstall The old `~/.cache/uv/` stays as the sandbox's cache; the host never reads it again. +**prek has the same problem.** The git hooks of a commit you make in a terminal run prek outside the sandbox, from hook environments under its home: `~/.cache/prek/` by default, which the `~/.cache/` grant makes sandbox-writable. Nothing excluded from the sandbox runs prek, so the settings `env` (which only Claude Code's own commands see, never your terminal) does the split: `"PREK_HOME": "~/.cache/prek-sandbox"` gives sandboxed prek a home of its own, and `Edit(~/.cache/prek/**)` keeps sandboxed commands out of the terminal's. prek expands the `~`. The first sandboxed `prek run` after the switch rebuilds its hook environments there once. `sandbox-lint` fails a settings file whose `PREK_HOME` is missing or overlaps `~/.cache/prek`. + +The `env` also reaches a command Claude Code runs *outside* the sandbox (an approved bypass, often a signed commit). The whole-user [git-hook dispatcher](#whole-user-with-the-per-repo-dispatcher) covers that: a hook it runs with no `SANDBOX_RUNTIME` in the environment gets `PREK_HOME=~/.local/share/prek-host` and a host-only `XDG_CACHE_HOME` (for the pip, go, npm and uv caches the hooks use), whatever the env said. It only runs when git reaches it: a repository-level `core.hooksPath` (some `prek install` runs set one) overrides the global one and skips the dispatcher. magpie-setup's session-start hook removes one that points at the repository's own `.git/hooks` (redundant, since the dispatcher chains there anyway) and says so; any other value is reported, and `setup-isolated-setup-verify` flags it. With per-project scope there is no dispatcher, so do not bypass the sandbox for a commit there. + Projects set up before the switch may still carry the old write grant. `sandbox-add-project-root.sh` removes it whenever it runs (on checkout, adopt and upgrade), and magpie-setup's session-start hook removes it from the checkout's `.claude/settings.local.json` the next time a session opens there, and says so. A linked worktree's main checkout is cleaned when a session opens in it: the worktree's `.git` file is sandbox-writable, so the hook never follows it. A broader grant, or one in user-scope or committed settings, is reported for you to remove; those files are yours. `sandbox-lint` fails a settings file that makes `~/.local/share/uv` writable or lacks the two `~/.config/uv` deny rules; `setup-isolated-setup-verify` checks the config file itself. diff --git a/plugins/magpie-setup/skills/isolated-setup-install/SKILL.md b/plugins/magpie-setup/skills/isolated-setup-install/SKILL.md index b0fce0eda..c1b8da99a 100644 --- a/plugins/magpie-setup/skills/isolated-setup-install/SKILL.md +++ b/plugins/magpie-setup/skills/isolated-setup-install/SKILL.md @@ -17,7 +17,7 @@ when_to_use: >- capability: capability:platform surface_hash: sha256:6358702510d21c26 license: Apache-2.0 -measured_tokens: 7894 +measured_tokens: 8036 ---