From Multi-Model Gateways
Provides Python code and prompts for using Kimi K2 (Moonshot AI) API for deep reasoning, code review, debugging, and algorithm design.
How this skill is triggered — by the user, by Claude, or both
Slash command
/ai-gateways:kimiThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Expert skill for Kimi K2 (Moonshot AI) - specialized in deep reasoning and code analysis.
Expert skill for Kimi K2 (Moonshot AI) - specialized in deep reasoning and code analysis.
# API ключи: ~/.claude/.credentials.master.env
# Переменная: KIMI_API_KEY
KIMI_API_KEY=os.getenv('KIMI_API_KEY')
KIMI_BASE_URL=https://api.moonshot.ai/v1
KIMI_MODEL=kimi-k2-thinking
Best for:
Advantages:
pip install openai # Uses OpenAI-compatible API
from openai import OpenAI
import os
client = OpenAI(
api_key=os.getenv('KIMI_API_KEY'),
base_url=os.getenv('KIMI_BASE_URL', 'https://api.moonshot.ai/v1')
)
MODEL = os.getenv('KIMI_MODEL', 'kimi-k2-thinking')
def kimi_reason(problem: str, show_thinking: bool = True):
"""
Use Kimi K2 for complex reasoning tasks.
Args:
problem: The problem to analyze
show_thinking: Whether to include thinking process
"""
system = """You are an expert problem solver.
Think step by step and show your reasoning process.
Be thorough and consider edge cases."""
response = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "system", "content": system},
{"role": "user", "content": problem}
],
temperature=0.7,
max_tokens=8192
)
return response.choices[0].message.content
# Usage
result = kimi_reason("Design an algorithm to find the shortest path in a weighted graph with negative edges")
def kimi_code_review(code: str, language: str = "python"):
"""
Comprehensive code review with Kimi K2.
Returns:
- Bugs and issues
- Security vulnerabilities
- Performance concerns
- Best practices violations
- Improvement suggestions
"""
prompt = f"""Review this {language} code thoroughly:
```{language}
{code}
Analyze for:
Provide specific line numbers and fix suggestions."""
response = client.chat.completions.create(
model=MODEL,
messages=[{"role": "user", "content": prompt}],
temperature=0.3,
max_tokens=8192
)
return response.choices[0].message.content
review = kimi_code_review(""" def process_user(user_id): user = db.query(f"SELECT * FROM users WHERE id = {user_id}") return user """)
### Debugging Analysis
```python
def kimi_debug(error: str, code: str, context: str = ""):
"""
Analyze and fix bugs with Kimi K2.
Args:
error: Error message or description
code: Relevant code
context: Additional context (stack trace, logs)
"""
prompt = f"""Debug this issue:
**Error:**
{error}
**Code:**
{code}
**Context:**
{context}
Provide:
1. Root cause analysis
2. Step-by-step fix
3. Prevention strategy
4. Test cases to verify fix"""
response = client.chat.completions.create(
model=MODEL,
messages=[{"role": "user", "content": prompt}],
temperature=0.2,
max_tokens=8192
)
return response.choices[0].message.content
def kimi_optimize(code: str, metrics: str = ""):
"""
Analyze and optimize code performance.
Args:
code: Code to optimize
metrics: Performance metrics if available
"""
prompt = f"""Optimize this code for performance:
{code}
{f"Current metrics: {metrics}" if metrics else ""}
Analyze:
1. Time complexity - current and optimized
2. Space complexity - memory usage
3. Bottlenecks - hot paths, expensive operations
4. Caching opportunities
5. Algorithm alternatives
Provide optimized version with benchmarks."""
response = client.chat.completions.create(
model=MODEL,
messages=[{"role": "user", "content": prompt}],
temperature=0.3,
max_tokens=8192
)
return response.choices[0].message.content
def kimi_algorithm(problem: str, constraints: str = ""):
"""
Design optimal algorithm for a problem.
Args:
problem: Problem description
constraints: Time/space constraints
"""
prompt = f"""Design an algorithm for:
**Problem:**
{problem}
**Constraints:**
{constraints if constraints else "Optimize for time, then space"}
Provide:
1. Problem analysis
2. Multiple approaches with trade-offs
3. Optimal solution with complexity analysis
4. Implementation in Python
5. Test cases
6. Edge cases handling"""
response = client.chat.completions.create(
model=MODEL,
messages=[{"role": "user", "content": prompt}],
temperature=0.5,
max_tokens=8192
)
return response.choices[0].message.content
def kimi_refactor(code: str, goals: str = ""):
"""
Refactor code for better quality.
Args:
code: Code to refactor
goals: Specific refactoring goals
"""
prompt = f"""Refactor this code:
{code}
Goals: {goals if goals else "Improve readability, maintainability, and testability"}
Apply:
1. SOLID principles
2. Design patterns where appropriate
3. Clean code practices
4. Better naming conventions
5. Proper abstraction levels
Show before/after with explanations."""
response = client.chat.completions.create(
model=MODEL,
messages=[{"role": "user", "content": prompt}],
temperature=0.4,
max_tokens=8192
)
return response.choices[0].message.content
def kimi_test_strategy(code: str, requirements: str = ""):
"""
Create comprehensive testing strategy.
Args:
code: Code to test
requirements: Specific requirements
"""
prompt = f"""Create a testing strategy for:
{code}
{f"Requirements: {requirements}" if requirements else ""}
Include:
1. Unit tests - all functions and methods
2. Integration tests - component interactions
3. Edge cases - boundaries, nulls, errors
4. Performance tests - load, stress
5. Security tests - if applicable
Provide test code with assertions."""
response = client.chat.completions.create(
model=MODEL,
messages=[{"role": "user", "content": prompt}],
temperature=0.3,
max_tokens=8192
)
return response.choices[0].message.content
Kimi K2 powers these agents in agents.json:
| Agent | Use Case |
|---|---|
kimi-code-reviewer | /kimi-review path/to/file |
kimi-senior-coder | Complex implementations |
kimi-refactoring-specialist | Code improvement |
kimi-algorithm-specialist | Algorithm design |
kimi-debugging-specialist | Bug analysis |
kimi-performance-optimizer | Performance tuning |
kimi-testing-strategist | Test planning |
# Code review with Kimi
/kimi-review path/to/file
# Auto-fix issues
/kimi-fix path/to/file
# Deep reasoning
/kimi-reasoning "complex problem description"
npx claudepluginhub jhamidun/claude-code-config-pack --plugin ai-gatewaysBuilds a throwaway prototype to answer a design question about UI appearance or state/logic behavior. Guides you through two branches: interactive terminal app for logic validation, or multiple UI variations for visual exploration.