π AI-powered code review using Kimi (Moonshot AI)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GitHub β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β PR Events β PR Comments β Inline Comments β β
β β β /review β /ask β β
β β β /ask β β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GitHub Actions (Docker) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β main.py β β
β β Event Router: PR events β /review, /ask commands β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Tools Layer β β
β β β β
β β ββββββββββββ ββββββββββββ β β
β β β Reviewer β β Ask β β β
β β β /review β β /ask β β β
β β ββββββ¬ββββββ ββββββ¬ββββββ β β
β β ββββββββββββ¬βββββββββββββββ β β
β β βΌ β β
β β ββββββββββββββββββ β β
β β β BaseTool β β β
β β β β’ clone_repo β β β
β β β β’ run_agent β β β
β β β β’ get_skill β β β
β β ββββββββββββββββββ β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β SkillManager β β
β β Load SKILL.md and set skills_dir for Agent SDK β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β ββββββββββββββββββββββ΄βββββββββββββββββββββ β
β βΌ βΌ β
β ββββββββββββββββββββ ββββββββββββββββββββ β
β β Kimi Agent SDK β β GitHub API β β
β β (kimi-k2.5) β β (REST) β β
β β β β β β
β β β’ Auto token mgmtβ β β’ Get PR diff β β
β β β’ Script exec β β β’ Post comments β β
β β β’ Context mgmt β β β’ Get PR info β β
β β β’ Markdown outputβ β β β
β ββββββββββββββββββββ ββββββββββββββββββββ β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- π
/review- Comprehensive code review of all PR changes - π¬
/ask- Interactive Q&A about the PR or specific code - π§ Agent Skills - Modular capability extension with custom review rules
- π Multi-language support (English/Chinese)
- βοΈ Configurable review strictness
- π― Direct Markdown Output - Clean, readable reviews powered by Agent SDK
- π Simplified Architecture - Agent SDK handles all context and token management
- Visit Moonshot AI Platform
- Register/Login
- Go to "API Key Management"
- Click "Create API Key"
- Copy the generated API Key
- Go to your GitHub repository
- Click
SettingsβSecrets and variablesβActions - Click
New repository secret - Add
KIMI_API_KEYwith the API Key from step 1 - (Optional) Add
KIMI_BASE_URLif using a custom API endpoint (defaults tohttps://api.moonshot.cn/v1)
# .github/workflows/kimi-review.yml
name: Kimi Code Review
on:
pull_request:
types: [opened, synchronize, reopened]
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
permissions:
contents: read
pull-requests: write
jobs:
kimi-review:
runs-on: ubuntu-latest
if: |
github.event_name == 'pull_request' ||
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/')) ||
(github.event_name == 'pull_request_review_comment' &&
startsWith(github.event.comment.body, '/'))
steps:
- name: Get PR ref (for comments)
id: get-pr
if: github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment'
uses: actions/github-script@v7
with:
script: |
const prNumber = context.issue?.number || context.payload.pull_request?.number;
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
core.setOutput('ref', pr.data.head.ref);
core.setOutput('sha', pr.data.head.sha);
- uses: actions/checkout@v4
with:
ref: ${{ (github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment') && steps.get-pr.outputs.ref || github.head_ref }}
- uses: xiaoju111a/kimi-actions@main
with:
kimi_api_key: ${{ secrets.KIMI_API_KEY }}
kimi_base_url: ${{ secrets.KIMI_BASE_URL }} # Optional
github_token: ${{ secrets.GITHUB_TOKEN }}
auto_review: 'false' # Use /review command insteadUse these commands in PR comments:
| Command | Description | Usage Location |
|---|---|---|
/review |
Comprehensive code review of all PR changes | PR comment area |
/ask <question> |
Q&A about the PR or specific code | PR comment area or Files changed tab (inline) |
/help |
Show help message | PR comment area |
π‘ Using /ask for code-specific questions:
- In PR comment area: Ask general questions about the entire PR
- In Files changed tab: Click the + button next to a line of code, then use
/ask <question>to ask about that specific code
π Avoiding Duplicate Reviews:
- The bot tracks the last reviewed commit SHA
- If you run
/reviewagain without new commits, it will show "β No new changes since last review" - This prevents wasting tokens on unchanged code
- uses: xiaoju111a/kimi-actions@main
with:
# Required
kimi_api_key: ${{ secrets.KIMI_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
# Optional
kimi_base_url: ${{ secrets.KIMI_BASE_URL }} # Custom API endpoint (optional, defaults to https://api.moonshot.cn/v1)
language: 'en-US' # Response language: zh-CN, en-US
model: 'kimi-k2.5' # Kimi model (default: kimi-k2.5)
review_level: 'normal' # Review strictness: strict, normal, gentle
max_files: '50' # Max files to review
exclude_patterns: '*.lock,*.min.js' # File patterns to exclude
auto_review: 'false' # Auto review on PR open (default: false, use /review command instead)Create .kimi-config.yml in your repo root to customize behavior:
# Category toggles
categories:
bug: true
performance: true
security: true
# Replace built-in skills with custom ones
skill_overrides:
code-review: my-company-review
# Ignore files
ignore_files:
- "*.test.ts"
- "**/__mocks__/**"
# Extra instructions
extra_instructions: |
Focus on security issues.Create .kimi/skills/ directory in your repo, each skill is a folder:
.kimi/skills/
βββ react-review/
β βββ SKILL.md # Required: core instructions
β βββ scripts/ # Optional: executable scripts
β β βββ check_hooks.py
β βββ references/ # Optional: reference documents
β βββ hooks-rules.md
βββ company-rules/
βββ SKILL.md
SKILL.md format:
---
name: react-review
description: React code review expert
triggers:
- react
- jsx
- hooks
---
# React Review Focus
## Hooks Rules
- Hooks can only be called at the top level of function components
- Cannot call Hooks inside conditionals
## Performance
- Check if useMemo/useCallback is neededSkills are automatically triggered based on PR code content.
| Model | Context | Notes |
|---|---|---|
kimi-k2.5 |
256K | Default, latest model with best performance |
kimi-k2-thinking-turbo |
256K | Faster thinking model |
kimi-k2-thinking |
256K | More thorough reasoning, slower |
All commands use Kimi Agent SDK with kimi-k2.5 model by default.
The Agent SDK automatically handles large PRs with its 256K context window.
| Category | Description | Examples |
|---|---|---|
| Bug | Code defects | Unhandled exceptions, null pointers, logic errors |
| Security | Security vulnerabilities | SQL injection, XSS, auth flaws |
| Performance | Performance issues | O(nΒ²) algorithms, N+1 queries |
kimi-actions/
βββ action.yml # GitHub Action definition
βββ Dockerfile # Docker container config
βββ requirements.txt # Python dependencies
βββ tests/ # Unit tests (115 tests)
βββ src/
βββ main.py # Entry point, event routing
βββ action_config.py # Action config (env vars)
βββ repo_config.py # Repo config (.kimi-config.yml)
βββ github_client.py # GitHub API client
βββ skill_loader.py # Skill loading/management
βββ tools/ # Command implementations (Agent SDK)
β βββ base.py # Base class (common functionality)
β βββ reviewer.py # /review - Code review
β βββ ask.py # /ask - Q&A
βββ skills/ # Built-in Skills
βββ code-review/
β βββ SKILL.md # Review instructions
β βββ references/ # Reference documents
βββ ask/
βββ SKILL.md
| Component | Purpose | Notes |
|---|---|---|
| skill_loader.py | Manage skills | Load SKILL.md, set skills_dir for Agent SDK |
| base.py | Common tool functionality | Repo cloning, Agent SDK execution |
| Agent SDK | LLM execution | Automatic token management, script execution, context handling, direct Markdown output |
Visit Moonshot AI Platform, register and create an API Key in the management page. New users get free credits.
Yes. Just ensure GITHUB_TOKEN has permission to read repository contents.
The Kimi Agent SDK automatically handles large PRs:
- 256K token context window: Can handle very large PRs
- Automatic context management: SDK intelligently manages what to include
- Smart file filtering: Excludes binary files, lock files, minified files
No manual chunking needed - the Agent SDK handles everything automatically.
Kimi Agent SDK is an intelligent agent framework that:
- Automatic token management: No need to manually count tokens or manage context
- Dynamic script execution: Automatically calls skill scripts when needed
- Built-in tools: Provides file operations (read/write) and bash execution
- Context optimization: Intelligently manages conversation context
This allows the action to focus on what to review (skills, rules) rather than how to execute (token counting, script running).
Skills define what the agent should do:
- SKILL.md contains instructions for the agent
- scripts/ contains executable tools (Python scripts)
- Agent SDK automatically calls scripts when needed based on instructions
Example flow:
1. Load skill: code-review
2. Pass skills_dir to Agent SDK
3. Agent reads SKILL.md instructions
4. Agent automatically calls scripts/check_security.py when analyzing code
5. Agent generates review based on script output + instructions
Create .kimi-config.yml in your repo root, or add custom Skills in .kimi/skills/ directory. See Configuration section above.
If you're using a proxy or custom Kimi API endpoint, add KIMI_BASE_URL to your repository secrets:
- Go to
SettingsβSecrets and variablesβActions - Click
New repository secret - Add
KIMI_BASE_URLwith your custom endpoint (e.g.,https://your-proxy.example.com/v1)
Then use it in your workflow:
- uses: xiaoju111a/kimi-actions@main
with:
kimi_api_key: ${{ secrets.KIMI_API_KEY }}
kimi_base_url: ${{ secrets.KIMI_BASE_URL }} # Custom endpoint from secrets
github_token: ${{ secrets.GITHUB_TOKEN }}Note: If KIMI_BASE_URL is not set, it defaults to https://api.moonshot.cn/v1.
This is useful for:
- Using a corporate proxy
- Testing with a local development server
- Using alternative API gateways
- Keeping endpoint URLs private
- Moonshot AI - Kimi LLM
- Kimi Agent SDK - Agent framework
- pr-agent - Architecture reference
- kimi-cli - Kimi CLI tool
- kodus-ai - AI code review reference
MIT