by Gil2015
Intelligent Git commit code reviewer. Supports local (Ollama) and cloud models (DeepSeek, OpenAI, Anthropic) with a rich CLI UI. 本地AI智能 Git 提交代码审查工具。支持使用本地 (Ollama) 及云端模型 (DeepSeek, OpenAI, Anthropic),提供丰富的 CLI 交互界面。
# Add to your Claude Code skills
git clone https://github.com/Gil2015/code-gateYour Lightweight Local AI Code Review Assistant
Code Gate is an intelligent code review tool seamlessly integrated into your Git workflow. When you run git commit, it automatically analyzes staged code changes, utilizing local LLMs (Ollama) or cloud AI services to provide instant feedback on code quality, security suggestions, and optimization plans.
Supports zero-config execution via npx, npm/yarn/pnpm package integration, and automated Git Hook reviews, flexibly adapting to any development workflow.
No comments yet. Be the first to share your thoughts!
All methods rely on the configuration file. Please add a .codegate.js file to your project root first.
export default {
provider: 'ollama', // Default using Ollama local model
providerOptions: {
ollama: {
baseURL: 'http://localhost:11434',
model: 'qwen2.5-coder',
concurrencyFiles: 1
},
deepseek: {
baseURL: 'https://api.deepseek.com',
apiKeyEnv: 'DEEPSEEK_API_KEY',
model: 'deepseek-chat',
concurrencyFiles: 4,
apiKey: 'sk-xxxx' // Replace with your API Key (Avoid exposing in public code)
}
// openai: { baseURL: 'https://api.openai.com/v1', apiKeyEnv: 'OPENAI_API_KEY', model: 'gpt-4o-mini' },
// anthropic: { baseURL: 'https://api.anthropic.com', apiKeyEnv: 'ANTHROPIC_API_KEY', model: 'claude-3-5-sonnet' },
// azureOpenAI: { endpoint: 'https://your-endpoint.openai.azure.com', apiKeyEnv: 'AZURE_OPENAI_KEY', deployment: 'gpt-4o-mini', apiVersion: '2024-08-01-preview' },
// aliyun: { baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1', apiKeyEnv: 'DASHSCOPE_API_KEY', model: 'qwen-plus' },
// volcengine: { baseURL: 'https://ark.cn-beijing.volces.com/api/v3', apiKeyEnv: 'VOLCENGINE_API_KEY', model: 'doubao-pro-32k' },
// zhipu: { baseURL: 'https://open.bigmodel.cn/api/paas/v4', apiKeyEnv: 'ZHIPU_API_KEY', model: 'glm-4' }
},
language: 'en',
fileTypes: ['ts', 'tsx', 'css'],
ui: {
openBrowser: true,
port: 5175
},
limits: {
maxDiffLines: 10000,
maxFiles: 100
},
prompt: `You are a senior code reviewer responsible for ensuring code quality and security meet high standards.
Project Info:
- [Fill in your project info: architecture, standards, business type, etc.]
Review Checklist:
- Code is clean and readable
- Proper naming conventions for functions and variables
- No code duplication
- Correct error handling
- Input validation implemented
- Performance considerations addressed
Provide feedback prioritized by:
- Critical Issues (Must fix)
- Warnings (Should fix)
- Suggestions (Consider improving, avoid unnecessary suggestions if not essential)
Provide specific examples on how to fix the issues.`,
output: {
dir: '.review-logs'
},
// Agent Mode (Optional) - Enables AI to actively retrieve code context
agent: {
enabled: false, // Set to true to enable Agent mode (supports DeepSeek and Zhipu)
maxIterations: 5, // Max iteration rounds
maxToolCalls: 10 // Max tool calls per review
}
}
Supported configuration formats include:
.codegate.ts,.codegate.js,.codegate.json,.codegate.yaml,.codegate.yml(also supports.mjs,.cjsextensions).
No installation required. Review the latest commit (or a specific commit) directly:
npx code-gate review <commit-hash>
Or review staged file changes:
npx code-gate review
Install code-gate as a development dependency in your project:
npm i -D code-gate
Add script command in package.json:
{
"scripts": {
"review": "code-gate review"
}
}
Manually trigger reviews via script commands:
# Review staged changes
npm run review
# Review a specific commit
npm run review <commit-hash>
If you want to use the
code-gate reviewcommand directly in the command line, you can installcode-gateas a global dependency:npm i -g code-gate
The recommended way. Automatically intercepts git commit flows.
Install code-gate as a development dependency:
npm i -D code-gate
We provide a one-click initialization command to configure Git Hooks.
Automatic Init (Recommended)
# Interactive selection for Git Hooks or Husky
npx code-gate init
You can also specify arguments if you prefer a specific hook manager:
npx code-gate init -m gitnpx code-gate init -m huskyAfter initialization, you can choose to add the generated config file to
.gitignore.
Just commit your code as usual, and Code Gate will automatically start the review:
git add .
git commit -m "feat: new feature"
| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| provider | string | 'ollama' | AI Provider. Supports ollama, deepseek, openai, anthropic, aliyun, volcengine, zhipu, etc. |
| providerOptions | object | {} | Specific configurations for each Provider (see table below) |
| fileTypes | string[] | [] | List of file extensions to review (whitelist). Reviews all files if empty or undefined. |
| exclude | string[] | ['**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml'] | List of files or directories to ignore (blacklist), supports glob patterns (e.g., node_modules/**). Higher priority than fileTypes. |
| ui.openBrowser | boolean | true | Auto-open browser for report preview |
| ui.port | number | 5175 | Preview server port |
| limits.maxDiffLines | number | 10000 | Max diff lines per review. Exceeding may cause incomplete review or excessive token usage. |
| limits.maxFiles | number | 100 | Max number of files to review |
| reviewMode | string | 'files' | Review Mode: 'summary' (summary only), 'files' (file details only), 'both' (both) |
| language | string | 'en' | UI & Prompt Language. Options: 'en', 'zh-CN', 'zh-TW', 'ja', 'ko', 'de', 'fr' |
| prompt | string | ... | Universal system prompt sent to AI |
| output.dir | string | '.review-logs' | Output directory for local reports and static assets |
| agent.enabled | boolean | false | Enable Agent mode for deeper context-aware reviews (DeepSeek & Zhipu only) |
| agent.maxIterations | number | 5 | Max iteration rounds for Agent to gather context |
| agent.maxToolCalls | number | 10 | Max tool calls allowed per review session |
Each Provider supports the following fields, with request option for timeout and retry control.
Key Parameters:
baseURL: API base URL (e.g., https://api.deepseek.com or http://localhost:11434)apiKey: API Key (specified directly in config, not recommended for committing)apiKeyEnv: Environment variable name storing the API Key (Recommended, e.g., DEEPSEEK_API_KEY)model: Model name to use (e.g., deepseek-chat, qwen2.5-coder)concurrencyFiles: Number of concurrent file reviews (Recommended: Cloud API 4-8, Local Model 1)request: Advanced request configuration (see "Advanced Configuration" below)| Provider | Configurable Parameters |
| :--- | :--- |
| deepseek | baseURL, apiKey, apiKeyEnv, model, concurrencyFiles, request |
| ollama | baseURL, model, concurrencyFiles, request |
| **ope