Master agentic coding with proven patterns from Anthropic's engineering team
๐ Claude Code Overview
Claude Code is a low-level, unopinionated agentic coding tool that provides close to raw model access without forcing specific workflows. It's designed to be flexible, customizable, scriptable, and safe.
๐ฏ Core Philosophy
Claude Code creates a flexible power tool that meets you where you work - in your terminal, with your existing tools and workflows.
๐ ๏ธ Low-Level Control
Direct access to Claude's capabilities without imposed frameworks or rigid workflows.
๐ง Highly Customizable
Adapt to any codebase, language, or development environment through configuration.
๐ Scriptable
Integrate into CI/CD pipelines and automate repetitive development tasks.
๐ก๏ธ Safe by Default
Conservative permission system with fine-grained control over tool access.
๐ฏ What You'll Learn
Environment optimization and context management
Creating effective CLAUDE.md files for project-specific guidance
Structured workflows for complex development tasks
Safety practices and permission management
Advanced features like MCP integration and custom commands
Pro tips from Anthropic's internal engineering teams
โจ๏ธ Core Commands
Master all Claude Code slash commands for complete development workflow control.
๐ Essential Commands
๐ /init
Creates a CLAUDE.md file with project analysis
# Run in your project directory
/init
# Claude analyzes your project and creates CLAUDE.md with:
# - Tech stack detection
# - Project structure overview
# - Key commands and scripts
# - Coding conventions discovered
โ /help
Shows all available commands and descriptions
# Get help on available commands
/help
# Shows comprehensive list of:
# - Built-in slash commands
# - Custom project commands
# - User-defined commands
# - Usage examples
๐ง /model
Switch between different Claude models
# Switch to Claude Opus for complex tasks
/model claude-3-opus-20240229
# Switch to Sonnet for quick responses
/model claude-3-5-sonnet-20241022
# Each model optimized for different use cases
โ๏ธ /config
Configure Claude Code settings and preferences
# Configure terminal theme matching
/config theme dark
# Set keyboard shortcuts
/config keybindings
# Customize default behaviors
/config defaults
๐ฌ Conversation Management
๐ /continue
Resume previous conversations
# Continue most recent conversation
/continue
# Continue in non-interactive mode for scripts
/continue --print
# Select from multiple conversations
/continue --select
๐๏ธ /clear
Reset conversation context completely
# Wipe conversation history completely
/clear
# Gives Claude a completely fresh start
# Still retains CLAUDE.md and file context
# Best when conversation has gone off track
๐๏ธ /compact
Compress context while preserving key information
# Compress conversation
/compact
# With optional focus instructions
/compact [focus instructions]
# Maintains important context and decisions
# Removes redundant information
๐ /cost
Monitor token usage and costs
# Check current usage and costs
/cost
# See detailed breakdown of:
# - Token consumption
# - Cost estimates
# - Usage patterns
# - Optimization suggestions
๐ Permission & Security
๐ก๏ธ /permissions
Manage tool permissions and security settings
# View current permissions
/permissions
# Add specific permissions
/permissions add Edit
/permissions add "Bash(git commit:*)"
# Customize tool access for safety
# Show project tree structure
/tree
# Claude breaks down the directory tree
# Perfect for understanding project layout
# Helps navigate complex codebases
๐ /overview
Get high-level project overview
# Get comprehensive project overview
/overview
# Perfect for:
# - Onboarding to new codebases
# - Open source project exploration
# - Understanding architecture
# List MCP servers
/mcp list
# Add new MCP server
/mcp add server-name
# Configure integrations
/mcp configure
๐จ Custom Commands
๐ Project Commands (/project:name)
Create team-shared commands in .claude/commands/:
# Create project command
mkdir -p .claude/commands
echo "Run all unit tests and report results" > .claude/commands/test.md
# Usage
/project:test
# Available to all team members
# Shows "(project)" in /help
๐ค User Commands (/user:name)
Create personal commands in ~/.claude/commands/:
# Create personal command
mkdir -p ~/.claude/commands
echo "Review code for security vulnerabilities" > ~/.claude/commands/security.md
# Usage
/user:security
# Available across all projects
# Shows "(user)" in /help
๐ Quick Reference
๐ง Core Commands
/help - List all commands
/init - Initialize project
/clear - Reset context
/compact - Compress context
/model - Switch models
๐ Management
/cost - Check usage
/memory - Manage memory
/permissions - Set permissions
/config - Configure settings
/continue - Resume session
๐๏ธ Project Tools
/tree - Show structure
/overview - Project summary
/review - Code review
/task - Spawn sub-agent
/ide - IDE integration
๐ฏ Custom Commands
/project:name - Team commands
/user:name - Personal commands
$ARGUMENTS - Pass parameters
@file.js - Reference files
!command - Execute bash
โ๏ธ Setup & Configuration
๐ง Environment Optimization
Claude Code automatically pulls context into prompts, which consumes time and tokens. Optimize through environment tuning:
Configure Tool Permissions
Customize the allowlist to permit safe tools and allow easy-to-undo operations:
# Allow file editing and git operations (easy to undo)
claude --allow-edit-files --allow-git
# Allow specific bash commands
claude --allow-bash-commands="npm,yarn,pip"
MCP Configuration
Configure Model Context Protocol servers for enhanced capabilities:
In project directory (available when running Claude Code in that directory):
# Commands
- npm run dev - Start development server
- npm test - Run test suite
- npm run build - Build for production
- npm run lint - Run ESLint
๐ Code Style
Define formatting and convention rules
# Code Style
- Use TypeScript strict mode
- Prefer named exports
- Use async/await over Promises
- Destructure imports when possible
๐ง Dynamic Updates
Use the # key to give Claude instructions that it will automatically incorporate into the relevant CLAUDE.md:
# Press # in Claude Code, then type:
"Always use semantic commit messages following conventional commits format"
# This gets automatically added to your CLAUDE.md
๐ก Optimization Tips
Keep content concise - CLAUDE.md is prepended to every prompt
Use bullet points instead of long paragraphs
Run through prompt improver for better adherence
Add emphasis with "IMPORTANT" or "YOU MUST" for critical rules
Include CLAUDE.md changes in commits to benefit team members
๐ Example CLAUDE.md Template
# Project: E-commerce Platform
## Tech Stack
- Next.js 14 with App Router
- TypeScript 5.2
- Prisma with PostgreSQL
- Tailwind CSS 3.4
## Key Commands
- npm run dev - Development server (localhost:3000)
- npm run build - Production build
- npm test - Run Jest tests
- npm run db:migrate - Run database migrations
## Code Style
- Use TypeScript strict mode
- Prefer named exports over default exports
- Use Prisma for all database operations
- Follow conventional commit format
- Write tests for new features
## Project Structure
- app/ - Next.js app router pages
- components/ - Reusable UI components
- lib/ - Utilities and database schema
- prisma/ - Database schema and migrations
## IMPORTANT
- Always validate user input before database operations
- Use proper error handling with try-catch blocks
- Include unit tests for business logic functions
๐ Proven Workflows
๐ฏ The Research โ Plan โ Implement Pattern
The most effective workflow for complex tasks follows this structured approach:
๐ Research Phase
Ask Claude to research the problem and understand the codebase:
"Before implementing anything, please:
1. Read through the relevant files in our authentication system
2. Understand the current user model and session handling
3. Identify any existing patterns we should follow
4. Research best practices for OAuth2 implementation"
๐ Planning Phase
Have Claude create a detailed plan before coding:
"Now create a detailed implementation plan that:
1. Breaks down the OAuth2 integration into logical steps
2. Identifies required dependencies and configuration
3. Plans the database schema changes
4. Outlines the testing strategy
5. Consider security implications and error handling"
"Implement the plan step by step:
1. Start with the database schema changes
2. Implement the OAuth2 routes and handlers
3. Add proper error handling and validation
4. Write comprehensive tests
5. Update documentation and examples"
๐ Completion Phase
Finalize with proper documentation and cleanup:
"Complete the implementation by:
1. Running all tests to ensure nothing broke
2. Creating a clear pull request with description
3. Updating the README with new OAuth2 setup instructions
4. Committing all changes with semantic commit messages"
๐งช Test-Driven Development (TDD) Workflow
For features that can be verified with tests:
Red Phase
"Write failing tests for the user authentication feature:
1. Test successful login with valid credentials
2. Test failed login with invalid credentials
3. Test password reset functionality
4. Test session management and logout"
Green Phase
"Now implement the minimum code needed to make these tests pass:
1. Focus on making tests pass, not perfect code
2. Implement core authentication logic
3. Add basic error handling
4. Ensure all tests are green"
Refactor Phase
"Refactor the implementation while keeping tests green:
1. Improve code organization and readability
2. Add comprehensive error handling
3. Optimize performance where needed
4. Ensure tests still pass after refactoring"
๐ก๏ธ Safety & Permissions
๐ Permission System
Claude Code uses a conservative permission system by default, requesting permission for any action that might modify your system.
โ ๏ธ Default Behavior
By default, Claude requests permission for:
File writes and modifications
Most bash commands
MCP tool usage
Network requests
โ๏ธ Customizing Permissions
๐ข Safe Tools to Allow
These tools are generally safe and easy to undo:
File editing (changes can be reverted with git)
Git operations (commits, branches, etc.)
Package manager commands (npm, yarn, pip)
Test runners (jest, pytest, etc.)
Linting and formatting tools
# Allow common safe operations
claude --allow-edit-files --allow-git --allow-bash-commands="npm,yarn,jest"
# Or configure in project settings
{
"permissions": {
"allowEditFiles": true,
"allowGit": true,
"allowedBashCommands": ["npm", "yarn", "jest", "eslint"]
}
}
โ ๏ธ Dangerous Mode
Use with extreme caution! The --dangerously-skip-permissions flag bypasses all permission checks.
๐ Safe Usage Guidelines
Only use in isolated containers without internet access
Use for workflows like fixing lint errors or generating boilerplate
Never use on production systems or with sensitive data
Always backup your work before using dangerous mode
# Use in a secure container environment
docker run --rm -v $(pwd):/workspace -w /workspace claude-container \
claude --dangerously-skip-permissions "Fix all ESLint errors in the codebase"
๐ Advanced Features
โก Custom Slash Commands
Store prompt templates in Markdown files within the .claude/commands folder for reusable workflows:
Creating Commands
# Create a custom refactoring command
echo "Refactor this code to improve readability and performance:
1. Extract reusable functions
2. Add proper TypeScript types
3. Improve error handling
4. Add comprehensive comments
5. Ensure all tests still pass" > .claude/commands/refactor.md
Using Arguments
Use $ARGUMENTS to pass parameters:
# Create a GitHub issue fixer
echo "Find and fix GitHub issue: $ARGUMENTS
Follow these steps:
1. Understand the issue described in the ticket
2. Locate the relevant code in our codebase
3. Implement a solution that addresses the root cause
4. Add appropriate tests
5. Prepare a concise PR description" > .claude/commands/fix-issue.md
# Usage: /fix-issue 123
๐ Model Context Protocol (MCP)
Extend Claude's capabilities with specialized tools and external services:
๐ Web Automation
Use Puppeteer server for browser automation and visual testing
The first version might be good, but after 2-3 iterations it will typically look much better. Give Claude the tools to see its outputs for best results.
๐ Onboarding and Exploration
When onboarding to a new codebase, use Claude Code for learning and exploration:
# Ask the same questions you'd ask another engineer
"Can you explain how the authentication flow works in this codebase?"
"What's the pattern for handling API errors here?"
"How are components typically structured in this project?"
"Where should I add the new feature I'm working on?"
โก Performance Optimization
๐ Context Management
Keep CLAUDE.md files concise to reduce token consumption
Use bullet points over paragraphs
Remove redundant information
Focus on actionable instructions
๐ฏ Targeted Prompts
Be specific about what you want Claude to focus on
Mention specific files or functions
Define clear success criteria
Break large tasks into smaller chunks
๐ฏ Remember the Goal
Claude Code is a tool to augment your development workflow, not replace your expertise. The best results come from combining Claude's capabilities with your domain knowledge and judgment.
๐ง Claude Code Extended Thinking & Ultrathink Mode: Complete Guide
Claude Code Extended Thinking is a powerful AI reasoning feature that allocates additional thinking tokens (4K, 10K, or 32K) for complex development tasks. The Claude ultrathink mode provides maximum reasoning capacity for system architecture, critical debugging, and complex refactoring. This comprehensive guide explains when to use Claude thinking mode and how to optimize Claude extended thinking for best results.
โก Quick Summary: Claude Extended Thinking
What: Claude extended thinking allocates extra reasoning tokens (4K-32K) for complex coding tasks
Critical: Extended thinking trigger phrases ("think", "think hard", "ultrathink") ONLY work in Claude Code CLI. They do NOT work in claude.ai web chat or direct API calls. The web interface and API require explicit parameters instead.
๐ฏ Claude Extended Thinking Token Allocation: 4K vs 10K vs 32K Tokens
Claude Code Extended Thinking offers three levels of thinking budget, triggered by natural language phrases in the CLI terminal:
Extended Thinking Comparison Table
Feature
Basic (4K)
Enhanced (10K)
Maximum (32K)
Trigger Phrases
"think"
"think hard", "megathink"
"ultrathink", "think harder"
Token Budget
4,000 tokens
10,000 tokens
32,000 tokens
Processing Time
5-15 seconds
15-45 seconds
45-180 seconds
Cost Per Task
~$0.06
~$0.15
~$0.48
Best Use Cases
Debugging, refactoring, code review
API design, database schema, optimization
System architecture, critical debugging, migrations
Logical Steps
3-5 steps
6-10 steps
10+ steps
โก Tier 1: Basic Thinking (4K tokens)
Trigger: "think"
Processing Time: 5-15 seconds
Cost: ~$0.06 per task
Best For:
Routine debugging and refactoring
Basic syntax analysis
Test case generation
Code reviews with checklists
Documentation writing
# Example usage
claude "Think about how to refactor this authentication module."
# Example usage
claude "Ultrathink about redesigning our data pipeline for 100x traffic."
๐ณ When to Use Claude Extended Thinking: Decision Tree for Developers
Simple Query (1-2 logical steps)
Examples: "Fix syntax error on line 42", "Format this JSON"
Recommendation: No extended thinking
Rationale: Basic tasks complete instantly without thinking. Extended thinking adds latency and cost without benefit, and can sometimes reduce accuracy.
Medium Complexity (3-5 logical steps)
Examples: "Refactor this class to use dependency injection", "Add error handling to this API endpoint"
Recommendation: Basic thinking (4K tokens) via "think"
Cost: ~$0.06 additional per task
Rationale: Standard mode with good prompts often sufficient, but basic thinking provides safety margin with ~15% accuracy improvement.
Complex Analysis (6-10 logical steps)
Examples: "Design a caching strategy", "Plan database migration from MongoDB to PostgreSQL"
Recommendation: Enhanced thinking (10K tokens) via "think hard"
Cost: ~$0.15 additional per task
Rationale: Multiple interconnected decisions benefit from structured reasoning. Community reports ~40% better architectural decisions.
Extremely Complex (10+ logical steps, high stakes)
Examples: "Redesign microservices architecture for 100x scale", "Debug race condition in distributed system"
Recommendation: Maximum thinking (32K tokens) via "ultrathink"
Cost: ~$0.48 additional per task
Rationale: Complex systems require comprehensive analysis. Justified when cost of error exceeds $5 or time saved exceeds 1 hour.
๐ป Claude Ultrathink CLI Examples: Real-World Development Tasks
# Interactive mode (recommended)
claude
> "Think about the best approach to implement rate limiting."
> "Megathink on whether we should use Redis or in-memory caching."
> "Ultrathink about our entire CI/CD pipeline optimization."
# Check costs regularly
> /cost
# Single command execution (print mode)
claude -p "Think. Explain the bugs in @src/api.ts"
# With explicit file context
claude "Think deeply. Read @api/routes.ts @api/handlers.ts and propose
a refactoring strategy to reduce coupling."
# System architecture redesign
claude "Ultrathink about migrating our monolith to microservices. Consider:
- Service boundaries and domain-driven design
- Data consistency patterns (saga vs 2PC)
- Deployment strategy and rollback procedures
- Backward compatibility during transition"
# Critical debugging session
claude "Ultrathink. We have a race condition in production.
Analyze @concurrency/ and identify potential deadlock scenarios."
โจ Claude Extended Thinking Best Practices for Cost Optimization
๐ Effective Usage Patterns
Start Conservative: Use "think" (4K) for most tasks, escalate only when needed
Monitor Costs: Check /cost regularly to track token consumption
Cache Optimization: Stick with one thinking level per session to preserve cache
Research โ Plan โ Implement: Use thinking for planning phase, standard mode for execution
Reserve Ultrathink: Save maximum thinking for architecture decisions and critical debugging only
Logarithmic Returns: Performance improvements follow logarithmic curve - going from 10K to 32K shows diminishing returns
๐ฏ Integration with Other Features
Plan Mode: Press Shift+Tab twice to enable plan mode, then use "ultrathink" for highest-quality architecture
Opus Plan Mode: Use Opus for planning with ultrathink, Sonnet for execution
Subagents: Create Task subagents that can use thinking modes independently
MCP Servers: Combine with GitHub MCP to analyze technical debt across repositories
Tab Toggle: Press Tab during any session to toggle extended thinking ON/OFF (v2.0.0+)
๐ฐ Cost Management
Individual Developer: $50-100/month for careful usage
Heavy User: $200/month (Claude Max subscription may be cost-effective)
Team Budget: $50-200 per developer/month depending on patterns
Keyboard Macro: Configure terminal to run /cost with quick keystroke (e.g., Cmd+K)
Cost-Benefit Rule: Reserve ultrathink for decisions where cost of error > $5 or time saved > 1 hour
๐ซ When NOT to Use Claude Extended Thinking: Common Mistakes
โ ๏ธ Anti-Patterns
Avoid extended thinking in these scenarios:
Well-Specified Tasks: If you can write detailed step-by-step instructions, standard mode is often sufficient
Iteration Speed Critical: Rapid prototyping where speed matters more than perfection
Budget Constraints: Development environments with strict token limits
Simple Data Transformation: Complex-looking but algorithmic tasks (sorting, filtering, mapping)
Already Correct Code: Code review without specific concerns wastes tokens on unnecessary analysis
Overthinking Simple Tasks: Extended thinking can make Claude MORE verbose and LESS accurate on basic tasks
๐ง How to Set Up Claude Extended Thinking in Your Project
Installation Requirements
Extended thinking works with Claude Code v2.0.0+
# Check version
claude --version
# Ensure v2.0.0+ for Tab toggle feature
npm install -g @anthropic-ai/claude-code
CLAUDE.md Integration
Document thinking guidelines in your project's CLAUDE.md:
# Thinking Mode Guidelines
- Use "think" for routine tasks and bug fixes
- Use "think hard" for API design and architecture
- Reserve "ultrathink" for system redesigns (requires approval)
# Budget Limits
Monthly team budget: $500
Per-session limit: $5
Custom Slash Commands
Create reusable commands with built-in thinking:
# Create .claude/commands/deep-analysis.md
echo "Ultrathink about this problem before proposing solutions.
Follow these steps:
1. Analyze the problem thoroughly
2. Consider multiple approaches with trade-offs
3. Evaluate security, performance, and maintainability
4. Recommend the best solution with detailed reasoning" > .claude/commands/deep-analysis.md
# Usage
/deep-analysis "How should we implement real-time notifications?"
โ ๏ธ Claude Extended Thinking Limitations: What You Need to Know
Platform-Specific Limitations
CLI Only: Trigger phrases only work in Claude Code CLI, not portable to other platforms
No Custom Budget Control: Locked to 4K/10K/32K tiers - no fine-grained control
Substring Matching Hazard: "I think we should..." accidentally triggers 4K budget
Tab Toggle Interaction: Unclear how Tab thinking mode interacts with keyword triggers (GitHub Issue #9072)
๐ฏ Real-World Success Stories
E-commerce Multi-tenancy: "Think hard" provided comprehensive analysis of data isolation, billing models, and security implications that standard mode missed
Reverse Proxy Deadlock: Standard mode gave confident but incorrect diagnosis; "ultrathink" correctly identified RWMutex locking issue
SWE-bench Performance: Extended thinking achieved 70.3% vs OpenAI o1's ~49% on verified benchmarks
18,000-line Refactoring: Successfully identified modularity patterns and generated plan, though token consumption exceeded expectations ($15-20 for 2.5 hour session)
๐ก Key Takeaway
Extended thinking is a powerful tool for complex problems, but it's not a silver bullet. Use it strategically for genuinely complex tasks where the cost of errors is high. For simple tasks, standard Claude is faster, cheaper, and often more accurate.
Cost-Benefit Threshold: Reserve ultrathink for decisions where cost of error > $5 or time saved > 1 hour.
โ Frequently Asked Questions: Claude Extended Thinking
What is Claude Code Extended Thinking?
Claude Code Extended Thinking is an AI reasoning feature that allocates additional thinking tokens (4K, 10K, or 32K) for Claude to analyze complex development problems more thoroughly. It works exclusively in Claude Code CLI terminal by detecting natural language trigger phrases like "think", "think hard", or "ultrathink" in your prompts.
How do I activate Claude Ultrathink mode?
To activate Claude Ultrathink (32K tokens), simply include the word "ultrathink" in your Claude Code CLI prompt. For example: claude "Ultrathink about migrating our monolith to microservices". Other trigger phrases include "think harder" and "think intensely". This ONLY works in Claude Code CLI, not in the web interface or direct API calls.
How much does Claude Extended Thinking cost?
Claude Extended Thinking costs vary by tier: Basic thinking (4K tokens) costs ~$0.06 per task, enhanced thinking (10K tokens) costs ~$0.15 per task, and maximum ultrathink (32K tokens) costs ~$0.48 per task. Use the /cost command in Claude Code CLI to monitor your token usage and expenses in real-time.
What's the difference between think, megathink, and ultrathink?
"Think" (4K tokens) is for routine debugging and refactoring tasks. "Megathink" or "think hard" (10K tokens) is for API design, database planning, and performance optimization. "Ultrathink" (32K tokens) is for system architecture redesigns, critical debugging, and complex migrations. Each level provides progressively more reasoning capacity and processing time.
Does Claude Extended Thinking work in the web browser?
No, Claude Extended Thinking trigger phrases ("think", "ultrathink", etc.) ONLY work in Claude Code CLI terminal. They do not work on claude.ai web chat or through direct API calls. The web interface and API require explicit extended_thinking parameters to be set programmatically instead.
When should I NOT use Extended Thinking?
Avoid Extended Thinking for simple syntax fixes, formatting tasks, well-specified problems with clear step-by-step instructions, and when iteration speed is critical. Extended thinking can actually make Claude MORE verbose and LESS accurate on basic tasks while adding unnecessary latency and cost.
Which Claude models support Extended Thinking?
Extended Thinking is supported by Claude 3.7 Sonnet, Claude 4 Opus, Claude 4 Sonnet, and Claude Sonnet 4.5. It is NOT supported by legacy models including Claude 3.5 Sonnet (older version), Claude 3.5 Haiku, Claude 3 Opus, or any Claude 2.x models.
How do I monitor Extended Thinking token usage?
Use the /cost command in Claude Code CLI to view your current token usage, costs, and detailed breakdown. You can set up a keyboard macro (like Cmd+K) to quickly check costs. Monitor regularly to stay within budget, especially when using ultrathink mode which consumes tokens rapidly.
Can I use Extended Thinking with custom slash commands?
Yes! Create custom commands in .claude/commands/ that include thinking triggers. For example, create a command file with "Ultrathink about this problem before proposing solutions" to automatically invoke extended thinking when the command is used. This helps standardize complex workflows across your team.