Fix code review hook failing when cwd is not git root#2
Open
malston wants to merge 2 commits intoNTCoding:mainfrom
Open
Fix code review hook failing when cwd is not git root#2malston wants to merge 2 commits intoNTCoding:mainfrom
malston wants to merge 2 commits intoNTCoding:mainfrom
Conversation
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.
Keep only the version bump, restore original inline keyword arrays.
There was a problem hiding this comment.
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-toplevelwith 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.claude/settings.json) which broke when Claude Code's working directory wasn't the repository root (e.g. in worktrees or subdirectories)PROJECT_ROOTviagit rev-parse --show-topleveland use absolute paths for all.claude/referencesError that was occurring
This fired on every PostToolUse and Stop hook invocation when the cwd wasn't the git root.
Test plan