Scripts2026年4月1日·1 分钟阅读

OpenCommit — AI-Powered Git Commit Messages

OpenCommit auto-generates meaningful git commit messages using AI. 7.2K+ stars. Claude, GPT, Ollama, git hook integration. Open source.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 17/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
Script
安装
Stage only
信任
信任等级:Established
入口
opencommit.md
安全暂存命令
npx -y tokrepo@latest install 8f087c35-53cf-4194-8342-c3ed43018302 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

TL;DR
CLI tool that auto-generates meaningful git commit messages using Claude, GPT, or Ollama from staged diffs.
§01

What it is

OpenCommit is a CLI tool that analyzes your staged git changes and generates meaningful commit messages using AI. It reads the diff, sends it to an LLM (Claude, GPT, or local models via Ollama), and proposes a conventional commit message. It supports git hook integration so commit messages are generated automatically on every commit.

Developers who want consistent, descriptive commit messages without spending time writing them benefit from OpenCommit. Teams enforcing conventional commit standards find it especially useful.

§02

How it saves time or tokens

Writing good commit messages takes 30-60 seconds per commit. OpenCommit generates one in about 1 second. Over a day with dozens of commits, this saves meaningful time. The AI reads the full diff context, producing messages that are often more descriptive than hastily written manual ones. The token_estimate per commit is approximately 389 tokens.

§03

How to use

  1. Install OpenCommit globally via npm
  2. Configure your AI provider and API key
  3. Stage your changes and run oco instead of git commit
§04

Example

# Install
npm install -g opencommit

# Configure provider
oco config set OCO_API_KEY=sk-ant-your-key
oco config set OCO_MODEL=claude-sonnet-4-20250514

# Use: stage changes and run
git add .
oco
# Output: feat(auth): add JWT token refresh logic with expiry check

# Or install as git hook (auto-generate on every commit)
oco hook set
git add . && git commit  # Message generated automatically
§05

Related on TokRepo

§06

Common pitfalls

  • Large diffs (many files changed) produce longer context and higher token costs; commit frequently in small batches
  • The git hook runs on every commit including rebases and merges; disable it for non-standard commits
  • Generated messages may not match your team's exact commit convention; customize the prompt template in config

常见问题

Which AI models does OpenCommit support?+

OpenCommit supports OpenAI (GPT-4, GPT-4o), Anthropic (Claude), local models via Ollama, and any OpenAI-compatible endpoint. You configure the provider and model in the oco config.

Can I use OpenCommit with a git hook?+

Yes. Run `oco hook set` to install a prepare-commit-msg hook. Every `git commit` will automatically generate an AI commit message. Run `oco hook unset` to remove it.

Does OpenCommit follow Conventional Commits?+

Yes. OpenCommit generates messages in Conventional Commits format by default (feat:, fix:, docs:, etc.). You can customize the format through configuration.

How much does each commit message cost?+

Cost depends on diff size and model. A typical commit with Claude costs fractions of a cent. Large diffs with GPT-4 may cost a few cents. Using Ollama with local models is free.

Can I review the message before committing?+

Yes. By default, OpenCommit shows the generated message and asks for confirmation. You can edit it, regenerate, or cancel. Auto-approve mode is available but not recommended.

引用来源 (3)
🙏

来源与感谢

di-sukharev/opencommit — 7,200+ GitHub stars

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产