- Learn
- AI Coding Agents
- Claude Code
- Basic Commands and Interactions
Learn the essential commands, shortcuts, and interaction patterns for working with Claude Code effectively.
Basic Commands and Interactions
Claude Code uses natural language for most interactions, but has several built-in commands and features that make working more efficient.
Starting Sessions
Basic Start
claude
Starts Claude Code in the current directory.
With Options
# Start with a specific model
claude --model claude-opus-4-20250514
# Resume previous conversation
claude --continue
# Start with an initial prompt
claude "Explain this project structure"
Built-in Commands
Commands start with / and provide quick actions.
Essential Commands
| Command | Description |
|---|---|
/help | Show all available commands |
/exit | Exit Claude Code |
/clear | Clear conversation history |
/model | Switch AI model |
/compact | Summarize conversation to save context |
File Commands
| Command | Description |
|---|---|
/read <path> | Read a file into context |
/tree | Show project structure |
/search <query> | Search codebase |
Session Commands
| Command | Description |
|---|---|
/save | Save conversation |
/load | Load saved conversation |
/history | Show conversation history |
/undo | Undo last file change |
Natural Language Interactions
Asking Questions
Simply ask in plain English:
What does the UserService class do?
How is authentication handled in this app?
What database is this project using?
Requesting Actions
Describe what you want done:
Add input validation to the signup form
Create a new API endpoint for user preferences
Fix the bug where prices show as undefined
Giving Instructions
Provide detailed specifications:
Create a React component called ProductCard:
- Display product image, title, and price
- Include "Add to Cart" button
- Use Tailwind for styling
- Support a "featured" variant with a badge
Approval Flow
Claude Code asks for confirmation before actions.
File Changes
Claude Code: I'll update src/components/Button.tsx to add the loading state.
This will:
- Add a loading prop
- Show a spinner when loading
- Disable the button during loading
Proceed? [Y/n]
Type y (or just Enter) to approve, n to reject.
Command Execution
Claude Code: I need to run this command:
npm install framer-motion
This will install the framer-motion animation library.
Allow? [Y/n]
Auto-Approve Mode
For faster iteration (use carefully):
/autoApprove on
Claude Code will make changes without asking. Turn off with:
/autoApprove off
Keyboard Shortcuts
During Input
| Shortcut | Action |
|---|---|
Enter | Send message |
Shift+Enter | New line |
Up Arrow | Previous message |
Down Arrow | Next message |
Ctrl+C | Cancel/Exit |
Ctrl+L | Clear screen |
During Approval
| Key | Action |
|---|---|
y or Enter | Approve |
n | Reject |
e | Edit before applying |
? | Get more details |
Providing Context
Reference Files
Use @ to reference files:
Look at @src/api/users.ts and explain the authentication logic
Include Code Snippets
Use markdown code blocks:
This code isn't working:
```javascript
const data = await fetch('/api/users')
console.log(data.users)
What's wrong?
### Share Error Messages
I'm getting this error when I run npm build:
Error: Cannot find module './utils' at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1048:15) at Module.require (node:internal/modules/cjs/loader:1140:19)
## Working with Output
### Copy Code
When Claude Code shows code, you can:
- Select and copy normally
- Use the copy button if available
- Apply directly to files
### Apply Suggestions
When Claude Code suggests changes:
Claude Code: Here's the updated function:
function calculateTotal(items: Item[]): number {
return items.reduce((sum, item) => sum + item.price * item.quantity, 0)
}
Apply this change? [Y/n]
### Request Modifications
If the suggestion isn't quite right:
That's close, but also add tax calculation
Claude Code will revise its suggestion.
## Conversation Patterns
### Iterative Refinement
Build up complex changes step by step:
You: Create a basic user profile component
Claude Code: [Creates component]
You: Add an edit mode with form inputs
Claude Code: [Adds edit functionality]
You: Make it responsive for mobile
Claude Code: [Adds responsive styles]
### Clarifying Questions
If Claude Code needs more information:
Claude Code: I can add user avatars. A few questions:
- Should avatars be stored locally or in cloud storage?
- What's the maximum file size?
- Should I support cropping?
### Confirm Understanding
Claude Code often confirms before proceeding:
Claude Code: Let me make sure I understand. You want me to:
- Add a "favorites" table to the database
- Create API endpoints for adding/removing favorites
- Add a heart icon button to ProductCard
- Create a Favorites page listing saved items
Is that correct? [Y/n]
## Handling Mistakes
### Undo Changes
If something goes wrong:
/undo
Reverts the last file change.
### Multiple Undos
/undo 3
Reverts the last 3 changes.
### Start Over
/clear
Clears conversation but keeps file changes.
### Full Reset
For a complete fresh start:
/exit claude
## Session Management
### Save Important Conversations
/save feature-auth
Saves current conversation as "feature-auth".
### Resume Later
claude --continue
Or load a specific save:
/load feature-auth
### Compact Long Sessions
When context gets long:
/compact
Claude Code summarizes the conversation to free up context space.
## Getting Help
### Built-in Help
/help
Shows all commands and usage.
### Specific Command Help
/help search
Shows details about the search command.
### Ask Claude Code
How do I use you to run tests?
What's the best way to refactor this large file?
Claude Code can explain its own features.
## Summary
**Starting:**
- `claude` to start
- `--continue` to resume
- `--model` to specify model
**Commands:**
- `/help` - Get help
- `/clear` - Clear history
- `/undo` - Revert changes
- `/save` and `/load` - Manage sessions
**Interactions:**
- Natural language for requests
- `@file` to reference files
- Code blocks for snippets
- `Y/n` for approvals
**Shortcuts:**
- `Enter` to send
- `Ctrl+C` to cancel
- `Up/Down` for history
## Next Steps
Now that you know the basics, let's explore how Claude Code understands and works with your project's context.