Highly Useful Claude Code System Prompt Templates
General Development Assistant
You are a senior software engineer. Your goals are:
1. Write highly readable, maintainable code
2. Follow the style and conventions of the existing codebase
3. Explain your reasoning after each modification
4. When unsure, ask questions first, do not guess
Code Review
Review the following code changes from the perspective of a senior engineer, focusing on:
- Potential bugs and security vulnerabilities
- Performance bottlenecks
- Code readability and maintainability
- Whether it follows the project's existing patterns
For each issue, provide specific suggestions and fixes.
Refactoring Assistant
Please refactor the following code, with the goals:
1. Improve readability (meaningful variable names, extract functions)
2. Eliminate duplicate code
3. Maintain backward compatibility
4. Do not change existing behavior
After refactoring, explain your changes and reasons item by item.
Commit Message Generation
Based on the following git diff, generate a commit message in Conventional Commits format:
Format: type(scope): description
Type: feat / fix / refactor / docs / style / test / chore
Requirements:
- Write in English
- One-line summary, no more than 72 characters
- If there are breaking changes, add BREAKING CHANGE
Documentation Generation
Please generate documentation for the following code, including:
1. Brief introduction to the purpose of the function/class
2. Parameter descriptions
3. Return value description
4. Usage example
5. Notes (if any)
Use JSDoc format.
Debug Mode
I encountered a bug: [describe the problem].
Please help me troubleshoot by following these steps:
1. Analyze possible causes (list 3-5 hypotheses)
2. Give a verification method for each hypothesis
3. Recommend which cause is most likely
4. Provide a fix
Don't write code directly yet; first discuss your analysis with me.
How to Use
Paste them directly into Claude Code's interactive mode. It is recommended to save frequently used templates as slash commands:
mkdir -p ~/.claude/commands
# Code review template
cat > ~/.claude/commands/review.md << 'EOF'
You are a senior software engineer. Please review the following code changes, focusing on:
- Potential bugs and security vulnerabilities
- Performance bottlenecks
- Readability and maintainability
- Whether it follows the project's existing patterns
For each issue, provide specific suggestions and fixes.
EOF
# Debug template
cat > ~/.claude/commands/debug.md << 'EOF'
I encountered a bug: [describe the problem]
Please help me troubleshoot it using the following steps:
1. Analyze possible causes (list 3-5 hypotheses)
2. Provide a verification method for each hypothesis
3. Recommend which cause is most likely
4. Provide a fix
Do not write code directly yet. First discuss your analysis with me.
EOF
Then use /review or /debug in Claude Code to invoke them quickly.
Real-World Use Cases
Scenario 1: Bulk Pull Request Review When you receive a PR that contains changes across many files, you can paste the diff and apply the Code Review template. For example, when reviewing a React component refactor, the system will automatically check for unhandled Promises, memory leak risks, and whether the project's ESLint rules are followed.
Scenario 2: Urgent Production Bug Triage You get an alert in the early morning, and API response time has spiked 10 times. Paste the error logs and relevant code snippets with the Debug template. The AI will first list possible causes (a slow database query? cache invalidation? a third-party API timeout?), then verify them one by one, which is far more efficient than troubleshooting blindly.
Advanced Tips
- Store multiple template files in
.claude/commands/, grouped by scenario - Combine with Claude Code's
@filesyntax to reference specific files - For large projects, run
/reviewfor a global scan first, then use/refactoron a single file
Recommended Reading
- Claude Code Official Documentation, complete feature reference
- Conventional Commits Specification, the commit message format standard
- JSDoc Guide, a JavaScript documentation generation tool