@brandongtr/rule-agent-cli
v1.0.1-beta.0
Published
A CLI tool to review git diffs against cursor rules using Claude Code
Downloads
11
Maintainers
Readme
Rule Agent CLI
A TypeScript CLI tool that reviews git diffs against cursor rules using Claude Code SDK.
Features
- 🔍 Review git commits or unstaged changes against cursor rules
- 📋 Auto-detects cursor rules from
.cursorrulesor.cursor/rules/*.mdc - 🤖 Uses Claude Code SDK for intelligent rule analysis
- 📊 Provides violations, suggestions, and summaries for each file
Installation
From npm (Recommended)
# Install globally
npm install -g @brandongtr/rule-agent-cli
# Or use with npx (no installation required)
npx @brandongtr/rule-agent-cli rule-review --helpFrom Source
- Clone and install dependencies:
git clone https://github.com/brandongtr/rule-agent-cli.git
cd rule-agent-cli
npm install- Set up environment variables:
cp .env.example .env
# Edit .env and add your ANTHROPIC_API_KEY- Build the project:
npm run buildUsage
Basic Commands
# Review latest commit against auto-detected rules
rule-review rule-review
# Review specific file in latest commit
rule-review rule-review --file src/index.ts
# Review unstaged changes
rule-review rule-review --commit unstaged
# Use custom rules file
rule-review rule-review --rules .cursor/rules/typescript.mdc
# Combine options: review specific file in unstaged changes
rule-review rule-review -f src/utils/git.ts -c unstaged
# Review specific commit by hash
rule-review rule-review -c abc1234
# Review with custom rules and specific file
rule-review rule-review -r my-rules.md -f src/index.tsUsing with npx
# No installation required - run directly
npx @brandongtr/rule-agent-cli rule-review
# Review unstaged changes
npx @brandongtr/rule-agent-cli rule-review -c unstaged
# Review specific file
npx @brandongtr/rule-agent-cli rule-review -f src/index.tsCommand Line Options
| Flag | Long Form | Argument | Description |
|------|-----------|----------|-------------|
| -f | --file | <file> | Specific file to review (filters diff to single file) |
| -c | --commit | <commit> | Git commit/reference to review (default: HEAD) |
| -r | --rules | <rules> | Custom path to cursor rules file |
| -h | --help | - | Display help information |
| -V | --version | - | Display version number |
Special Commit Values
HEAD(default) - Review the latest commitunstaged- Review uncommitted changes in working directory<commit-hash>- Review specific commit by hash<branch-name>- Review latest commit on specified branch
Cursor Rules Detection
The tool automatically detects cursor rules from:
.cursorrules(traditional format).cursor/rules/*.mdc(new Cursor IDE format)- Custom path via
-roption
Environment Variables
Required:
ANTHROPIC_API_KEY- Your Anthropic API key
Optional:
CLAUDE_MODEL- Claude model to use (default: claude-3-5-sonnet-20241022)ANTHROPIC_BASE_URL- API base URL (default: https://api.anthropic.com)
Development
# Run in development mode
npm run dev
# Build TypeScript
npm run build
# Run built version
npm startExample Output
🔍 Starting rule review...
📋 Loaded rules from: .cursor/rules/general.mdc
📄 Analyzing unstaged changes for src/index.ts
📊 Found 1 file(s) with changes
🔎 Analyzing: src/index.ts
📋 Results for src/index.ts:
❌ Rule Violations:
1. Use of console.log in src/index.ts:8 violates the 'No console log' rule
💡 Suggestions:
1. Remove console.log statement or replace with proper logging mechanism
2. Use const/let instead of var for variable declaration
3. Consider removing badFunction if not used
📝 Summary: The code changes introduce a function with a console.log statement that violates cursor rules. The function also uses outdated var declaration.
✨ Rule review completed!Help Output
$ rule-review rule-review --help
Usage: rule-review rule-review [options]
Review git diffs against cursor rules
Options:
-f, --file <file> Specific file to review
-c, --commit <commit> Specific commit to review (default: HEAD)
-r, --rules <rules> Path to cursor rules file (default: .cursorrules)
-h, --help display help for command