Skip to content

Fix code review hook failing when cwd is not git root#2

Open
malston wants to merge 2 commits intoNTCoding:mainfrom
malston:fix/code-review-hook-relative-paths
Open

Fix code review hook failing when cwd is not git root#2
malston wants to merge 2 commits intoNTCoding:mainfrom
malston:fix/code-review-hook-relative-paths

Conversation

@malston
Copy link

@malston malston commented Feb 26, 2026

Summary

  • The hook script used relative paths (.claude/settings.json) which broke when Claude Code's working directory wasn't the repository root (e.g. in worktrees or subdirectories)
  • Resolve PROJECT_ROOT via git rev-parse --show-toplevel and use absolute paths for all .claude/ references
  • Bumped plugin version to 1.0.4

Error that was occurring

jq: error: Could not open file .claude/settings.json: No such file or directory

This fired on every PostToolUse and Stop hook invocation when the cwd wasn't the git root.

Test plan

  • Verified hook exits gracefully when run outside a git repo
  • Verified hook runs cleanly from git root directory
  • Tested in a real project (diego-capacity-analyzer) that was previously hitting this error -- hook fires successfully with no jq errors

The hook script used relative paths (.claude/settings.json) which broke
when Claude Code's working directory wasn't the repository root (e.g.
in worktrees or subdirectories). Resolve PROJECT_ROOT via git rev-parse
and use absolute paths for all .claude/ references.
Copilot AI review requested due to automatic review settings February 26, 2026 03:40
Keep only the version bump, restore original inline keyword arrays.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where the automatic-code-review plugin hook script failed when Claude Code's working directory wasn't the git repository root (e.g., in worktrees or subdirectories). The fix resolves the git root path using git rev-parse --show-toplevel and uses absolute paths for all .claude/ file operations.

Changes:

  • Added PROJECT_ROOT resolution via git rev-parse --show-toplevel with graceful error handling for non-git directories
  • Updated file path variables in get_or_initialize_plugin_settings() to use absolute paths with PROJECT_ROOT
  • Bumped plugin version from 1.0.3 to 1.0.4

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
automatic-code-review/hooks/tools/automatic-code-review-plugin.sh Added PROJECT_ROOT resolution and updated settings_file, rules_file, and mkdir paths to use absolute paths
.claude-plugin/marketplace.json Bumped version to 1.0.4 and reformatted some keyword arrays to multi-line format
Comments suppressed due to low confidence (1)

.claude-plugin/marketplace.json:41

  • The keywords array formatting changes appear to be unrelated to the bug fix described in the PR. Some entries (like "full-codebase-review") have been reformatted to multi-line, while others (like "automatic-code-review" at line 27 and "task-check" at line 19) remain inline. This creates inconsistency in the formatting. Consider either reverting these formatting changes or applying them consistently to all keyword arrays in the file.
      "keywords": ["code-review", "tech-debt", "codebase-analysis", "periodic-review", "quality"]
    },
    {
      "name": "track-and-improve",
      "source": "./track-and-improve",
      "description": "Capture mistakes and improvement opportunities with automatic 5 whys analysis",
      "version": "1.0.0",

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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