Repository navigation
fix(agent-guard): make the fresh-clone hook guard cross-platform (Windows) - #823
Merged
potiuk merged 1 commit intoJul 12, 2026
Merged
Conversation
…dows) Follow-up to apache#786: the POSIX `[ -f … ] && … || true` guard only works in a POSIX shell, so on Windows (PowerShell, no Git Bash) the committed hook breaks. Replace it with an inline `python3 -c` existence check that no-ops when agent-guard.py is absent and runs + propagates its exit code otherwise — cross-platform, no shell conditional, and reads CLAUDE_PROJECT_DIR from the environment in Python (no $VAR vs %VAR% expansion). Reported by an adopter (Apache JMeter) reviewing the same change downstream. Generated-by: Claude Opus 4.8
Contributor
Author
|
Heads-up for maintainers: this cross-platform fix may be superseded by #824. That issue proposes writing the agent-guard hook into the gitignored, per-machine Happy to close this in favour of #824, or keep it as the interim fix if you would rather ship the smaller change first — your call. |
Member
|
Oh... Windows support :) |
potiuk
approved these changes
Jul 12, 2026
3 of 21 tasks
AmirF194
added a commit
to AmirF194/magpie
that referenced
this pull request
Aug 26, 2026
…ettings.json The adopt flow committed the agent-guard PreToolUse wiring into the tracked .claude/settings.json while the script it invokes (.claude/hooks/agent-guard.py) stayed gitignored, synced in only by /magpie-setup. That split forced two prior workarounds for the same root cause: apache#786 guarded the command against a fresh clone that has the wiring but not yet the script, and apache#823 rewrote that guard for Windows, where the POSIX conditional does not run. Move the wiring itself into the gitignored, per-machine settings.local.json, written by Step 12 pass 1 at the same moment the script is deposited. Once wiring and script exist together on the same schedule, the fresh-clone race is gone and the command collapses to a plain `python3 "..."` call that runs the same on POSIX and Windows, so both the apache#786 guard and the apache#823 rewrite become unnecessary. This supersedes apache#823 and retro-justifies removing the apache#786 guard. Updates the merge/read/clean side for the same wiring across adopt.md (Step 12 pass 1, Step 2), worktree-init.md (Step 1d), unadopt.md, and verify.md, plus tools/agent-guard/README.md's documented snippet. The idempotent-merge Python (skip if already wired, preserve every other settings.local.json key and hooks.PreToolUse matcher, leave a hand-edited/corrupt file alone) is unchanged from the existing Step 12 pass 3 pattern for the sandbox-allowlist entry. Fixes apache#824 Generated-by: Claude Code (Sonnet 5)
potiuk
pushed a commit
that referenced
this pull request
Aug 27, 2026
…ettings.json (#1115) * fix(setup): wire the agent-guard hook into settings.local.json, not settings.json The adopt flow committed the agent-guard PreToolUse wiring into the tracked .claude/settings.json while the script it invokes (.claude/hooks/agent-guard.py) stayed gitignored, synced in only by /magpie-setup. That split forced two prior workarounds for the same root cause: #786 guarded the command against a fresh clone that has the wiring but not yet the script, and #823 rewrote that guard for Windows, where the POSIX conditional does not run. Move the wiring itself into the gitignored, per-machine settings.local.json, written by Step 12 pass 1 at the same moment the script is deposited. Once wiring and script exist together on the same schedule, the fresh-clone race is gone and the command collapses to a plain `python3 "..."` call that runs the same on POSIX and Windows, so both the #786 guard and the #823 rewrite become unnecessary. This supersedes #823 and retro-justifies removing the #786 guard. Updates the merge/read/clean side for the same wiring across adopt.md (Step 12 pass 1, Step 2), worktree-init.md (Step 1d), unadopt.md, and verify.md, plus tools/agent-guard/README.md's documented snippet. The idempotent-merge Python (skip if already wired, preserve every other settings.local.json key and hooks.PreToolUse matcher, leave a hand-edited/corrupt file alone) is unchanged from the existing Step 12 pass 3 pattern for the sandbox-allowlist entry. Fixes #824 Generated-by: Claude Code (Sonnet 5) * fix(setup): point the last worktree-init.md adopt.md reference at install.md The #913 rebase repointed two of the three adopt.md links in this file but missed the one inside the settings.local.json wiring bullet this PR adds, which is what the CI link validator (prek, validate skills and tool contracts) has been failing on.
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
Follow-up to #786 (merged): that PR guarded the committed agent-guard hook command with a POSIX shell conditional —
[ -f … ] && python3 … || true— so the hook no-ops on a fresh clone before/magpie-setuphas syncedagent-guard.pyin. But that form only works in a POSIX shell; on Windows (PowerShell, no Git Bash) the committed hook breaks.Replace it with an inline
python3 -cexistence check that is cross-platform and needs no shell conditional:CLAUDE_PROJECT_DIRfrom the environment in Python, so it doesn't depend on$VARvs%VAR%shell expansion.Updated in the two places that ship the snippet:
skills/setup/adopt.mdandtools/agent-guard/README.md.Found by an adopter (Apache JMeter) reviewing the same change downstream — the reviewer asked "Does this work with windows?" on the adoption PR.
Type of change
Test plan
Doc / template change. The guarded command is valid on both POSIX and Windows (pure
python3 -c, no shell conditional); it no-ops when the script is missing and runs + propagates the guard's exit code when present.