Rewrite of #2217. Required team mode wrote a bash check-gstack.sh and
registered it as "$CLAUDE_PROJECT_DIR/.claude/hooks/check-gstack.sh", which
only works when the hook runner is a POSIX shell. Under cmd.exe or PowerShell
(Windows, Copilot CLI) the variable is not expanded and the .sh cannot run, so
an intended allow or deny became a hook error.
- The hook is now .claude/hooks/check-gstack.cjs: the same root search
(GSTACK_ROOT, every host's global root, the migrated repo), with the home
directory from HOME, then USERPROFILE, then os.homedir(). It prints {} when
gstack resolves and the PreToolUse deny JSON with exit 2 when not.
- The registered command is `node -e "require(require('path').resolve(
process.env.CLAUDE_PROJECT_DIR || '.', '.claude', 'hooks',
'check-gstack.cjs'))"`: no `$` or `%`, so sh, cmd.exe and PowerShell all
pass it through unchanged.
- An existing check-gstack registration (matcher Skill or Skill|skill) is
replaced in place; duplicates are dropped and unrelated hooks in the same
entry kept. The legacy .sh is deleted only after the settings write
succeeds (a tracked one joins the suggested git add), and is kept when bun
is missing or the write fails, which now reports instead of claiming success.
Tests: team-mode and the hook-schema test run the command as registered;
test/team-init-hook-shell-neutral.test.ts runs it through the platform's
default shell (cmd.exe on the Windows lane, which curates it in) and through
PowerShell when installed (verified here in the pwsh 7 container). The
routing-probe check for the bash `_GSTACK_ROOT` gate now pins the same
contract in the .cjs: every host root probed, block only when none resolves.
Co-authored-by: neallee2012 <1499497+neallee2012@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>