UNPKG

commit-guardian

Version:

Interactive CLI tool with browser-based GitHub-style diff viewer for reviewing and approving git changes before commit. Features React-based UI, approval workflow, line comments, and safe commit protection.

220 lines (162 loc) • 6.51 kB
# Commit Guardian šŸ›”ļø **The Perfect Claude Code Companion for Safe Commits** Interactive CLI tool designed specifically for **Claude Code** users who want to review changes before committing. Never accidentally commit code again - approve every change through a beautiful browser interface. ## šŸŽÆ Why Commit Guardian? **Built for Claude Code users** who want to maintain control over their commits while leveraging AI assistance. This tool creates the perfect workflow: 1. **Claude Code makes changes** to your codebase 2. **You stay in control** of what gets committed 3. **Review everything** in a GitHub-style diff viewer 4. **Approve or reject** with confidence ## šŸš€ Perfect Claude Code Integration ### Step 1: Configure Claude Code Settings Add to your `~/.claude/settings.local.json`: ```json { "tools": { "deny": [ "Bash(git commit:*)" ], "allow": [ "Bash(npx commit-guardian *)" ] } } ``` This prevents Claude Code from making direct commits while allowing it to use Commit Guardian. ### Step 2: Usage with Claude Code Simply tell Claude Code: ``` "Please run npx commit-guardian with an appropriate commit message" ``` Or add this to your `CLAUDE.md` for automatic usage: ```markdown When committing changes, always use: npx commit-guardian -m "descriptive commit message" ``` ### Step 3: The Magic Happens 1. **Claude Code runs** `npx commit-guardian -m "your message"` 2. **Browser opens automatically** with your diff 3. **You review** the changes in GitHub-style interface 4. **Approve**: Browser closes, control returns to Claude Code, commit is made 5. **Reject**: Browser closes, control returns to Claude Code, no commit made ## ✨ Features - šŸ” **GitHub-style diff viewer** in browser - šŸ’¬ **Line-by-line comments** on changes - āœ… **Approval workflow** - approve to commit or reject to cancel - šŸš€ **Auto-commit** after approval with custom commit message - šŸ“‹ **Staged & unstaged changes** support - šŸ›”ļø **Pre-commit safety** - prevents accidental commits - šŸŽÆ **File status indicators** - see what's added, modified, or deleted - šŸ“± **Responsive interface** - works on all screen sizes - šŸ¤– **Claude Code optimized** - seamless integration workflow ## šŸ“¦ Installation ### Option 1: Global Installation (Recommended) ```bash npm install -g commit-guardian ``` ### Option 2: Use with npx (No installation needed) ```bash npx commit-guardian -m "Your commit message" ``` ## šŸš€ Usage Examples ### Basic Usage ```bash commit-guardian -m "Add new feature" commit-guardian -m "Fix login bug" commit-guardian --message "Update documentation" ``` ### With Claude Code ```bash # Claude Code will run this for you: npx commit-guardian -m "Implement user authentication system" ``` ## šŸ“‹ Typical Workflow ### Manual Usage 1. **Stage your changes** using `git add` 2. **Run commit-guardian** with your commit message 3. **Browser opens** automatically showing your changes 4. **Review diffs** with GitHub-like interface 5. **Add comments** (optional) by clicking the šŸ’¬ button on any line 6. **Click "āœ… Approve & Commit"** to commit or "āŒ Reject" to cancel ### Claude Code Integration Workflow 1. **Ask Claude Code** to make changes to your project 2. **Tell Claude Code** to commit with commit-guardian 3. **Review changes** when browser opens automatically 4. **Approve or reject** - control returns to Claude Code automatically 5. **Continue working** with Claude Code seamlessly ## šŸŽ® Example Session ``` šŸ” Commit Guardian - Review changes before commit šŸ“Š Changes detected: • 3 files modified • 2 files added šŸ“ Commit message: "Implement user authentication system" šŸš€ Review server started at http://localhost:3456 🌐 Opening browser for review... ā³ Waiting for your approval... • Review changes in browser • Add comments if needed • Approve to commit or reject to cancel Press Ctrl+C to cancel ``` After approval: ``` āœ… Changes approved! šŸ“ Commit message: Implement user authentication system šŸ’¬ Comments: 1. src/auth.js:42 - Good error handling implementation 2. src/login.js:15 - Consider adding rate limiting šŸŽ‰ Successfully committed changes! ``` ## āš ļø Requirements - Node.js (v14 or higher) - Git repository - Modern web browser - Claude Code (for optimal experience) ## šŸŽÆ Design Philosophy Commit Guardian was built specifically for **Claude Code users** who want to: - **Maintain control** over what gets committed to their repository - **Review AI-generated changes** before they become permanent - **Prevent accidental commits** through mandatory approval workflow - **Keep development velocity high** while ensuring code quality - **Stay in the flow** with seamless tool integration ## šŸ’” Pro Tips ### For Claude Code Users 1. **Add to CLAUDE.md**: Include commit-guardian usage instructions in your project's CLAUDE.md 2. **Use descriptive messages**: Let Claude Code suggest commit messages based on the changes 3. **Review everything**: Even AI-generated code should be reviewed before committing 4. **Comment on changes**: Use the comment feature to note concerns or improvements ### Configuration Tip ```json // ~/.claude/settings.local.json { "tools": { "deny": ["Bash(git commit:*)"], "allow": ["Bash(npx commit-guardian *)"] } } ``` ## šŸ¤– Claude Code Best Practices When working with Claude Code: ```markdown # In your CLAUDE.md or prompts: When making commits, always use: `npx commit-guardian -m "descriptive message"` Never use `git commit` directly. ``` ## šŸ™ Inspiration This tool was inspired by the excellent [difit](https://github.com/yoshiko-pg/difit) project, but designed specifically for Claude Code integration and approval workflows. ## šŸ”’ Safety Features - **Explicit approval required** - no accidental commits - **Full change visibility** - shows staged and unstaged changes - **Respects .gitignore** automatically - **Comments preserved** for review history - **Auto-shutdown** after commit for security - **Claude Code integration** prevents AI from committing without review ## šŸ¤ Contributing Found a bug or have a feature request? Please check our [GitHub Issues](https://github.com/TeXmeijin/commit-guardian/issues). Pull requests are welcome! For major changes, please open an issue first. ## šŸ“„ License MIT License - feel free to use and modify as needed. --- **Happy Safe Committing with Claude Code!** šŸ›”ļøšŸ¤–āœØ