Claude Code Custom Commands
Claude Code Custom Commands Guide
Claude Code supports custom slash commands that let you quickly run common operations. This chapter covers practical commands and how to use them.
What Are Custom Commands
Custom commands are Markdown files stored in .claude/commands/. You invoke them with /<command-name>.
Command File Structure
---
description: Command description (shown in command list)
argument-hint: [parameter hint]
allowed-tools: Read, Edit, Bash(git:*)
---
# Command Title
This is the command's prompt content...
Use $ARGUMENTS to reference user-provided arguments
Command File Location
.claude/
└── commands/
├── think-harder.md
├── reflection.md
└── gh/
├── review-pr.md
└── fix-issue.md
Analysis & Thinking Commands
/think-harder - Enhanced Deep Analysis
For deep analysis of complex problems.
Usage:
/think-harder How should I design a high-concurrency order system?
Core flow:
- Problem clarification - Define core problem, identify hidden assumptions
- Multi-dimensional analysis
- Structural decomposition: break into base components and dependencies
- Stakeholder perspectives: consider all affected parties
- Temporal analysis: short-term vs long-term impact
- Causal reasoning: map cause-effect chains and feedback loops
- Critical evaluation - Challenge assumptions, identify cognitive biases
- Synthesis - Connect cross-domain insights
Output format:
- Problem reframe
- Key insights
- Reasoning chain
- Alternative approaches
- Uncertainties
- Actionable recommendations
/think-ultra - Ultra-Deep Analysis
A deeper pass than /think-harder. For extremely complex problems.
Usage:
/think-ultra How would you build an AI programming assistant from scratch?
/reflection - Instruction Reflection
Analyzes the current session and improves instructions in CLAUDE.md.
Usage:
/reflection
Core flow:
- Analysis phase - Review conversation history, check current CLAUDE.md
- Identify issues
- Inconsistencies in Claude's responses
- Misunderstandings of user requests
- Areas where more detail could help
- Interactive phase - Suggest improvements, wait for confirmation
- Implementation phase - Modify CLAUDE.md
Best practices:
- Use TodoWrite to track analysis progress
- Read current CLAUDE.md thoroughly before modifying
- Consider edge cases and common scenarios
/reflection-harder - Deep Session Analysis
End-to-end analysis of the entire session, capturing learnings and improvement points.
Usage:
/reflection-harder
/eureka - Record Technical Breakthroughs
Use this when you have an important technical insight worth saving.
Usage:
/eureka Discovered that React 18 Suspense perfectly solves the data-fetching waterfall problem
GitHub Integration Commands
/gh:review-pr - PR Code Review
Auto-fetches PR details and runs a code review.
Usage:
/gh:review-pr 123
Core flow:
- Fetch PR details:
gh pr view 123 - Get code diff:
gh pr diff 123 - Analyze changes and provide review feedback
- Post comments directly on GitHub
Review focus:
- Code correctness
- Project convention compliance
- Performance impact
- Test coverage
- Security considerations
Comment format:
# Get commit ID
gh api repos/OWNER/REPO/pulls/123 --jq '.head.sha'
# Post comment
gh api repos/OWNER/REPO/pulls/123/comments \
--method POST \
--field body="Suggestion: consider using useMemo here for optimization" \
--field commit_id="abc123" \
--field path="src/components/List.tsx" \
--field line=42 \
--field side="RIGHT"
/gh:fix-issue - Issue Fix Workflow
Complete Issue fix workflow.
Usage:
/gh:fix-issue 456
Core flow:
- Fetch Issue details
- Analyze root cause
- Create fix branch
- Implement fix
- Create PR linked to Issue
Utility Commands
/translate - Technical Translation
Translates English/Japanese technical content to Chinese.
Usage:
/translate This article explains the fundamentals of RAG...
Features:
- Preserves technical terms
- Maintains code formatting
- Proper technical expression in the target language
/cc:create-command - Create New Command
Quickly creates a new custom command.
Usage:
/cc:create-command deploy "Automated deployment to production"
Creating Your Own Commands
Step 1: Create the Command File
mkdir -p .claude/commands
touch .claude/commands/my-command.md
Step 2: Write the Command Content
---
description: My custom command description
argument-hint: [parameter description]
allowed-tools: Read, Write, Bash
---
# Command Title
You are a professional [role].
## Task
Based on the user's $ARGUMENTS, perform the following:
1. Step one
2. Step two
3. Step three
## Output Format
- Use clear headings
- Provide specific recommendations
Step 3: Use the Command
/my-command argument content
Command Config Parameters
| Parameter | Description | Example |
|---|---|---|
description | Command description | "Code review command" |
argument-hint | Parameter hint | "[pr-number]" |
allowed-tools | Allowed tools | "Read, Edit, Bash(git:*)" |
Common allowed-tools Values
Read- Read filesWrite- Write filesEdit- Edit filesGlob- File searchGrep- Content searchBash- Execute commandsBash(git:*)- Git commands onlyBash(gh:*)- gh commands onlyTodoWrite- Task managementWebFetch- Web fetching
Best Practices
- Name clearly - command name should directly express the function
- Describe accurately - description should be instantly understandable
- Limit tools - use allowed-tools to restrict permissions
- Structured output - define a clear output format
- Error handling - consider edge cases
Recommended Command Set
| Command | Purpose | Scenario |
|---|---|---|
/think-harder | Deep analysis | Complex problem analysis |
/reflection | Instruction tuning | Improving CLAUDE.md |
/gh:review-pr | PR review | Code review |
/gh:fix-issue | Issue fix | Bug fixing |
/translate | Tech translation | Document translation |
Reference: feiskyer/claude-code-settings
📚 相关资源
❓ 常见问题
关于本章主题最常被搜索的问题,点击展开答案
Claude Code 自定义命令文件应该放在哪里?
项目级放 `.claude/commands/`,跟 repo 走团队共用;可以分子目录组织,比如 `gh/review-pr.md` 用 `/gh:review-pr` 调用。每个文件是一个 Markdown,frontmatter 写 `description` / `argument-hint` / `allowed-tools`,正文是 Prompt 内容,用 `$ARGUMENTS` 引用用户传参。
/think-harder 和 /think-ultra 区别在哪?
都是深度分析命令,但 think-harder 走 4 步流程(问题澄清 → 多维分析 → 批判性评估 → 综合整合),适合"高并发订单系统怎么设计"这种有边界的复杂问题;think-ultra 是 think-harder 的 plus 版,分析维度更全,适合"从零构建 AI 编程助手"这类极复杂、需要跨领域综合的开放问题。日常 80% 场景 think-harder 够用。
/reflection 命令到底改的是什么?
改 CLAUDE.md。它会复盘当前对话,找出 3 类问题:(1) Claude 响应不一致;(2) 对你请求的误解;(3) 信息可以更详细的地方。然后提出修改建议给你确认,confirmed 后直接动 CLAUDE.md。比 `/reflection-harder`(综合分析整个会话)轻量,每次完成一个 task 后跑一次最划算。
allowed-tools 里 `Bash(git:*)` 是什么意思?
范围权限,只允许跑 git 子命令(git status / git diff / git commit 等),其他 bash 命令一律拒绝。比直接给 `Bash` 安全很多 — 防止 AI 误删文件 / 起服务 / 改系统配置。常见组合:`Bash(git:*)` 用于 commit 命令,`Bash(gh:*)` 用于 GitHub Issue/PR 命令,`Read,Edit` 加上去就够覆盖大部分编辑场景。
/gh:review-pr 命令是怎么把评论发到 GitHub 的?
4 步:(1) `gh pr view 123` 拿 PR 详情;(2) `gh pr diff 123` 拿代码差异;(3) AI 分析变更生成审查意见;(4) `gh api repos/OWNER/REPO/pulls/123/comments --method POST --field body="..." --field commit_id="abc123" --field path="src/x.ts" --field line=42 --field side="RIGHT"` 直接发评论。commit_id 用 `gh api repos/.../pulls/123 --jq '.head.sha'` 拿到。