All the commits in this repo are authored by OpenCommit — look at the commits to see how OpenCommit works. Emojis and long commit descriptions are configurable, basically everything is.
You can use OpenCommit by simply running it via the CLI like this oco. 2 seconds and your staged changes are committed with a meaningful message.
-
Install OpenCommit globally to use in any repository:
npm install -g opencommit
-
Get your API key from OpenAI or other supported LLM providers (we support them all). Make sure that you add your OpenAI payment details to your account, so the API works.
-
Set the key to OpenCommit config:
oco config set OCO_API_KEY=<your_api_key>
Your API key is stored locally in the
~/.opencommitconfig file.
You can call OpenCommit with oco command to generate a commit message for your staged changes:
git add <files...>
ocoRunning git add is optional, oco will do it for you.
You can also run it with local model through ollama:
- install and start ollama
- run
ollama pull llama3:8b(only once) - run (in your project directory):
git add <files...>
oco config set OCO_AI_PROVIDER='ollama' OCO_MODEL='llama3:8b'OpenCommit has no default model for Ollama. Set OCO_MODEL to a model that you pulled.
If you have ollama that is set up in docker/ on another machine with GPUs (not locally), you can change the default endpoint url.
You can do so by setting the OCO_API_URL environment variable as follows:
oco config set OCO_API_URL='http://192.168.1.10:11434'where 192.168.1.10 is example of endpoint URL, where you have ollama set up.
If you encounter issues with Ollama, such as the error
✖ local model issues. details: connect ECONNREFUSED ::1:11434It's likely because Ollama is not listening on IPv6 by default. To fix this, you can set the OLLAMA_HOST environment variable to 0.0.0.0 before starting Ollama:
export OLLAMA_HOST=0.0.0.0This will make Ollama listen on all interfaces, including IPv6 and IPv4, resolving the connection issue. You can add this line to your shell configuration file (like .bashrc or .zshrc) to make it persistent across sessions.
You can run OpenCommit with local models served by llama.cpp:
- install and build llama.cpp
- start the server with a GGUF model:
./llama-server -m model.gguf --port 8080 - run (in your project directory):
git add <files...>
oco config set OCO_AI_PROVIDER='llamacpp' OCO_API_URL='http://localhost:8080'If the server is running on a different machine, set the URL accordingly:
oco config set OCO_API_URL='http://192.168.1.10:8080'There are multiple optional flags that can be used with the oco command:
Link to the GitMoji specification: https://gitmoji.dev/
This flag enables GitMoji and allows users to use all emojis in the GitMoji specification. Without the flag, OCO_EMOJI=true uses a shorter set of 10 emojis (🐛✨📝🚀✅♻️⬆️🔧🌐💡) to limit the number of tokens sent in each request.
This is due to limit the number of tokens sent in each request. However, if you would like to use the full GitMoji specification, you can use the --fgm flag.
oco --fgm
If you always want the full specification, turn it on once in the config instead of passing the flag on every run:
oco config set OCO_EMOJI_FULL_SPEC=trueThe setting also applies to messages generated by the prepare-commit-msg git hook, which does not take flags.
Use --yes (or -y) to commit the staged files without a prompt, for example in a script:
git add <files...>
oco --yes
With this flag, OpenCommit never prompts, never stages files and never pushes. If something is missing, such as staged files, an API key or the configured model, it prints an error and exits with code 1.
Create a .env file in the repository to change the message format:
OCO_LANGUAGE=<locale, scroll to the bottom to see options>
OCO_DESCRIPTION=<postface a message with ~3 sentences description of the changes>
OCO_EMOJI=<boolean, add GitMoji>
OCO_EMOJI_POSITION_BEFORE_DESCRIPTION=<boolean, place GitMoji immediately before the commit subject; default: false>
OCO_EMOJI_FULL_SPEC=<boolean, use the full GitMoji specification, same as the --fgm flag; default: false>
OCO_ONE_LINE_COMMIT=<one line commit message, default: false>
OCO_OMIT_SCOPE=<boolean, omit the scope from the message; default: false>
OCO_TICKET_FROM_BRANCH=<boolean, reference the ticket ID from the branch name in the message; default: false>A cloned repository can contain a hostile .env file. Therefore OpenCommit ignores all other settings in it and shows a warning. Set them globally or in the shell.
The global ~/.opencommit config file can contain the settings above and these settings:
OCO_AI_PROVIDER=<openai (default), anthropic, azure, ollama, llamacpp, mlx, gemini, flowise, groq, mistral, deepseek, minimax, openrouter>
OCO_API_KEY=<your OpenAI API token> // or other LLM provider API token
OCO_API_URL=<may be used to set proxy path to OpenAI api>
OCO_API_CUSTOM_HEADERS=<JSON string of custom HTTP headers for openai, groq, deepseek, minimax, ollama and llamacpp>
OCO_TOKENS_MAX_INPUT=<max model token limit (default: 4096)>
OCO_TOKENS_MAX_OUTPUT=<max response tokens (default: 500)>
OCO_REASONING=<override reasoning-model auto-detection with true or false; omitted by default>
OCO_REASONING_MAX_TOKENS=<max completion token budget for reasoning models, including hidden reasoning tokens (default: 1000)>
OCO_MODEL=<a model of your provider; 'gpt-6-luna' is the default for OpenAI>
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=<message template placeholder, default: '$msg'>
OCO_PROMPT_MODULE=<either conventional-commit or @commitlint, default: conventional-commit>The environment variables of your shell override the .env file, and the .env file overrides the global config.
When you switch providers, set the new provider's API key, model, and any required endpoint or custom headers. Put OCO_AI_PROVIDER alongside the API key when you select a different provider in the shell. A key, endpoint, or custom header configured without a provider applies to the globally configured provider. If OpenCommit prompts for a key for a shell provider that differs from the global provider, it uses the key for the current run.
Simply set any of the variables above like this:
oco config set OCO_MODEL=gpt-6-lunaTo see all available configuration parameters and their accepted values:
oco config describeTo see details for a specific parameter:
oco config describe OCO_MODELConfigure GitMoji to preface a message.
oco config set OCO_EMOJI=trueTo remove preface emojis:
oco config set OCO_EMOJI=falseBy default, GitMoji appears at the start of the commit header:
🐛 (server.ts): handle an unavailable port
To place GitMoji immediately before the subject, after the Conventional Commit type and optional scope:
oco config set OCO_EMOJI_POSITION_BEFORE_DESCRIPTION=truefix(server.ts): 🐛 handle an unavailable port
This setting only affects commits generated with OCO_EMOJI=true, OCO_EMOJI_FULL_SPEC=true or --fgm.
Other config options are behaving the same.
You can set the OCO_WHY config to true to have OpenCommit describe WHY the changes were done. Default is false. This option works only with the @commitlint prompt module.
To make this perform accurate we must store 'what files do' in some kind of an index or embedding and perform a lookup (kinda RAG) for the accurate git commit message. If you feel like building this comment on this ticket #398 and let's go from there together.
oco config set OCO_WHY=trueWith OpenAI, OpenCommit uses the gpt-6-luna model by default.
You can switch to gpt-6.1-terra, which performs better, but costs more:
oco config set OCO_MODEL=gpt-6.1-terraOpenCommit automatically fetches available models from your provider when you run oco setup. Models are cached for 7 days to reduce API calls.
To see available models for your current provider:
oco modelsTo refresh the model list (e.g., after new models are released):
oco models --refreshTo see models for a specific provider:
oco models --provider anthropicBy default OpenCommit uses OpenAI.
You could switch to Azure OpenAI Service or Flowise or Ollama or llama.cpp.
oco config set OCO_AI_PROVIDER=azure OCO_API_KEY=<your_azure_api_key> OCO_API_URL=<your_azure_endpoint>
oco config set OCO_AI_PROVIDER=flowise OCO_API_KEY=<your_flowise_api_key> OCO_API_URL=<your_flowise_endpoint>
oco config set OCO_AI_PROVIDER=ollama OCO_API_KEY=<your_ollama_api_key> OCO_API_URL=<your_ollama_endpoint>
oco config set OCO_AI_PROVIDER=llamacpp OCO_API_URL=<your_llamacpp_endpoint>To use any OpenAI-compatible API or gateway, keep the openai provider and set the base URL of the gateway in OCO_API_URL:
oco config set OCO_AI_PROVIDER=openai OCO_API_KEY=<your_gateway_api_key> OCO_API_URL=<gateway_base_url> OCO_MODEL=<gateway_model_id>The base URL is the part before /chat/completions, for example https://router.example.com/v1. oco models --refresh lists the models of the configured gateway.
OpenRouter remains a named provider:
oco config set OCO_AI_PROVIDER=openrouter OCO_API_KEY=<your_openrouter_api_key>If you are behind a proxy, you can set it in the config:
oco config set OCO_PROXY=http://127.0.0.1:7890If OCO_PROXY is unset, OpenCommit will automatically use HTTPS_PROXY or HTTP_PROXY environment variables, except for the hosts in NO_PROXY.
To explicitly disable proxy use for OpenCommit, even when those environment variables are set:
oco config set OCO_PROXY=nullTo globally specify the language used to generate commit messages:
# de, German, Deutsch
oco config set OCO_LANGUAGE=de
oco config set OCO_LANGUAGE=German
oco config set OCO_LANGUAGE=Deutsch
# fr, French, française
oco config set OCO_LANGUAGE=fr
oco config set OCO_LANGUAGE=French
oco config set OCO_LANGUAGE=françaiseThe default language setting is English All available languages are currently listed in the i18n folder
A prompt for pushing to git is on by default but if you would like to turn it off just use:
oco config set OCO_GITPUSH=falseand it will exit right after commit is confirmed without asking if you would like to push to remote.
OpenCommit allows you to choose the prompt module used to generate commit messages. By default, OpenCommit uses its conventional-commit message generator. However, you can switch to using the @commitlint prompt module if you prefer. This option lets you generate commit messages in respect with the local config.
You can set this option by running the following command:
oco config set OCO_PROMPT_MODULE=<module>Replace <module> with either conventional-commit or @commitlint.
The @commitlint module runs the @commitlint package and configuration of the current repository. If you set this module globally, use OpenCommit only in repositories that you trust.
To switch to using the @commitlint prompt module, run:
oco config set OCO_PROMPT_MODULE=@commitlintTo switch back to the default conventional-commit message generator, run:
oco config set OCO_PROMPT_MODULE=conventional-commitThe integration between @commitlint and OpenCommit is done automatically the first time OpenCommit is run with OCO_PROMPT_MODULE set to @commitlint. OpenCommit does not detect later changes. After you change the @commitlint configuration or OCO_LANGUAGE, generate the configuration again:
oco commitlint forceTo view the generated configuration for @commitlint, you can use this command:
oco commitlint getThis allows you to ensure that the configuration is set up as desired.
OpenCommit saves the generated configuration in the .opencommit-commitlint file in the root of your repository. The file contains the prompts for your @commitlint rules and an example commit message. You can edit the file to match your project guidelines. oco commitlint force overwrites your edits.
This offers you greater control over the generated commit messages, allowing for customization that aligns with your project's conventions.
The opencommit or oco commands can be used in place of the git commit -m "${generatedMessage}" command. This means that any regular flags that are used with the git commit command will also be applied when using opencommit or oco.
oco --no-verifyis translated to :
git commit -m "${generatedMessage}" --no-verifyTo include a message in the generated message, you can utilize the template function, for instance:
oco '#205: $msg'opencommit examines placeholders in the parameters, allowing you to append additional information before and after the placeholders, such as the relevant Issue or Pull Request. Similarly, you have the option to customize the OCO_MESSAGE_TEMPLATE_PLACEHOLDER configuration item, for example, simplifying it to $m!"
The OCO_MESSAGE_TEMPLATE_PLACEHOLDER feature in the opencommit tool allows users to embed a custom message within the generated commit message using a template function. This configuration is designed to enhance the flexibility and customizability of commit messages, making it easier for users to include relevant information directly within their commits.
In our codebase, the implementation of this feature can be found in the following segment:
commitMessage = messageTemplate.replace(
config.OCO_MESSAGE_TEMPLATE_PLACEHOLDER,
() => generatedMessage
);This line is responsible for replacing the placeholder in the messageTemplate with the generated message.
For instance, using the command oco '$msg #205', users can leverage this feature. The provided code represents the backend mechanics of such commands, ensuring that the placeholder is replaced with the appropriate commit message.
Once users have generated their desired commit message, they can proceed to commit using the generated message. By understanding the feature's full potential and its implementation details, users can confidently use the generated messages for their commits.
If your branches carry a ticket ID, OpenCommit can reference it in every generated message:
oco config set OCO_TICKET_FROM_BRANCH=trueOn the branch feat/foo-1234-button the ticket is added as a footer, where Conventional Commits puts issue references:
feat(button): add the component
Refs: FOO-1234
With OCO_ONE_LINE_COMMIT=true the message has no footer, so the ticket goes at the end of the subject: feat(button): add the component (FOO-1234).
The ticket ID is the first LETTERS-123 style key in the branch name, written in upper case. Branches without such a key keep the generated message as it is, and so do messages that already name the ticket. The setting also applies to the prepare-commit-msg git hook.
You can remove files from being sent to OpenAI by creating ignore files. OpenCommit supports both local and global ignore files:
Create a .opencommitignore file in your project root:
path/to/large-asset.zip
**/*.jpg
docs/generated/
*.generated.ts
Create a global .opencommitignore file in your home directory (~/.opencommitignore) to ignore files across all projects:
*.log
*.tmp
.DS_Store
node_modules/
.env
.env.local
dist/
build/
coverage/
.vscode/
.idea/
Priority: Local ignore rules are applied after global rules. Both files use gitignore syntax.
This helps prevent opencommit from uploading artifacts and large files.
By default, opencommit ignores lock files, such as package-lock.json, pnpm-lock.yaml and Cargo.lock. It does not ignore source files with similar names, such as mutex-lock.ts.
You can set OpenCommit as Git prepare-commit-msg hook. Hook integrates with your IDE Source Control and allows you to edit the message before committing.
To set the hook:
oco hook setTo unset the hook:
oco hook unsetTo use the hook:
git add <files...>
git commitOr follow the process of your IDE Source Control feature, when it calls git commit command — OpenCommit will integrate into the flow.
The hook records the absolute paths of Node.js and OpenCommit, so it works in clients that start Git without Node.js in PATH. After you move or reinstall either one, run oco hook set again. If either recorded path disappears, the hook lets Git continue and prints a recovery hint.
Run oco hook unset in repositories that use the hook before you uninstall or downgrade OpenCommit. Older releases can only remove the symlinks they install. If oco hook set reports a different hook after an upgrade, check whether the existing prepare-commit-msg is an old OpenCommit symlink. Remove that symlink from the configured hooks directory manually once you have verified its target, then run oco hook set again.
Install OpenCommit as a dependency and call generateCommitMessage with the output of git diff:
npm install opencommitimport { execSync } from 'node:child_process';
import { generateCommitMessage } from 'opencommit';
const diff = execSync('git diff --staged', { encoding: 'utf8' });
const message = await generateCommitMessage(diff, {
config: {
OCO_AI_PROVIDER: 'openai',
OCO_API_KEY: process.env.OPENAI_API_KEY,
OCO_MODEL: 'gpt-6-luna',
OCO_EMOJI: true
},
context: 'Optional context for the model, like oco --context',
fullGitMojiSpec: false
});The config keys are the configuration keys of the CLI that set the provider, the model and the message format. Keys that you omit get the CLI default values. The library does not read ~/.opencommit, .env or OCO_* environment variables, and it does not prompt or commit. The library always uses the conventional-commit prompt module. Errors from the provider are thrown to the caller.
OCO_PROXY applies only to the requests to the AI provider. The library does not change the global proxy settings of your process. The library throws an error if you set OCO_PROXY with the gemini provider.
You pay your AI provider for your requests.
OpenCommit stores your key locally.
