AI-powered Git commit message generator with efficient chunk processing for large files
A sophisticated CLI tool that generates meaningful, contextual commit messages using ORCommit and OpenAI APIs. Designed with a modular TypeScript architecture and optimized for handling large codebases through intelligent diff chunking.
- 🤖 AI-Powered: Generate commit messages using ORCommit and OpenAI models
- 📦 Token-Aware Chunking: Intelligently split large diffs based on actual token limits
- 🚀 Smart Push Integration: Interactive push prompts with automatic upstream setup
- 🎨 Elegant UI: Structured progress with phase indicators and timing
- ⚡ Lightning Fast: Intelligent caching with memory and disk persistence
- 🔧 Highly Configurable: Extensive CLI options and provider settings
- 🔒 Secure: Safe storage of API keys with proper file permissions (600)
- 🎯 Conventional Commits: Full support for conventional commit format with emoji
- 🛡️ Robust: Comprehensive error handling with timeouts and auto-recovery
- 🧠 Smart Filtering: Automatically filters generated files and whitespace
- 🧪 Production Ready: Comprehensive test suite with 90%+ coverage
Install globally via npm:
npm install -g orcommitOr use directly with npx:
npx orcommit-
Set up your API key:
orc config set openrouter your-api-key-here # or for OpenAI orc config set openai your-openai-key-here
-
Stage your changes:
git add . -
Generate and create commit:
orc commit
That's it! The tool will analyze your staged changes and generate an appropriate commit message.
Generate and create a commit message for staged changes.
Options:
Basic Options:
-y, --yes- Skip confirmation and auto-commit-d, --dry-run- Generate message without creating commit-v, --verbose- Enable verbose logging-w, --watch- Watch for changes and auto-generate commits
Commit Format:
-s, --scope <scope>- Specify commit scope (e.g., auth, ui, api)-t, --type <type>- Specify commit type (feat, fix, docs, etc.)-b, --breaking- Mark as breaking change--emoji- Include appropriate emoji in commit message--one-line- Generate single-line commit message--description-length <length>- Maximum description length
Provider & Processing:
-p, --provider <provider>- Specify AI provider (openrouter|openai)--max-files <count>- Maximum number of files to analyze--ignore-generated- Ignore auto-generated files (default: true)--ignore-whitespace- Ignore whitespace-only changes (default: true)
Caching:
--no-cache- Disable caching for this commit--clear-cache- Clear cache before generating
Git Integration:
--push- Push changes to remote after commit--auto-push- Automatically push all future commits
Examples:
# Basic usage with interactive push prompt
orc commit
# Auto-confirm and push
orc commit --yes --push
# Generate with emoji and one-line format
orc commit --emoji --one-line
# Specify type, scope and auto-push
orc commit --type feat --scope auth --auto-push
# Dry run to see generated message
orc commit --dry-run --verbose
# Breaking change with description limit
orc commit --breaking --type feat --description-length 50
# Clear cache and use specific provider
orc commit --clear-cache --provider openai
# Process only 5 files with no caching
orc commit --max-files 5 --no-cacheManage configuration settings.
Subcommands:
# Set API key
orc config set openrouter sk-your-key-here
orc config set openai sk-your-openai-key
# Set default model
orc config model openrouter anthropic/claude-3-haiku:beta
orc config model openai gpt-4
# View configuration
orc config get
orc config get openrouter
# Show config file path
orc config pathManage intelligent caching system.
# Show cache statistics
orc cache stats
# Clear all cached data
orc cache clear
# Clean up expired entries
orc cache cleanupTest API connection for configured providers.
# Test default provider
orc test
# Test specific provider
orc test openrouter
orc test openaiConfiguration is stored in ~/.config/orcommit.json with secure 600 permissions.
{
"providers": {
"openrouter": {
"baseUrl": "https://openrouter.ai/api/v1",
"timeout": 60000
},
"openai": {
"baseUrl": "https://api.openai.com/v1",
"timeout": 60000
}
},
"preferences": {
"defaultProvider": "openrouter",
"maxTokens": 500,
"temperature": 0.6,
"autoConfirm": false,
"language": "en",
"commitFormat": "conventional"
}
}When using --type option, these conventional commit types are supported:
feat- New featuresfix- Bug fixesdocs- Documentation changesstyle- Code style changes (formatting, etc.)refactor- Code refactoringtest- Adding or updating testschore- Maintenance tasksperf- Performance improvementsci- CI/CD changesbuild- Build system changesrevert- Reverting previous commits
The tool is built with a modular TypeScript architecture:
- CLI Module: Command-line interface using Commander.js with @clack/prompts
- Config Module: Secure configuration management with file permissions (600)
- Git Module: Advanced Git repository interaction with intelligent diff parsing
- API Module: Robust HTTP client with exponential backoff and concurrency control
- Logger Module: Elegant progress indicators with timing and structured output
- Tokenizer Module: Token-aware chunking using tiktoken for accurate processing
- Cache Module: Two-level caching (memory + disk) with TTL and cleanup
- Diff Filter Module: Smart filtering of generated files and irrelevant changes
- Core Orchestrator: Main coordination with phase-based processing
- Token-Based Chunking: Uses tiktoken to respect actual model token limits
- Intelligent Caching: Memory + disk caching with automatic cleanup and TTL
- Smart Filtering: Automatically filters out generated files, lock files, and whitespace-only changes
- Interactive Push: Prompts user for push with automatic upstream configuration
- Elegant UI: Phase-based progress with emojis, timing, and structured output
- Robust Error Handling: Comprehensive error types with timeout protection
- Type Safety: Full TypeScript coverage with strict mode enabled
- Production Ready: Extensive test suite with unit and integration tests
You can set API keys via environment variables:
export OPENROUTER_API_KEY="your-key-here"
export OPENAI_API_KEY="your-openai-key"The tool intelligently processes large codebases:
Token-Aware Chunking:
- Uses tiktoken for accurate token counting
- Respects model-specific token limits (GPT-4: 8K, Claude: 100K)
- Preserves context at logical boundaries (files, functions)
- Dynamic chunk sizing based on available tokens
Intelligent Filtering:
- Auto-detects and skips generated files (dist/, build/, .lock files)
- Filters out whitespace-only changes
- Relevancy scoring to focus on meaningful changes
- Configurable file size limits (default: 1MB per file)
Performance:
- Memory + disk caching for instant repeated requests
- Concurrent API processing (up to 3 parallel requests)
- Exponential backoff for rate limit handling
Configure specific models for each provider:
# ORCommit models
orc config model openrouter anthropic/claude-3-haiku:beta
orc config model openrouter openai/gpt-4-turbo-preview
# OpenAI models
orc config model openai gpt-4
orc config model openai gpt-3.5-turboElegant Progress Display:
🔍 Analyzing changes...
✓ Found 15 staged files
✓ Ready to analyze 12 files
🤖 Generating commit message...
✓ Commit message generated (1.2s)
💾 Creating commit...
✓ Commit created
✓ Commit: feat(ui): add interactive push prompts
Do you want to push to remote? › Yes
🚀 Pushing to remote...
✓ Pushed to main (2.1s)
✓ Changes pushed successfully
Smart Push Integration:
- Interactive prompts for push decisions
- Automatic upstream branch setup
- Support for multiple remotes
- Graceful handling of push failures
git clone <repository>
cd orcommit
npm installnpm run build # Build TypeScript
npm run dev # Run in development mode
npm run test # Run tests
npm run test:watch # Run tests in watch mode
npm run lint # Run ESLint
npm run format # Format code with PrettierThe project includes comprehensive tests:
# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Run specific test file
npm test -- utils.test.ts- Node.js >= 16.0.0
- Git repository
- ORCommit or OpenAI API key
- API keys are stored with 600 file permissions (owner read/write only)
- No API keys are logged or exposed in error messages
- Secure HTTP client with proper timeout and retry handling
"Not in a git repository"
- Ensure you're running the command inside a Git repository
"No staged changes found"
- Use
git addto stage files before generating commits - Check if files are in .gitignore
"API key not configured"
- Set your API key:
orc config set openrouter your-key - Verify with:
orc config get
"All changes were filtered out"
- Check if only generated files were changed
- Try with
--ignore-generated=falseto include all files - Use
--verboseto see what was filtered
"Operation timed out"
- Large repositories may take time - operations auto-timeout at 30s
- Try with
--max-files 10to limit scope - Check your internet connection and API key validity
"Push failed"
- Ensure you have push permissions to the repository
- Check if upstream branch is configured:
git branch -vv - Try manual push first:
git push
Use verbose logging for detailed information:
orc commit --verboseMIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
- GitHub Issues: Report bugs or request features
- Documentation: Additional guides and examples
- OpenRouter for providing access to multiple AI models
- OpenAI for their powerful language models
- The open-source community for the excellent tools and libraries used in this project
Built with ❤️ using TypeScript, Commander.js, and cutting-edge AI technology.