Basic CLI Commands¶
Learn the essential terminal commands and shortcuts that make Claude Code CLI efficient to use.
What You'll Learn¶
- Slash commands for quick actions in the terminal
- Keyboard shortcuts for terminal interaction
- CLI session management
- Getting help from the command line
Slash Commands¶
Slash commands start with / and perform specific actions. Type them at the prompt:
Essential Commands¶
| Command | What It Does |
|---|---|
/help |
Show all available commands |
/exit |
End the session |
/clear |
Clear conversation history |
/compact |
Summarize conversation to save context |
Example Session¶
> /help
Available commands:
/help - Show this help message
/exit - Exit Claude Code
/clear - Clear conversation history
/compact - Summarize and compact conversation
/config - View/edit configuration
...
> /clear
Conversation cleared. Starting fresh.
>
CLI Invocation Options¶
Claude Code CLI supports various command-line arguments. These are typed in your terminal before starting an interactive session.
Basic Start¶
With Initial Prompt¶
# Start with a question (terminal argument)
claude "explain what this project does"
# Start and immediately begin a task
claude "find all TODO comments in this codebase"
Continue Previous Session¶
This restores context from your previous terminal session - useful when you need to step away and come back.
Non-Interactive Mode (Scripting)¶
Perfect for shell scripts and automation:
# Get an answer and exit (no interactive session)
claude -p "what does the main function do"
# Pipe output to a file
claude -p "explain this codebase" > explanation.md
# Use in shell scripts
RESULT=$(claude -p "what testing framework is used")
echo "This project uses: $RESULT"
Specify a Directory¶
Terminal Keyboard Shortcuts¶
These keyboard shortcuts work at the Claude Code CLI prompt (similar to other terminal tools like bash):
| Shortcut | Action |
|---|---|
Enter |
Send message |
Shift+Enter |
New line (multiline input) |
Ctrl+C |
Cancel current operation |
Ctrl+C (twice) |
Exit Claude Code CLI |
Up Arrow |
Previous message in history |
Down Arrow |
Next message in history |
Ctrl+L |
Clear terminal screen (keeps conversation) |
Tab |
Auto-complete (where supported) |
Multiline Input¶
For longer prompts, use Shift+Enter to add new lines:
> Here's my requirements:
- User authentication
- Password hashing
- JWT tokens
Please create a basic auth module.
Session Management¶
Checking Status¶
Shows current session info like working directory and conversation length.
Compacting Long Conversations¶
As conversations grow, they use more context. Use /compact to summarize:
This preserves key information while reducing token usage.
Configuration¶
View and modify settings like: - Default model - Auto-permission settings - Theme preferences
Getting Help¶
In-Session Help¶
Asking Claude¶
You can ask Claude about its own capabilities:
Documentation¶
Opens the official documentation.
Practical Examples¶
Example 1: Quick Project Overview¶
Example 2: Continue Working¶
# Yesterday you were debugging
claude -c
# Claude remembers your context
> Let's continue fixing that bug we found
Example 3: One-Off Question¶
Example 4: Focused Session¶
Try It Yourself¶
Exercise: Command Practice¶
-
Start Claude Code:
-
Try each of these commands:
-
Practice multiline input:
-
Exit and restart with continue:
-
Verify it remembers your conversation:
CLI Quick Reference Card¶
Print this out or keep it handy in your terminal:
┌───────────────────────────────────────────────────────┐
│ CLAUDE CODE CLI QUICK REFERENCE │
├───────────────────────────────────────────────────────┤
│ TERMINAL COMMANDS (before starting) │
│ claude Start interactive session │
│ claude "prompt" Start with initial prompt │
│ claude -c Continue last session │
│ claude -p "q" Non-interactive (for scripts) │
│ claude --cwd DIR Work in specific directory │
│ claude --version Show CLI version │
│ claude --help Show all CLI options │
├───────────────────────────────────────────────────────┤
│ SLASH COMMANDS (inside session) │
│ /help Show help │
│ /exit Exit session │
│ /clear Clear conversation history │
│ /compact Summarize to save context │
│ /config View/edit settings │
├───────────────────────────────────────────────────────┤
│ KEYBOARD SHORTCUTS │
│ Ctrl+C Cancel / Exit (2x) │
│ Shift+Enter Multiline input │
│ Up/Down History navigation │
│ Ctrl+L Clear terminal screen │
└───────────────────────────────────────────────────────┘
What's Next?¶
You know the CLI commands - now let's learn how Claude Code CLI works with files in 03-file-operations.
Summary:
- Terminal commands (claude, claude -c, claude -p) - typed in your shell
- Slash commands (/help, /exit, /clear) - typed inside a session
- Use claude -p for shell scripting and automation
- Use Shift+Enter for multiline prompts in the terminal
- /compact keeps conversations manageable in long sessions
Learning Resources¶
Featured Video¶
NetworkChuck: AI in the Terminal - Commands Section (3.6M subscribers)
Deep dive into Claude Code CLI commands, slash commands, keyboard shortcuts, and productivity tips.
Additional Resources¶
| Type | Resource | Description |
|---|---|---|
| 🎬 Video | 800+ Hours Learning Claude Code | Edmund Yong - Advanced tips and shortcuts |
| 📚 Official Docs | CLI Reference | Complete command documentation |
| 📖 Tutorial | How I Use Claude Code | Builder.io practical guide |
| 🎓 Free Course | AI in Terminal Guide | NetworkChuck's companion repository |
| 💼 Commercial | AI Coding Crash Course | Udemy - Comprehensive AI coding |