高质量 Slash Commands 全集
以下是一套完整的全局 Slash Commands,你可以直接让 Claude Code 帮你设置:
🔍 代码审查类
/code-review
# Code Review
You are a senior software engineer conducting a thorough code review.
## Focus Areas
- Security vulnerabilities (SQL injection, XSS, CSRF, etc.)
- Performance bottlenecks and optimization opportunities
- Code readability and maintainability
- SOLID principles and design patterns
- Error handling and edge cases
- Memory leaks and resource management
## Output Format
1. **Critical Issues** (must fix)
2. **Warnings** (should fix)
3. **Suggestions** (nice to have)
For each issue, provide:
- Specific line reference
- Problem description
- Suggested fix with code example
/security-audit
# Security Audit
Perform a comprehensive security audit of this code.
## Check For
- Input validation and sanitization
- Authentication/Authorization flaws
- Sensitive data exposure
- SQL/NoSQL injection
- XSS vulnerabilities
- CSRF vulnerabilities
- Insecure dependencies
- Hardcoded secrets/credentials
- Improper error handling that leaks info
## Output
Rate severity: 🔴 Critical | 🟠 High | 🟡 Medium | 🟢 Low
Provide remediation code for each finding.
🐛 调试类
/debug
# Debug Issue
You are an expert debugger. Help me systematically debug this issue.
## Process
1. **Understand**: What is the expected vs actual behavior?
2. **Reproduce**: Identify steps to reproduce
3. **Isolate**: Narrow down the problem area
4. **Analyze**: Check logs, stack traces, and state
5. **Hypothesize**: List possible root causes
6. **Test**: Suggest diagnostic code/commands
7. **Fix**: Provide solution with explanation
## Output
- Root cause analysis
- Step-by-step fix
- Prevention strategies
/explain-error
# Explain Error
Explain this error message in simple terms.
## Provide
1. What the error means (plain English)
2. Common causes of this error
3. How to fix it (with code examples)
4. How to prevent it in the future
Keep explanations clear and beginner-friendly while being technically accurate.
/trace-bug
# Trace Bug
Help me trace through the code execution path to find a bug.
## Steps
1. Map out the data flow from input to output
2. Identify all functions/methods involved
3. List assumptions made at each step
4. Find where assumptions might break
5. Suggest strategic console.log/breakpoint locations
6. Provide debugging script if applicable
✨ 重构类
/refactor
# Refactor Code
Refactor this code for better quality.
## Goals
- Improve readability
- Reduce complexity (lower cyclomatic complexity)
- Apply DRY principle
- Follow SOLID principles
- Use appropriate design patterns
- Improve naming conventions
## Output Format
1. Current issues identified
2. Refactored code
3. Explanation of changes
4. Before/After comparison of key metrics
Preserve all existing functionality and behavior.
/optimize
# Optimize Performance
Analyze and optimize this code for performance.
## Analysis Areas
- Time complexity (Big O)
- Space complexity
- Database query efficiency
- Network call optimization
- Caching opportunities
- Lazy loading possibilities
- Memory management
## Output
1. Current performance bottlenecks
2. Optimized code with benchmarks
3. Trade-offs of optimization
4. Estimated improvement percentage
/simplify
# Simplify Code
Make this code simpler and more elegant.
## Guidelines
- Reduce lines of code without sacrificing readability
- Use modern language features appropriately
- Remove unnecessary abstractions
- Consolidate duplicate logic
- Use built-in functions over custom implementations
Show before/after with explanation.
📝 文档类
/document
# Generate Documentation
Create comprehensive documentation for this code.
## Include
- Overview/Purpose
- Installation/Setup (if applicable)
- API Reference with parameters and return types
- Usage examples
- Error handling
- Edge cases and limitations
## Style
- Use JSDoc/TSDoc/docstring format as appropriate
- Include TypeScript types if applicable
- Add inline comments for complex logic
/readme
# Generate README
Create a professional README.md for this project.
## Sections
1. Project Title & Badges
2. Description (what & why)
3. Features
4. Quick Start / Installation
5. Usage with examples
6. Configuration options
7. API Reference (if applicable)
8. Contributing guidelines
9. License
10. Contact/Support
Make it scannable with good formatting.
/changelog
# Generate Changelog
Create a changelog entry for recent changes.
## Format (Keep a Changelog)
### [Version] - YYYY-MM-DD
#### Added
#### Changed
#### Deprecated
#### Removed
#### Fixed
#### Security
Be specific and user-focused in descriptions.
🧪 测试类
/write-tests
# Write Tests
Write comprehensive tests for this code.
## Coverage Goals
- Happy path scenarios
- Edge cases
- Error conditions
- Boundary values
- Null/undefined handling
## Output
- Unit tests with clear descriptions
- Use appropriate testing framework (Jest/Mocha/Pytest/etc.)
- Include setup/teardown if needed
- Add comments explaining test purpose
- Aim for high coverage
/test-cases
# Generate Test Cases
Generate test cases for this feature/function.
## Include
- Input/Output pairs
- Boundary conditions
- Invalid inputs
- Performance edge cases
- Concurrency scenarios (if applicable)
## Format
| Test Case | Input | Expected Output | Notes |
|-----------|-------|-----------------|-------|
Then provide implementation code.
/mock-data
# Generate Mock Data
Create realistic mock data for testing.
## Requirements
- Match the data schema exactly
- Include edge cases (empty, null, max length)
- Generate enough variety for thorough testing
- Make data realistic and consistent
- Include timestamps in proper format
Provide as JSON and as factory functions if applicable.
🚀 Git/PR 类
/commit
# Generate Commit Message
Create a conventional commit message for these changes.
## Format
<type>(<scope>): <subject>
<body>
<footer>
## Types
feat | fix | docs | style | refactor | perf | test | chore | ci
## Rules
- Subject: imperative, lowercase, no period, <50 chars
- Body: explain what and why (not how)
- Footer: reference issues (Fixes #123)
/create-pr
# Create Pull Request
Create a well-structured pull request description.
## Template
### Summary
Brief description of changes
### Motivation
Why these changes are needed
### Changes Made
- List of specific changes
### Testing Done
How changes were tested
### Screenshots (if UI changes)
### Checklist
- [ ] Tests added/updated
- [ ] Documentation updated
- [ ] No breaking changes (or documented)
- [ ] Self-reviewed code
/release-notes
# Generate Release Notes
Create user-friendly release notes.
## Format
## What's New in v[X.X.X]
### ✨ New Features
### 🐛 Bug Fixes
### ⚡ Performance Improvements
### 🔧 Other Changes
### Breaking Changes ⚠️
### Upgrade Guide
Write for end-users, not developers.
🏗️ 架构类
/architecture
# Architecture Review
Analyze the architecture of this code/system.
## Evaluate
- Component responsibilities (SRP)
- Coupling and cohesion
- Dependency management
- Scalability considerations
- Testability
- Maintainability
## Output
1. Architecture diagram (Mermaid)
2. Strengths
3. Weaknesses
4. Improvement recommendations
5. Migration strategy if major changes needed
/design-pattern
# Suggest Design Pattern
Analyze this code and suggest appropriate design patterns.
## Process
1. Identify the problem/smell
2. Suggest applicable patterns
3. Explain why each pattern fits
4. Show implementation example
5. Discuss trade-offs
Common patterns to consider:
Factory, Strategy, Observer, Decorator, Adapter, Facade, Repository, etc.
/api-design
# API Design Review
Review or design a RESTful/GraphQL API.
## Evaluate
- RESTful principles / GraphQL best practices
- Naming conventions
- HTTP methods/status codes
- Request/Response structure
- Pagination, filtering, sorting
- Versioning strategy
- Error handling format
- Authentication/Authorization
## Output
OpenAPI spec or GraphQL schema with examples.
💾 数据库类
/optimize-query
# Optimize SQL Query
Analyze and optimize this database query.
## Check For
- Missing indexes
- N+1 problems
- Unnecessary joins
- Subquery optimization
- Query plan analysis
- Pagination efficiency
## Output
1. Explain current query execution
2. Optimized query
3. Suggested indexes
4. Expected performance improvement
/schema-review
# Database Schema Review
Review this database schema design.
## Evaluate
- Normalization level
- Index strategy
- Foreign key relationships
- Data types appropriateness
- Naming conventions
- Scalability considerations
## Output
- Schema diagram (Mermaid ERD)
- Issues found
- Recommendations
- Migration scripts if changes needed
🔄 转换类
/convert
# Convert Code
Convert this code to the specified language/framework.
## Guidelines
- Maintain exact functionality
- Use idiomatic patterns of target language
- Preserve comments and documentation
- Handle language-specific features appropriately
- Note any features that don't translate directly
Output clean, production-ready code.
/modernize
# Modernize Code
Update this code to use modern language features and best practices.
## Goals
- Use latest stable language features
- Replace deprecated APIs
- Apply current best practices
- Improve type safety
- Use modern tooling patterns
Explain each modernization applied.
📊 分析类
/complexity
# Analyze Complexity
Analyze the complexity of this code.
## Metrics
- Cyclomatic complexity
- Cognitive complexity
- Lines of code
- Dependency count
- Nesting depth
## Output
- Complexity scores
- Problem areas highlighted
- Refactoring suggestions
- Complexity reduction priority list
/dependencies
# Analyze Dependencies
Analyze the dependencies in this project/file.
## Check For
- Outdated packages
- Security vulnerabilities
- Unused dependencies
- Duplicate dependencies
- Bundle size impact
- License compatibility
## Output
- Dependency tree visualization
- Upgrade recommendations
- Security alerts
- Cleanup suggestions
🛠️ 实用工具类
/explain
# Explain Code
Explain this code in detail.
## Include
1. High-level overview (what it does)
2. Step-by-step walkthrough
3. Key concepts used
4. Why it's written this way
5. Potential gotchas
Adjust explanation depth based on code complexity.
Use analogies where helpful.
/fix
# Quick Fix
Fix this code issue quickly.
## Process
1. Identify the problem
2. Provide the fix
3. Brief explanation
Keep it concise and actionable.
Just give me working code.
/improve
# Improve Code
Suggest improvements for this code.
## Categories
- Readability
- Performance
- Security
- Maintainability
- Testing
Rate each suggestion by impact and effort.
Provide code for top 3 improvements.
/todo
# Find TODOs
Find and organize all TODOs, FIXMEs, and HACKs in this code.
## Output
| Priority | Type | Location | Description | Suggested Action |
|----------|------|----------|-------------|------------------|
Group by priority: 🔴 High | 🟡 Medium | 🟢 Low
🎯 快速使用指令
让 Claude Code 执行这个命令来设置:
请帮我创建一个全局 Slash Commands 配置。将以上所有命令保存为独立的 .md 文件,放在 ~/.claude/commands/ 目录下(或 Claude Code 的全局命令目录)。
文件命名规则:
- /code-review → code-review.md
- /debug → debug.md
- 以此类推
每个文件只包含命令内容,不需要文件名标题。
本文档为站内渲染。原始文件本地路径:saas/source/knowledge-ai/Knowledge-AI-Newsletter-md-slash-debad7.md(仅本地保留,不入库不部署)