Core commands in Claude Code
These are the essential slash commands you will use in every Claude Code session.
These are the essential slash commands you will use in every Claude Code session.
The commands you will use daily
Claude Code has many commands. Most sessions use a few familiar commands. Let's explore those commands first.
File context commands
/add
Add the file to Claude's context. This is probably the command you'll use most often.
Basic usage instructions:
/add src/auth.js Add more files:
/add src/auth.js src/user.js src/session.js Add more glob patterns:
/add src/components/**/*.tsx # Tất cả các file TSX trong components /add tests/*.test.js # Tất cả các file kiểm thử /add **/*.md # Tất cả các file markdown When to use:
- Before asking questions about specific code.
- Before requesting changes to a file
- When Claude needed to understand how the files worked together.
Helpful tip : Add the file BEFORE asking the question. Claude will give a better answer once he's seen the actual code.
/ls
List the files in context.
/ls This displays what Claude currently knows. Use this command to verify that your /add commands worked or to see what has accumulated in the context.
Conversation management
/clear
Completely delete your conversation history.
/clear When to use:
- Start a completely new task.
- The context becomes muddled with irrelevant history.
- Claude was confused or gave inconsistent feedback.
- You want to start over without restarting Claude Code.
Warning : This action is irreversible. Everything from the current session will be deleted.
/compact
Summarize the context to reduce the file size while retaining key information.
/compact When to use:
- The context is getting bigger, but you want to keep working.
- Claude refers to the possibility of reaching the contextual limit.
- Responses are slowing down.
The difference compared to /clear: Compact retains the essence of what you discussed. Clear deletes everything.
/undo
Restore Claude's final actions.
/undo When to use:
- Claude has made changes that you didn't want.
- You want to try a different approach.
- Something is wrong.
Faster than undoing changes manually.
Help and explore
/help
Display available commands.
/help The commands change with updates. /help always displays what is currently available.
/status
Display the current session status.
/status Displays contextual usage levels, active files, and other session information.
Actual samples
Start a new mission.
/clear /add src/feature-im-working-on/* > Hãy thêm cache vào lớp tìm nạp dữ liệu Delete all related files or specific tasks.
Refresh the context mid-way.
/compact /add src/new-file-i-need.js > Tiếp tục với việc triển khai cache. Bây giờ hãy tích hợp với file mới này. Compact helps preserve history. Add new context. Continue from where you left off.
Explore an unfamiliar codebase.
/add README.md package.json > Dự án này làm gì và công nghệ sử dụng là gì? /add src/index.js src/app.js > Hãy cho tôi biết các điểm truy cập chính Start with an overview, then narrow it down.
Think before you commit.
/add $(git diff --name-only) > Xem lại những thay đổi này. Có lỗi hoặc vấn đề gì không? Only add the changed files. Consider focusing on them.
Common mistakes
Adding too much:
/add src/**/* Don't include your entire source code. The context is limited. Be selective.
Not enough added:
> Tại sao hàm này không hoạt động? Claude can't see the function. Please add the file first.
Forget what's in context:
# Sau nhiều lệnh /add. > Tại sao bạn lại tham chiếu đến file cũ đó? Use /ls to see what's actually in the context. Use /clear if it's too cluttered.
Use /clear when /compact is functional:
/clear # Bây giờ tôi phải thêm lại mọi thứ và giải thích lại nhiệm vụ If you want to preserve the session context but reduce its size, use /compact instead of /clear.
Quick reference to commands
| Command | Its function | When should it be used? |
|---|---|---|
/add | Add files to the context. | Before performing any specific tasks related to files |
/ls | List the context files. | To check what Claude saw. |
/clear | Delete the conversation | A new beginning with a new mission. |
/compact | Context summary | Reduce in size, retain the essence. |
/undo | Undo the last action | Claude made an unwanted change. |
/help | Display commands | Discover or verify commands |
/status | Display session status | Check the usage in context. |
Exercise
Open Claude Code in a project and practice:
- Add some source files using the /add command.
- Use the /ls command to verify if they are in context.
- Ask questions about the code.
- Use the /compact command to see how it's summarized.
- Use the /clear command and notice the difference.
Familiarize yourself with these commands before proceeding. They are fundamental to everything else.
Key points to remember
- /add is your most important command - provide Claude with the appropriate files.
- /clear to start over, /compact to reduce the size while retaining context.
- Check what's in the context using the /ls command when confused.
- /undo is faster than manually undoing.
- Less is more: Being selective about context is better than dumping everything in.
-
Question 1:
What should you do when Claude's feedback starts to become confusing or inconsistent?
EXPLAIN:
A cluttered context often leads to confusing responses. Clearing or simplifying the context will provide Claude with a cleaner platform to work on.
-
Question 2:
When should you use '/add' with a glob template like 'src/**/*.ts'?
EXPLAIN:
The glob template allows you to add multiple related files at once, which is useful when Claude needs to understand how the files work together.
-
Question 3:
What is the difference between '/clear' and '/compact'?
EXPLAIN:
/clear completely deletes the conversation history. /compact summarizes the context to retain important information while minimizing token usage.
Training results
You have completed 0 questions.
-- / --
Discover more
Claude Claude CodeShare by
Marvin FryYou should read it
- How to combine Claude Code with Obsidian CLI
- How to use Claude Code safely: A guide to risk management.
- Using Claude Code on your phone
- How to optimize Claude Code for more efficient one-shot code implementation.
- Why do developers always choose Claude over other AIs?
- Cursor Composer User Guide
- Context management in Claude Code
- This prompt template creates test questions for various subjects.
- Tips for recognizing AI-generated text