A Python script that runs git diff --staged
, and if there are changes, sends a request to a local Ollama chat to generate a commit name and message.
- Automatically generates commit messages based on your staged changes
- Supports multiple AI providers (Ollama, Web UI)
- Follows conventional commit formatting
- User-friendly CLI with helpful error messages
- Configurable through JSON configuration
- Python 3.12
- Git
- Ollama or a compatible local AI service
-
Clone this repository:
git clone <repository-url> cd opencode
-
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows, use venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
Or run the installation script:
./install.sh
The tool uses opencode.json
for configuration. An example configuration file is provided as opencode.json.example
. Copy this file to opencode.json
and modify it according to your setup:
cp opencode.json.example opencode.json
Then edit opencode.json
to match your AI provider configuration.
An example configuration is:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"ollama": {
"npm": "@ai-sdk/openai-compatible",
"name": "Ollama (local)",
"options": {
"baseURL": "http://localhost:11434/v1"
},
"models": {
"hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:IQ2_M": {
"name": "hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:IQ2_M",
"tools": true,
"thinking": true
}
}
}
}
}
# Basic usage
python opencode.py
# Show help
python opencode.py --help
# Use a specific provider
python opencode.py --provider ollama
# Show the diff without generating a commit message
python opencode.py --dry-run
# Enable verbose output
python opencode.py --verbose
# Open editor with generated commit message
python opencode.py --edit
# Automatically commit without prompting
python opencode.py --auto-commit
- The tool checks if you're in a Git repository
- It verifies you have staged changes
- It runs
git diff --staged
to get the changes - It sends the diff to your configured AI provider
- The AI generates a commit message following conventional commit formatting
- The tool displays the suggested commit message
- Make sure your AI service (Ollama/Web UI) is running
- Verify your configuration in opencode.json
- Ensure the specified model is available
- Check your network connection if using a remote service