This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a zsh plugin called review_pr that automates GitHub Pull Request reviews using Claude AI. The plugin creates an intelligent workflow for fetching, caching, and reviewing PRs with detailed analysis.
review_pr()- Primary function that orchestrates the entire PR review processreview_pr_last()- Utility to view the most recent review for a specific PR
URL Parsing & Validation (lines 6-20):
- Validates GitHub PR URL format:
https://github.com/owner/repo/pull/number - Extracts owner, repo, and PR number using bash parameter expansion
Repository Caching System (lines 23-41):
- Smart caching at
$HOME/.cache/review_pr/repos/owner/repo - Automatic daily updates using cross-platform stat commands
- Fallback clone if cache doesn't exist
Git Worktree Management (lines 54-58):
- Creates isolated worktrees for each PR:
_pr-{number}-{sha} - Uses detached HEAD checkout for clean isolation
- Automatic cleanup unless
DEBUG_REVIEW_PRis set
Claude Integration (lines 68-75):
- Calls Claude CLI with structured prompt for PR analysis
- Uses
--add-dir .to include full codebase context - Saves reviews with timestamped filenames
Output Management (lines 83-87):
- Prefers
batfor syntax highlighting, falls back toless - Always uses
--paging=alwaysand--style=plainfor bat
# Test plugin loading
zsh -c "source ~/.oh-my-zsh/custom/plugins/review_pr/review_pr.plugin.zsh && review_pr"export DEBUG_REVIEW_PR=1
review_pr https://github.com/owner/repo/pull/123
# Worktree preserved at: ~/.cache/review_pr/repos/owner/repo/_pr-123-sha# Update gist with changes
gh gist edit 545ab6f8677b519eaa1c9fd163456e40 -f ~/.oh-my-zsh/custom/plugins/review_pr/review_pr.plugin.zsh
# View gist history
gh gist view 545ab6f8677b519eaa1c9fd163456e40 --web~/.cache/review_pr/
├── repos/owner/repo/ # Git repository cache
│ └── _pr-123-abc123/ # Temporary worktrees (debug mode only)
└── reviews/owner/repo/123/ # Review output files
└── 123-abc123-20240101-120000.md
Required:
gh(GitHub CLI) - PR metadata and authenticationclaude(Claude CLI) - AI review generation- Git with worktree support
Optional:
bat- Enhanced output formatting
DEBUG_REVIEW_PR- Preserves worktrees for debuggingREVIEW_CACHE- Custom cache location (default:$HOME/.cache/review_pr)
The plugin uses consistent error handling:
- Early validation with descriptive error messages
|| { echo "❌ Error"; return 1; }pattern for critical failures- Cross-platform compatibility (macOS/Linux stat commands)
The Claude review prompt (lines 69-74) requests:
- PR title and description
- File-by-file code analysis
- Existing reviewer comments
- Risk assessment and open questions
- Explicit acknowledgment of missing context
Authentication Issues:
gh auth status
gh auth refreshCache Management:
# Clear repository cache
rm -rf ~/.cache/review_pr/repos
# Clear old worktrees
find ~/.cache/review_pr -type d -name "_pr-*" -exec rm -rf {} +Empty Reviews:
- Check Claude CLI authentication
- Verify repository accessibility
- Check for API rate limiting