#22425: chore: make prepare git hooks setup cross-platform
scripts
size: XS
Cluster:
Build and Fix Enhancements
## Summary
- Problem: The existing prepare script uses POSIX shell syntax which produces confusing output on Windows during pnpm install.
- Why it matters: Windows contributors see misleading "The system cannot find the path specified." messages even though installation succeeds.
- What changed: Replaced the shell-based prepare command with a small Node script (scripts/setup-git-hooks.mjs) that performs the same checks in a cross-platform way.
- What did NOT change (scope boundary): Behavior and scope remain identical — core.hooksPath is only set when git is available, inside a work tree, and git-hooks/ exists. The install process remains non-fatal.
## Change Type (select all)
- [ ] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Docs
- [ ] Security hardening
- [x] Chore/infra
## Scope (select all touched areas)
- [ ] Gateway / orchestration
- [ ] Skills / tool execution
- [ ] Auth / tokens
- [ ] Memory / storage
- [ ] Integrations
- [ ] API / contracts
- [ ] UI / DX
- [x] CI/CD / infra
## Linked Issue/PR
- Closes #
- Related #
None — improvement discovered during Windows setup.
## User-visible / Behavior Changes
None.
## Security Impact (required)
- New permissions/capabilities? (No)
- Secrets/tokens handling changed? (No)
- New/changed network calls? (No)
- Command/tool execution surface changed? (No)
- Data access scope changed? (No)
- If any `Yes`, explain risk + mitigation:
None.
## Repro + Verification
### Environment
- OS: Windows 11
- Runtime/container: Node v24.13.0, pnpm v10.23.0
- Model/provider: N/A
- Integration/channel (if any): N/A
- Relevant config (redacted): Default repo configuration
### Steps
1. Run pnpm install on Windows before this change.
2. Observe misleading shell-related error message.
3. Apply this PR and run pnpm install again.
### Expected
Clean install output with no POSIX shell error messages.
### Actual
Install succeeds without confusing Windows-specific shell error output.
## Evidence
- [x] Failing test/log before + passing after
## Human Verification (required)
- Verified scenarios: Fresh install on Windows inside a git work tree.
- Edge cases checked: Non-git directory; git not available; git-hooks directory missing.
- What you did **not** verify: macOS/Linux environments (behavior unchanged by design).
## Compatibility / Migration
- Backward compatible? (Yes)
- Config/env changes? (No)
- Migration needed? (No)
- If yes, exact upgrade steps:
None.
## Failure Recovery (if this breaks)
- How to disable/revert this change quickly: Revert this PR commit.
- Files/config to restore: Restore previous prepare script in package.json.
- Known bad symptoms reviewers should watch for: git hooks not being configured automatically.
## Risks and Mitigations
None.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Replaced POSIX shell-based git hooks setup with a cross-platform Node.js script (`scripts/setup-git-hooks.mjs`) to eliminate confusing error messages on Windows during `pnpm install`.
The changes successfully achieve the stated goal of cross-platform compatibility. The new script properly checks for git availability, work tree status, and sets `core.hooksPath` with appropriate error handling.
**Key observations:**
- The new script adds a check for `git-hooks/` directory existence (lines 27-30) that the original shell command did not have
- This is actually an improvement (avoids setting hooks path to non-existent directory in npm package installations), but represents a minor behavior change beyond just "cross-platform translation"
- The PR description states "Behavior and scope remain identical" but this added check is technically a scope enhancement, albeit a sensible one
- All error paths correctly exit with code 0 to maintain non-fatal install behavior
- The implementation is clean, well-structured, and follows Node.js best practices
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are well-contained to the prepare script, properly handle all edge cases, maintain backward compatibility, and improve cross-platform support. The added directory existence check is a minor enhancement that makes the behavior cleaner without breaking existing functionality.
- No files require special attention
<sub>Last reviewed commit: baa711b</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#11951: Prepending Windows Node to PATH didn’t help
by tranhoangtu-it · 2026-02-08
79.7%
#18493: making pnpm build:ui and pnpm build to work on windows
by darkpowerxo · 2026-02-16
79.2%
#11432: fix(security): add --ignore-scripts to npm install in hook and plug...
by coygeek · 2026-02-07
78.9%
#9250: Fix: Add shell:true for Windows .cmd files to prevent spawn EINVAL ...
by vishaltandale00 · 2026-02-05
78.4%
#3006: fix(scripts): use local pnpm binary in run-node.mjs if global is mi...
by elliotsecops · 2026-01-27
77.6%
#17347: fix(pre-commit): fail fast when lint/format tooling is unavailable
by ephelia-ai · 2026-02-15
76.8%
#9914: fix(hooks): resolve bundled hook dist paths and packaging checks
by zimmra · 2026-02-05
76.5%
#11817: fix(build): compile bundled hook handlers into dist
by AnonO6 · 2026-02-08
76.4%
#12804: fix(daemon): use wrapper script for pnpm global installs in service...
by odinho · 2026-02-09
76.3%
#19931: Config: merge PATH env vars and bootstrap Windows bins
by Kemalau · 2026-02-18
76.2%