Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster through natural language commands.
βοΈ
Installation & Setup
npm install -g @anthropic-ai/claude-code
Install Claude Code globally via npm
claude
Start Claude Code (will prompt for authentication on first run)
claude update
Update Claude Code to the latest version
claude --version
Check your Claude Code version (confirm you're on latest)
claude config
Configure Claude Code settings
π
Basic Usage
claude
Start interactive REPL session
claude "explain this project"
Start REPL with initial prompt
claude -p "query"
Run one-off query, then exit (print mode)
cat file.py | claude -p "explain this code"
Process piped content
claude --continue
Continue most recent conversation
claude --resume
Show conversation picker to resume a session
/init
Initialize project with CLAUDE.md guide
/clear
Clear conversation history
/compact
Compact conversation to keep context window lean
/compact Focus on the authentication system
Compact conversation with custom focus instructions
/cost
Show token usage statistics
/memory
Edit CLAUDE.md memory files
/prime
Load key files and information into context window
! command
Execute bash commands directly
@ file/path
Reference specific file paths
# memorize this information
Add information to memory files
Escape (double-tap)
Undo/edit previous prompt
Shift + Tab
Toggle auto-accept mode for edits
Ctrl + R
Enable verbose output mode
\ + Enter
Create newline in input
ποΈ
CLI Flags
claude -p "query" --output-format json
Output response as JSON (useful for scripting)
claude -p "query" --output-format stream-json
Stream JSON output in real-time
claude --verbose
Enable verbose logging
claude -p --max-turns 3 "query"
Limit number of agentic turns
claude --mcp-debug
Debug MCP server configuration issues
claude --dangerously-skip-permissions
Skip all permission prompts (use with caution!)
β‘
Slash Commands (Interactive Mode)
/config
View/modify configuration
/review
Request code review
/pr_comments
View pull request comments
/doctor
Check Claude Code installation health
/login
Switch Anthropic accounts
/logout
Sign out from your Anthropic account
/vim
Enter vim mode for alternating insert and command modes
/terminal-setup
Install Shift+Enter key binding for newlines (iTerm2 and VSCode only)
/bug
Report bugs (sends conversation to Anthropic)
/help
Get usage help
π οΈ
Custom Slash Commands
echo "Analyze performance and suggest optimizations:" > .claude/commands/optimize.md
Create project-level custom command (available as /project:optimize)
echo "Review code for security vulnerabilities:" > ~/.claude/commands/security-review.md
Create global custom command (available in all projects)
echo "Fix issue #$ARGUMENTS with tests and PR description" > .claude/commands/fix-issue.md
Create parameterized command (use with /project:fix-issue 123)
# Add instant memory
Start input with # to quickly add to memory files
π―
Advanced Workflows
claude -p "Find all TODO comments and fix them" --max-turns 10
Automated task with multiple turns
for file in *.py; do claude -p "Add type hints:" < "$file"; done
Process multiple files with Claude
git worktree add ../project-feature-a -b feature-a
Create Git worktree for parallel Claude Code sessions
claude -c -p "Continue debugging from yesterday"
Continue previous session in print mode
claude -p "think deeply about implementing OAuth2" --output-format json
Extended thinking with JSON output for parsing
π
MCP & Integrations
claude mcp
Configure Model Context Protocol servers
claude --mcp-debug
Launch with MCP debugging enabled
MCP Integration:
- Add servers to
.mcp.json
file for team sharing - Use project config for repository-specific tools
- Claude Code functions as both MCP server and client
- Examples: Puppeteer, Sentry, GitHub, filesystem tools
π¬
Prompt Engineering Tips
be concise
Force short, focused answers from Claude
read the entire file first
Force Claude to read complete files before responding
think deeply about this
Trigger extended reasoning and deeper analysis
think harder
Intensify Claude's reasoning process
make a plan first, don't code yet
Force planning phase before implementation
break this into small testable steps
Get incremental, verifiable progress
π―
Complete Plan Mode Guide
What is Plan Mode?
- A special operating mode where Claude Code only reads, analyzes, and plansβno file edits, commands, or commits
- Mirrors senior engineer workflow: understand first, plan second, build third
- Used to load context window with all relevant information before any code changes
Shift + Tab (twice)
Enter Plan Mode - Claude restricted from making file changes or running commands
/prime
Load key files and information into context window before planning
Correct me if I'm wrong, but...
Validate assumptions and get neutral, unbiased feedback
write a detailed specification for this feature in specs/
Create comprehensive plan/spec file for complex features
analyze the codebase and create an implementation plan
Have Claude understand and plan before building
Core Principles:
- No Mutations: Cannot create, modify, or delete files (including plan.md/spec files)
- Context Building: Read files and understand codebase, fill context window with key info
- Ask Questions: Freely ask clarifying or "stupid" questions to validate assumptions
- Validate Understanding: Use "Correct me if I'm wrong" for unbiased feedback
Recommended Workflows:
- Plan β Execute (Quick Tasks): For small, simple changes
- Plan β Write Spec β Execute (Mid/Large Features): Recommended for most work
- In Plan Mode: analyze, create detailed specification
- Review and iterate on the plan
- Exit Plan Mode and execute according to the spec
Best Practices:
- Be Explicit: Clearly state what you want planned - more explicit = better plan
- Prime the Context: Use
/prime
to load key files before planning - Iterate on Plans: Ask follow-up questions to clarify and capture all requirements
- Store Plans: Save specs in dedicated directory (e.g.,
specs/
) for review and version control - Higher-Order Prompts: Treat plans as prompts for agents - pass specs as parameters
- Parallelize Work: Use agentic loops for multi-agent, parallel development
Why Use Plan Mode?
- Safety: No risk of accidental file changes or destructive actions
- Clarity: Forces full understanding of problem and requirements before building
- Efficiency: Reduces wasted time by ensuring right approach before execution
- Scalability: Enables complex, multi-agent workflows with clear, shared plan
Plan Mode Summary Table
Step | Action/Advice |
---|---|
Enter Plan Mode | Shift+Tab twice |
No Mutations | Only reads/analyzes, never edits files |
Build Context | Load key files/info before planning |
Ask Questions | Validate assumptions, use "Correct me if I'm wrong" |
Plan β Execute | For quick tasks: plan, then build |
Plan β Spec β Execute | For big tasks: plan, write spec, review, then build |
Store Plans | Save specs in dedicated directory |
Parallel Agents | Use agentic loops for multi-agent, parallel work |
Higher-Order Prompts | Treat plans as prompts for agents |
Review & Iterate | Always review and refine plans before execution |
Key Takeaways:
- The plan is the prompt: Well-crafted plan/spec is foundation for effective agentic coding
- Think, then build: Always plan before coding - new standard for AI-augmented engineering
- Set up codebase for agents: Organize files, specs, and context to maximize agent productivity
π€
Plan Mode vs Auto Accept Mode
Shift + Tab
Toggle between Plan Mode and Auto Accept Mode
Plan Mode:
- Claude asks for permission before each action
- Best for: thinking, clarifying, and iterating before executing
- Use when: working on critical code or unfamiliar tasks
- Allows you to guide and course-correct Claude's approach
Auto Accept Mode:
- Claude executes changes automatically without asking
- Best for: trusted operations and repetitive tasks
- Use when: you trust Claude's judgment on the task
- Monitor the context usage indicator during auto mode
π
Project Management & Planning
echo "# Attack Plan\n## Goals\n## Steps\n## Progress" > plan.md
Create markdown file for tracking plans and progress
use the plan.md file as a checklist and update progress
Have Claude maintain project progress in markdown files
consult multiple models for this critical decision
Get second opinions for important architectural choices
Project Management Best Practices:
- Use markdown files (.md) for attack plans and progress tracking
- Break big refactors into small, testable steps
- Have Claude update progress in your planning documents
- For critical decisions, consult multiple AI models (Claude, Gemini, GPT-4)
- Keep a running checklist of completed vs pending tasks
β¨οΈ
Keyboard Shortcuts & Navigation
\ + Enter
Quick escape to create newline
Option + Enter
Add newline (Meta+Enter with proper terminal config)
Shift + Tab
Toggle auto-accept mode
Escape
Interrupt Claude during any phase (thinking, tool calls, file edits)
Escape (double-tap)
Jump back in history and edit previous prompt
Arrow Keys
Navigate conversation picker when resuming sessions
Hidden Features:
- View previous chats: Access via Claude Code UI in your current folder
- Context usage indicator: Monitor context window fill in the UI
- Double-tap Escape: Powerful feature for iterating on prompts
- Use
/compact
before context window fills for best performance
ποΈ
Dangerous Operations
β οΈ DANGER ZONE
The following commands can cause data loss or unexpected behavior. Use with extreme caution!
claude --dangerously-skip-permissions
π₯ Skip ALL permission prompts (Claude can modify/delete files without asking)
claude -p "Delete all test files" --dangerously-skip-permissions
π₯ Automated destructive operations without confirmation
rm -rf .claude/
π₯ Remove all Claude Code configuration and memory (PERMANENT!)
βοΈ
Configuration Examples
Example settings.json configuration:
{
"permissions": {
"allow": [
"Bash(npm run lint)",
"Bash(npm run test:*)",
"Read(~/.zshrc)"
],
"deny": [
"Bash(curl:*)"
]
},
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"NODE_ENV": "development"
},
"theme": "dark",
"auto_accept": false,
"max_turns": 10
}
Configuration Hierarchy:
~/.claude/settings.json
- Global user settings.claude/settings.json
- Project settings (checked into git).claude/settings.local.json
- Local overrides (not checked in)- Enterprise policies take precedence over all user settings
π‘
Best Practices
Effective Usage Tips:
- Use
/init
to create CLAUDE.md for better context - Use
/compact
frequently before context window fills - Master Plan Mode: Enter with Shift+Tab twice for safe analysis and planning
- Ask Claude to make a plan before coding with "make a plan first, don't code yet"
- Use auto-accept mode (Shift+Tab) for trusted operations
- Create custom slash commands for repeated workflows
- Use Git worktrees for parallel Claude sessions
- Monitor costs with
/cost
command and context usage in UI - Start small and scale up for complex tasks
- Use
think deeply
for complex architectural decisions - Use MCP servers for extended functionality
- Use markdown files for project planning and progress tracking
- Break big refactors into small, testable steps
- Use "be concise" for focused answers, "read the entire file first" for complete analysis
- Double-tap Escape to edit and iterate on previous prompts
- Consult multiple AI models for critical architectural decisions
- Follow Plan β Spec β Execute workflow for complex features
- Store specifications in dedicated
specs/
directory - Use "Correct me if I'm wrong" to validate assumptions in Plan Mode