Skip to content

fix(skills): add PATH guard and remove absolute paths from hooks#565

Open
itxaiohanglover wants to merge 1 commit into
tirth8205:mainfrom
itxaiohanglover:fix/issue-549-558-hooks-path
Open

fix(skills): add PATH guard and remove absolute paths from hooks#565
itxaiohanglover wants to merge 1 commit into
tirth8205:mainfrom
itxaiohanglover:fix/issue-549-558-hooks-path

Conversation

@itxaiohanglover

Copy link
Copy Markdown

Summary

Fixes two related bugs in generate_hooks_config():

Changes

PATH guard (#549)

# Before
"command": "cat >/dev/null || true; git rev-parse --git-dir >/dev/null 2>&1 && code-review-graph update ..."

# After
"command": "cat >/dev/null || true; command -v code-review-graph >/dev/null 2>&1 || exit 0; git rev-parse --git-dir >/dev/null 2>&1 && code-review-graph update ..."

This mirrors the pattern already used by the git pre-commit hook installed by the same install command.

Narrowed matcher (#549)

# Before
"matcher": "Edit|Write|Bash"

# After
"matcher": "Edit|Write"

Edit|Write covers the cases where the graph can actually become stale from within Claude Code. Bash-driven file mutations are rare and the cost of firing on every shell command is high.

Dynamic repo root (#558)

# Before
--repo "/home/username/work/some/path/to/depot"

# After
--repo "$(git rev-parse --show-toplevel 2>/dev/null)"

The repo_root parameter is retained for backward compatibility but no longer embedded in commands.

Test plan

  • test_hooks_have_path_guard — verifies both hooks include command -v code-review-graph
  • test_hooks_use_dynamic_repo_root — verifies both hooks use git rev-parse --show-toplevel
  • test_hooks_no_absolute_path_embedded — verifies no hardcoded path appears in commands
  • test_post_tool_use_matcher_excludes_bash — verifies matcher is Edit|Write, not Edit|Write|Bash
  • All 144 existing skills tests still pass
  • ruff check passes (no new lint errors introduced)

Closes #549, #558

Two related bugs in generate_hooks_config():

1. tirth8205#549: Hooks called bare `code-review-graph` without checking if the
   binary is on PATH. When installed in a project venv, every Edit/Write/Bash
   tool call surfaced "code-review-graph: not found". Also, the `Bash`
   matcher fired on every shell command, not just file mutations.

   Fix: add `command -v code-review-graph >/dev/null 2>&1 || exit 0`
   guard. Narrow matcher from `Edit|Write|Bash` to `Edit|Write`.

2. tirth8205#558: Hooks embedded `json.dumps(repo_root.resolve().as_posix())` —
   an absolute path — making settings.json non-shareable across
   collaborators with different checkout paths.

   Fix: use `$(git rev-parse --show-toplevel 2>/dev/null)` to resolve
   the repo root dynamically at runtime.

Also fixes the `json.dumps()` shell-quoting abuse from tirth8205#497 for the
hooks path (though tirth8205#497 also covers the .mcp.json cwd field separately).

Closes tirth8205#549, tirth8205#558
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.

Generated Claude Code hooks fail noisily when the binary is not on PATH, and fire on every Bash command

1 participant