Skip to content

fix(agent-guard): make the fresh-clone hook guard cross-platform (Windows)#823

Open
milamberspace wants to merge 1 commit into
apache:mainfrom
milamberspace:fix/agent-guard-hook-cross-platform
Open

fix(agent-guard): make the fresh-clone hook guard cross-platform (Windows)#823
milamberspace wants to merge 1 commit into
apache:mainfrom
milamberspace:fix/agent-guard-hook-cross-platform

Conversation

@milamberspace

Copy link
Copy Markdown
Contributor

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-setup has synced agent-guard.py in. 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 -c existence check that is cross-platform and needs no shell conditional:

python3 -c "import os,sys,subprocess; p=os.path.join(os.environ.get('CLAUDE_PROJECT_DIR',''),'.claude','hooks','agent-guard.py'); sys.exit(subprocess.call([sys.executable,p]) if os.path.isfile(p) else 0)"
  • no-ops (exit 0) when the script is absent (fresh clone);
  • runs the guard and propagates its exit code (so a deny still blocks) when present;
  • reads CLAUDE_PROJECT_DIR from the environment in Python, so it doesn't depend on $VAR vs %VAR% shell expansion.

Updated in the two places that ship the snippet: skills/setup/adopt.md and tools/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

  • Bug fix (docs / committed template)

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.

…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
@milamberspace

Copy link
Copy Markdown
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 .claude/settings.local.json at setup (alongside the script) rather than committing it to .claude/settings.json. If that lands, the wiring only ever exists once the script is present, so no fresh-clone guard is needed at all — and the command reduces to a plain python3 ".../agent-guard.py", which is already cross-platform. In other words #824 would make both the #786 guard and this python3 -c rewrite unnecessary.

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.

@potiuk

potiuk commented Jul 11, 2026

Copy link
Copy Markdown
Member

Oh... Windows support :)

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.

2 participants