iTranslated by AI
The Complete Guide to Claude Code Custom Commands: Boosting Development Efficiency with Automation
Complete Guide to Claude Code Custom Commands: From Basics to Practice, Automation Techniques to Dramatically Improve Development Efficiency
Hello, this is Tomada.
Have you ever found yourself writing the same instructions over and over in Claude Code and thought, "Could I make this more efficient?"
Actually, Claude Code has a powerful feature called "Custom Commands."
You can register frequently used instructions as short commands, which can significantly streamline your development workflow.
In this article, I will systematically explain practical ways to use them, from the basic mechanism of custom commands to automating quality checks and improving development workflows through GitHub integration.
Summary for Busy People
- You can create your own commands just by placing Markdown files in
.claude/commands/. - Use quality check commands to discover and fix review points in advance.
- Automate everything from issue-driven development to PR review responses by integrating with GitHub CLI.
- Customize per project to improve the development efficiency of the entire team.
- Reduce costs by discovering problems early through checks immediately after implementation.
What are Custom Commands?
Custom commands are a feature that allows you to register frequently used instructions as short commands.
To put it in everyday terms, it's like "Shortcuts" on a smartphone.
It's like that thing where just by saying "Good morning," you can automate a series of actions like reading the weather forecast, checking today's schedule, and displaying the news.
Similarly, Claude Code's custom commands allow you to execute complex instructions with simple commands.
If you want to learn the basics of custom commands in detail, I explain them in another article.
What are Claude Code Custom Commands? Introduction to Creating Slash Commands
The Mechanism is Very Simple
The mechanism of custom commands is very simple.
Just place a Markdown file in a directory called .claude/commands/.
The filename becomes the command name, and the content of the file becomes the instructions to be executed.
For example, if you create a file named .claude/commands/hello.md, you will be able to use the /hello command.
It's really that simple.
Anyone who can create a text file can create a custom command, even without programming knowledge.
Also, if you place it in ~/.claude/commands/ in your home directory, it can be used as a common command across all projects.
Let's Actually Create One
Now, let's actually create a custom command.
First, we'll start with something simple.
Prepare the Directory for Commands
Run the following command in the root directory of your project:
mkdir -p .claude/commands
Now you have a place to put your custom commands.
Create Your First Custom Command
Now, let's create a command to have the project overview explained.
Create a file named .claude/commands/explain.md and write the following content:
Please explain this project from the following perspectives:
- Main features
- Technologies used
- Directory structure
- Important files
Explain concisely so that even someone seeing it for the first time can understand.
With this, the preparation is complete.
Start Claude Code and try entering /explain.
It should automatically explain the project overview.
claude
/explain
Performance Optimization
Now, let's create a slightly more practical command.
This is a command to check for common performance issues.
.claude/commands/performance-check.md:
Please analyze the performance of the current implementation and suggest improvements.
## Check Items
### Frontend
- Is unnecessary re-rendering occurring?
- Are heavy calculations properly memoized?
- Room for optimization of images and assets
- Impact on bundle size
- Room for utilizing lazy loading
### Backend
- Room for database query optimization (N+1 problems, etc.)
- Possibility of utilizing cache
- Proper use of asynchronous processing
- Possibility of memory leaks
Please propose improvement plans by considering the balance between implementation difficulty and effectiveness.
When I ran this command in a certain React project, I received a suggestion stating, "You are creating a new object every time inside the array's map method."
It suggested that performance could be improved by using useMemo for memoization.
Since these kinds of subtle problems are hard to notice yourself, these check commands are extremely helpful.
However, because this checks a very broad range, in practice, people often create more specific commands.
Next, I will introduce an example of a dynamic command using arguments.
Dynamic Commands Using Arguments
Custom commands can also receive arguments at runtime.
By using the special variable $ARGUMENTS, you can pass values when executing the command.
I explain how to handle arguments in detail in another article.
How to Receive Arguments Using $ARGUMENTS in Claude Code Custom Commands
Generating Tests for Specific Files
Creating test code is important, but it is a time-consuming task.
Let's create a command to generate tests by specifying a specific file.
.claude/commands/test-file.md:
Please generate comprehensive test code for the file in $ARGUMENTS.
Create tests from the following perspectives:
## Test Case Design
- Normal case: Verification of behavior with expected input
- Abnormal case: Error cases and edge cases
- Boundary values: Maximum, minimum, empty values, etc.
## Test Structure
- Group test cases for each function/method
- Clearly describe preconditions and expected results
- Set up mocks appropriately if needed
## Quality Standards
- Aim for 80% or higher coverage
- Make the test code easy to maintain
- Efficient tests considering execution time
Please comply with the test framework used in the project.
Usage:
/test-file src/utils/validator.ts
This will generate test code specifically for the designated file.
Requirements Definition Support Command
Before implementing a new feature, it is important to organize the requirements.
Let's create a command to create a requirements definition from an idea.
.claude/commands/requirements.md:
Please create a detailed requirements definition for the feature "$ARGUMENTS".
## Content of Requirements Definition
### 1. Feature Overview
- Purpose and value proposition
- User stories
- Success criteria
### 2. Functional Requirements
- Must Have
- Nice to Have
- Future Enhancement
### 3. Non-Functional Requirements
- Performance standards
- Security requirements
- Usability requirements
### 4. Technical Considerations
- Impact on existing systems
- Required tech stack
- Data model design
### 5. Implementation Plan
- Proposal for phase division
- Estimated man-hours
- Risks and countermeasures
Please consider the balance between business value and technical feasibility.
Usage:
/requirements User Notification System
With this command, you can turn a vague idea into specific requirements.
Practical Commands for Quality Improvement
While Claude Code has added built-in commands such as /review and /security-review, custom commands tailored to project-specific needs are also important.
For a general overview of Claude Code commands, including built-in ones, I explain them in detail in another article.
List of Basic Claude Code Commands: Major Commands Used Daily
Component Generation Command
In frontend development, quickly creating component templates leads to better efficiency.
.claude/commands/component.md:
Please generate a React component named "$ARGUMENTS".
## Generated Content
1. Component Body
- Type definitions in TypeScript
- Definition of Props interface
- Basic styling
2. Test File
- Basic rendering test
- Test for passing Props
3. Story for Storybook (if being used)
4. Documentation of usage examples
Please follow the project's coding conventions and directory structure.
API Design Command
In backend development, it is important to standardize API design.
.claude/commands/api-design.md:
Please design a REST API related to "$ARGUMENTS".
## Design Content
### Endpoint Design
- URL design for CRUD operations
- Selection of HTTP methods
- Definition of query parameters
### Request/Response
- JSON Schema definition
- Validation rules
- Format of error responses
### API Specification
- Description in OpenAPI format
- Usage examples (curl commands)
- Considerations for authentication/authorization
Follow RESTful design principles and consider future extensibility.
Refactoring Proposals
Commands that provide suggestions for improving existing code are also useful.
.claude/commands/refactor.md:
Please analyze the current code and provide refactoring proposals.
## Analysis Perspectives
### Areas requiring particular improvement
- Duplicate code
- Methods that are too long
- Overly complex conditional branching
- Inappropriate naming
### Application of Design Patterns
- Applicable design patterns
- Compliance with SOLID principles
- Achieving loose coupling and high cohesion
### Specific Improvement Steps
1. Prioritized improvement list
2. Scope of impact for each improvement
3. Step-by-step implementation approach
Please make proposals that improve code quality while minimizing breaking changes.
Advanced: Automating Development Workflows with GitHub Integration
As a slightly more advanced usage, you can significantly improve development efficiency by integrating GitHub CLI with Claude Code.
GitHub CLI is a tool that allows you to operate GitHub features from the command line.
I would like to introduce this combination because it has considerably boosted efficiency, especially in professional practice.
Claude Code and GitHub integration in general is explained in detail in another article.
Explaining Claude Code Best Practices Published by Anthropic for Beginners
Preparation: GitHub CLI Setup
First, install the GitHub CLI and complete the authentication.
# macOS
brew install gh
# Windows (winget)
winget install --id GitHub.cli
Authentication settings:
gh auth login
Automating Issue-Driven Development
.claude/commands/issue-start.md:
Review the content of GitHub Issue #$ARGUMENTS and start the implementation.
Proceed with the following steps:
1. Load the Issue content
```bash
gh issue view $ARGUMENTS
-
Organize requirements and completion criteria
-
Propose implementation strategy
-
Create a step-by-step implementation plan
-
Start implementation
Accurately understand the requirements written in the Issue and implement them thoroughly.
Usage:
```bash
/issue-start 123
With this, Claude Code will automatically read the content of Issue #123 and begin implementation.
Responding to Review Comments
This is my personal favorite custom command.
.claude/commands/pr-review-respond.md:
Check unresolved review comments for PR #$ARGUMENTS using the GitHub CLI and address them.
Steps:
1. Retrieve unresolved review comments
2. For each comment:
- Evaluate the validity of the comment
- If it's a valid point, fix the implementation
- If discussion is needed, explain why
3. Update tests as necessary
Accurately understand the intent of the review comments and respond appropriately.
Claude Code will read the content of the comments and propose or implement appropriate responses.
However, I recommend that you always digest and understand the review comments yourself before having them fixed.
PR Creation Support
.claude/commands/pr-create.md:
Check the changes in the current branch and assist in creating a PR using the GitHub CLI.
1. Check the changes using git diff
2. Generate the PR description
Include the following items:
- Overview of changes
- Reason/Background for changes
- Key changes (bullet points)
- Testing method
- Related Issues
3. Create the PR
Create a clear description that is easy for reviewers to understand.
Summary
Claude Code's custom commands are a powerful feature that significantly improves development efficiency.
The mechanism is simple: just place a Markdown file in the .claude/commands/ directory.
By automating quality checks, you can discover review points in advance and fix problems early.
Integration with the GitHub CLI allows you to streamline the entire development workflow, from issue-driven development to PR review responses.
Start with simple commands first and gradually customize them to suit your development style.
As you use them more, they will likely become indispensable.
Using the commands introduced here as a reference, please try creating a custom command set optimized for your project.
You should be able to improve both the quality and speed of development!
For more details on custom command frontmatter settings and handling multiple arguments, please refer to the following articles:
Claude Code Custom Command Frontmatter Settings: description, allowed-tools, and model
How to Handle Multiple Arguments Using $1/$2/$3 in Claude Code Custom Commands
📚 Learn More in My Udemy Course
For those who want to learn the content of this article in even greater depth.
I've released a Udemy course that systematically explains six extension features: CLAUDE.md, rules, custom commands, sub-agents, Skills, and Hooks.
You can learn how to maximize development efficiency while saving context through a hands-on approach.
You can enroll with a special coupon for 1,500 yen via the link above.
Discussion
「GUIのあるIDE統合型のAIの方が便利」という点で言いますと、
私個人としてはエディタや環境を選ばず、動作も軽量で、ターミナルさえあれば使える CLI 型の方が好みです。
そのため、最終的にはどっちが優れているかというよりは、個人にとって使いやすいかどうかの判断になるのかなとは思います。
GitHub Copilotは最新機能を把握していないものの
Claude Code では カスタムコマンドやサブエージェントのカスタマイズを行うフレームワーク(OSS)が充実しており、あまりノウハウがなくても、サクッと高度な開発環境を整えるといったメリットがあると感じています。
あまり答えになっていないかもしれませんが、参考になりましたら幸いです!
Claude Codeの機能やフレームワークで拡充される点について、別な記事に書いておりますので、検討の際に少しでもお役に立てるかもしれません。