Core Commands
The essential slash commands you'll use in every Claude Code session.
Premium Course Content
This lesson is part of a premium course. Upgrade to Pro to unlock all premium courses and content.
- Access all premium courses
- 1000+ AI skills included
- New content added weekly
Commands You’ll Use Daily
Claude Code has many commands. Most sessions use the same handful. Let’s nail those first.
File Context Commands
/add
Adds files to Claude’s context. This is probably the command you’ll use most.
Basic usage:
/add src/auth.js
Multiple files:
/add src/auth.js src/user.js src/session.js
Glob patterns:
/add src/components/**/*.tsx # All TSX files in components
/add tests/*.test.js # All test files
/add **/*.md # All markdown files
When to use:
- Before asking questions about specific code
- Before requesting changes to files
- When Claude needs to understand how files work together
Pro tip: Add files BEFORE asking questions. Claude gives better answers when it has seen the actual code.
/ls
Lists files in context.
/ls
Shows what Claude currently knows about. Use this to verify your /add commands worked or to see what’s accumulated in context.
Conversation Management
/clear
Wipes conversation history completely.
/clear
When to use:
- Starting a completely new task
- Context has become cluttered with irrelevant history
- Claude is confused or giving inconsistent responses
- You want a fresh start without restarting Claude Code
Warning: This is irreversible. Everything from the current session is gone.
/compact
Summarizes context to reduce size while keeping key information.
/compact
When to use:
- Context is getting large but you want to keep working
- Claude mentions approaching context limits
- Responses are slowing down
Difference from /clear: Compact preserves the essence of what you’ve discussed. Clear erases everything.
/undo
Reverts Claude’s last action.
/undo
When to use:
- Claude made a change you don’t want
- You want to try a different approach
- Something went wrong
Faster than manually reverting changes.
Help and Discovery
/help
Shows available commands.
/help
Commands change with updates. /help always shows what’s currently available.
/status
Shows current session state.
/status
Displays context usage, active files, and other session info.
Practical Patterns
Starting a New Task
/clear
/add src/feature-im-working-on/*
> Let's add caching to the data fetching layer
Clear slate. Relevant files. Specific task.
Midway Context Refresh
/compact
/add src/new-file-i-need.js
> Continue with the caching implementation. Now integrate with this new file.
Quick check: Before moving on, can you recall the key concept we just covered? Try to explain it in your own words before continuing.
Compact keeps history. Add new context. Continue where you left off.
Exploring an Unfamiliar Codebase
/add README.md package.json
> What does this project do and what's the tech stack?
/add src/index.js src/app.js
> Walk me through the main entry points
Start broad, then narrow in.
Reviewing Before Committing
/add $(git diff --name-only)
> Review these changes. Any bugs or issues?
Add only changed files. Focused review.
Common Mistakes
Adding too much:
/add src/**/*
Don’t add your entire codebase. Context has limits. Be selective.
Not adding enough:
> Why isn't this function working?
Claude can’t see the function. Add the file first.
Forgetting what’s in context:
# After many /add commands...
> Why are you referencing that old file?
Use /ls to see what’s actually in context. Use /clear if it’s cluttered.
Using /clear when /compact would work:
/clear
# Now I have to re-add everything and re-explain the task
If you want to keep session context but reduce size, use /compact instead.
Command Quick Reference
| Command | What It Does | When to Use |
|---|---|---|
/add | Add files to context | Before any file-specific work |
/ls | List context files | To check what Claude sees |
/clear | Wipe conversation | Fresh start on new task |
/compact | Summarize context | Reduce size, keep essence |
/undo | Revert last action | Claude made unwanted change |
/help | Show commands | Discover or verify commands |
/status | Show session state | Check context usage |
Exercise
Open Claude Code in a project and practice:
- Add a few source files with
/add - Use
/lsto verify they’re in context - Ask a question about the code
- Use
/compactto see how it summarizes - Use
/clearand notice the difference
Get comfortable with these before moving on. They’re the foundation for everything else.
Key Takeaways
/addis your most important command—give Claude the right files/clearfor fresh starts,/compactto reduce size while keeping context- Check what’s in context with
/lswhen confused /undois faster than manual reverting- Less is more: selective context beats dumping everything
Next: how to manage context strategically for better results.
Up next: In the next lesson, we’ll dive into Context Management.
Knowledge Check
Complete the quiz above first
Lesson completed!