Show HN: I created a CLI that stages and commits my code for me with AI

17 hours ago 1

 MIT TypeScript Bun

An intelligent CLI tool that automatically stages and commits files using AI-powered commit message generation.

⚠️ Note: This tool requires an OpenAI API key to function. It will analyze your code changes and generate commit messages using GPT-4.

⚠️ Vibe Coded: The majority of this code was "vibe coded". I use the tool for my own projects, and I checked for any serious bugs and issues, but still: Use at your own risk.

  • 🤖 AI-powered commit messages using GPT-4.1 with conventional commit format
  • 📊 Line-by-line diff analysis showing exactly what changed
  • 🎯 Smart file grouping for logical commits
  • 🔍 Detailed change tracking (added/removed/modified lines)
  • Safety checks to prevent conflicts with existing staged files
  • 🎨 Beautiful colored CLI with interactive confirmations
  • YOLO mode for automatic commits without confirmation
  • Node.js (v18+) or Bun (v1.0+)
  • Git configured with user.name and user.email
  • OpenAI API key (Get one here)

Run directly without installing (Recommended)

You can also run gitprompt directly without installing it globally:

# Run with npx (npm) npx gitprompt # Or with bunx (bun) bunx gitprompt # With options npx gitprompt --yolo bunx gitprompt --help

This approach downloads and runs the latest version on-demand, which is perfect for occasional use or trying out the tool.

# Install globally via npm npm install -g gitprompt # Or via yarn yarn global add gitprompt # Or via pnpm pnpm add -g gitprompt # Or via bun bun install -g gitprompt

After installation, you can use gitprompt command in any git repository:

Install from GitHub (Development)

# Clone the repository git clone https://github.com/xyassini/gitprompt.git cd gitprompt # Install dependencies bun install # Make globally available (optional) bun link

Create a .env file or set your OpenAI API key:

# Option 1: Environment variable export OPENAI_API_KEY="your-api-key-here" # Option 2: .env file (add to .gitignore!) echo "OPENAI_API_KEY=your-api-key-here" > .env

Interactive Mode (Default)

# Navigate to your git repository and run gitprompt
# Skip confirmations and commit everything automatically gitprompt --yolo # or short form gitprompt -y
# View all available options and commands gitprompt --help

If you're developing locally from the GitHub repository:

# Interactive mode bun src/index.ts # YOLO mode bun src/index.ts --yolo # Help bun src/index.ts --help
🤖 gitprompt - AI-Powered Git Assistant 🤖 Analyzing repository status... 🤖 Calculating diffs... ✅ Found 3 file(s) with changes 🤖 Generating intelligent commit groups... ℹ️ Found 2 commit group(s) 📦 Commit Group 1 Message: feat(auth): add user authentication and JWT validation Files: • src/auth.ts • src/middleware/auth.ts • tests/auth.test.ts ? Commit this group? (y/n) y 🤖 Staging files: src/auth.ts, src/middleware/auth.ts, tests/auth.test.ts 🤖 Creating commit: feat(auth): add user authentication and JWT validation ✅ Committed: feat(auth): add user authentication and JWT validation 📦 Commit Group 2 Message: docs: update API documentation for auth endpoints Files: • README.md • docs/api.md ? Commit this group? (y/n) y ✅ All done! 🎉

The CLI provides beautiful colored output with:

  • 🤖 Progress indicators for each step
  • Success messages when operations complete
  • Error messages with helpful context
  • 📦 Commit group previews showing files and messages
  • Interactive prompts for confirmation
🤖 gitprompt - AI-Powered Git Assistant 🤖 Analyzing repository status... 🤖 Calculating diffs... ✅ Found 8 file(s) with changes 🤖 Generating intelligent commit groups... 🤖 Parsing AI recommendations... ℹ️ Found 3 commit group(s) 📦 Commit Group 1 Message: feat(core): add AI-powered git assistant modules Files: • src/ai.ts • src/diff.ts • src/git.ts ? Commit this group? (y/n) y 🤖 Staging files: src/ai.ts, src/diff.ts, src/git.ts 🤖 Creating commit: feat(core): add AI-powered git assistant modules ✅ Committed: feat(core): add AI-powered git assistant modules
gitprompt/ ├── src/ │ ├── git.ts # Git operations (status, staging, committing) │ ├── diff.ts # Diff calculation and file content analysis │ ├── ai.ts # AI integration for commit message generation │ └── utils.ts # Validation and utility functions ├── cli.ts # CLI interface and user interaction ├── index.ts # Original programmatic interface ├── types.ts # Type definitions └── package.json

The main CLI application featuring:

  • Argument parsing with yargs
  • Colored output with yoctocolors
  • Interactive prompts for commit confirmation
  • YOLO mode for automated commits
  • Error handling with user-friendly messages

Handles all git-related operations:

  • getStatusMatrix() - Gets current git status
  • getUnstagedChanges() - Filters for unstaged files
  • getGitConfig() - Reads global git configuration
  • stageFiles() - Stages specific files
  • commitChanges() - Creates commits with author info

Manages diff calculation and file analysis:

  • calculateLineDiffs() - Line-by-line comparison
  • calculateDiffForFile() - Complete diff analysis for a file
  • getDiffs() - Processes all unstaged files
  • Determines change types: added, removed, modified, untracked

AI integration for intelligent commit grouping:

  • generateCommitGroups() - Calls GPT-4 to analyze changes
  • parseCommitGroups() - Parses AI response into structured data
  • Groups related files and generates conventional commit messages

Validation and utility functions:

  • validateNoStagedFiles() - Ensures clean staging area
  • validateNoDiffs() - Checks for changes to process
  1. 🔍 Status Check: Reads git status and validates no files are already staged
  2. 📊 Diff Analysis: Calculates line-by-line diffs for all unstaged files
  3. 🤖 AI Processing: Sends diffs to GPT-4 for intelligent file grouping and commit message generation
  4. 📋 Interactive Review: Shows each commit group and asks for confirmation
  5. 📝 Staging & Committing: Stages and commits approved groups sequentially
  • AI Model: Uses GPT-4.1, configurable in src/ai.ts
  • Git Config: Automatically uses your global git user.name and user.email
  • Colors: Fully customizable in the CLI code
  • ✅ Prevents running when files are already staged
  • ✅ Validates git configuration before proceeding
  • ✅ Interactive confirmations by default (unless --yolo)
  • ✅ Sequential processing to avoid git conflicts
  • ✅ Detailed error handling and user feedback
  • Node.js/Bun
  • Git configured with user.name and user.email
  • OpenAI API key for GPT-4 access
  • yargs - Command line argument parsing
  • yoctocolors - Terminal colors and styling
  • @ai-sdk/openai - AI integration
  • isomorphic-git - Git operations in JavaScript

This project was created using bun init in bun v1.2.12. Bun is a fast all-in-one JavaScript runtime.

"Git user.name and user.email must be configured"

git config --global user.name "Your Name" git config --global user.email "[email protected]"

"There are already staged files"

# Either commit existing staged files git commit -m "your message" # Or unstage them git reset

"OpenAI API Error"

  • Verify your API key is set correctly
  • Check your OpenAI account has credits
  • Ensure you have access to GPT-4

"Could not find HEAD"

  • Make sure you're in a git repository
  • Ensure you have at least one commit in your repository

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

# Clone the repo git clone https://github.com/xyassini/gitprompt.git cd gitprompt # Install dependencies bun install # Run in development bun src/index.ts
  • Follow the existing code style
  • Add tests for new features
  • Update documentation as needed
  • Use conventional commit messages
  • Code Analysis: This tool analyzes your code locally and sends diff information to OpenAI's API
  • No Code Storage: Your code is not stored by the tool or OpenAI beyond the API call
  • API Security: Uses OpenAI's secure API endpoints
  • Local Processing: All git operations happen locally on your machine

This project is licensed under the MIT License - see the LICENSE file for details.


⭐ Star this repo if you find it helpful!

The project includes comprehensive tests for all core functionality:

# Run all tests bun test # Run tests in watch mode bun test --watch
  • 🛠️ Utils: Validation functions, error handling, logging
  • 📊 Diff: Line-by-line diff calculation, file change detection
  • 🔧 Git: Status matrix parsing, configuration reading, file staging logic
  • 🤖 AI: Commit group parsing, error handling

Tests use Bun's built-in test runner with mocking for external dependencies.

Read Entire Article