otter-commit-gen
一个 VS Code 扩展:读取暂存区的 Git Diff,调用 AI(DeepSeek、OpenAI、Claude 或任意 OpenAI 兼容服务)自动生成符合 Conventional Commits 规范的 Commit Message,并直接填入 SCM 提交输入框。
功能
- 在「源代码管理」面板标题栏提供一个按钮,一键生成 Commit Message
- 支持 DeepSeek、OpenAI、Claude(Anthropic)及自定义 OpenAI 兼容服务
- API Key 通过密码框输入,安全存储在系统钥匙串中,不落盘明文
- 支持自定义 Base URL、模型名称和提示词模板
- 生成的 Commit Message 自动填入提交输入框,可编辑后直接提交
环境要求
- VS Code
^1.125.0
- 一个 AI 服务的 API Key(DeepSeek / OpenAI / Anthropic Claude / 其他 OpenAI 兼容服务)
配置
1. 设置 API Key
API Key 不存放在设置文件里,而是通过命令输入、安全存储到系统钥匙串:
- 按
Cmd + Shift + P(macOS)或 Ctrl + Shift + P(Windows / Linux)打开命令面板 → 输入「设置 API Key」(或「Otter: 设置 API Key」)→ 回车 → 在弹出的密码框中粘贴 API Key。
2. 选择服务提供商
在设置(Cmd + ,)中搜索 otterCommitGen,配置以下选项:
| 设置项 |
默认值 |
说明 |
otterCommitGen.provider |
deepseek |
AI 服务提供商:deepseek / openai / anthropic / custom |
otterCommitGen.baseUrl |
"" |
API Base URL,留空使用 provider 默认地址,或填自定义端点 |
otterCommitGen.model |
"" |
模型名称,留空使用 provider 默认模型,或填自定义模型 |
otterCommitGen.prompt |
内置提示词 |
提示词模板,{diff} 占位符会被替换为暂存区 diff |
otterCommitGen.maxDiffLength |
2000 |
发送给 AI 的 diff 最大字符长度,超出部分会被截断 |
otterCommitGen.maxTokens |
2046 |
Anthropic(Claude)请求的最大输出 token 数 |
各 provider 的默认 Base URL 与模型:
| provider |
默认 Base URL |
默认模型 |
deepseek |
https://api.deepseek.com |
deepseek-chat |
openai |
https://api.openai.com/v1 |
gpt-4o-mini |
anthropic |
https://api.anthropic.com |
claude-sonnet-4-5-20250929 |
custom |
需手动填写 |
需手动填写 |
custom 适用于任意 OpenAI 兼容服务(如 OpenRouter、Ollama、本地代理等)。
使用
- 首次使用:按
Cmd + Shift + P(macOS)或 Ctrl + Shift + P(Windows / Linux)打开命令面板,输入「设置 API Key」配置好 Key,并选择 provider。
- 打开任意 git 仓库(「文件 → 打开文件夹」)。
- 修改代码后,在「源代码管理」面板标题栏点击插件图标(未暂存时会自动
git add 暂存全部改动)。
- 稍等片刻,生成的 Commit Message 会自动填入提交输入框,可直接编辑后提交。
提示:按钮仅在 git 仓库可用(when: scmProvider == git)。未暂存的改动会在点击时自动 git add 暂存。
已知问题
- 首次使用前需先通过「设置 API Key」命令配置 Key,否则会提示配置。
版本日志
1.2.0
- 新增可配置项
maxDiffLength 与 maxTokens,用户可自由设置 diff 截断长度与 Anthropic 最大输出 token 数
1.1.1
- 精简默认提示词,减少输入 token,同时保留标题行与可选正文的结构
- 降低 Anthropic 请求的最大输出 token 限制,从 4096 调整为 2046,减少生成耗时并避免冗长输出
1.1.0
- 点击生成时自动
git add 暂存改动(暂存区为空时),免去手动暂存步骤
- 优化默认提示词:更细粒度的生成规则(Conventional Commits 格式、中英术语规则、格式与简洁约束、类型白名单)
1.0.0
- API Key 改为密码框输入 + 系统钥匙串安全存储,不再明文保存
- 新增 provider 选择:DeepSeek / OpenAI / Claude(Anthropic 原生 API)/ 自定义 OpenAI 兼容服务
- Base URL 与模型支持按 provider 预设,也支持自定义覆盖
0.0.1
- 初始版本:读取暂存区 Diff,调用 OpenAI 兼容 API 生成 Commit Message,支持 apiKey / baseUrl / model / prompt 动态配置。
| |