Claude Code Best Practices Guide

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

๐Ÿง  /memory

View and manage project memory

# View current memory/context /memory # Edit memory settings /memory edit # Optimize memory usage /memory optimize

๐Ÿ“ Project & File Management

๐ŸŒณ /tree

Display project directory structure

# 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

๐Ÿ” /structure

Analyze and explain project structure

# Analyze project structure /structure # Claude identifies: # - Architecture patterns # - Design principles # - Code organization # - Development practices

๐Ÿ’ป /ide

Connect with IDE integration

# Connect to IDE /ide # Enables Claude to: # - See open files # - Read linter warnings # - Access IDE context # - Fix issues directly

๐Ÿ”ง Development Tools

๐Ÿ‘€ /review

Code review and analysis

# Review code for issues /review # Get feedback on: # - Security vulnerabilities # - Performance optimizations # - Code style compliance # - Bug detection

๐ŸŽฏ /task

Spawn sub-agents for parallel work

# Create focused sub-agent /task # Parallel execution: # - Independent context # - Same tool access # - Focused objectives # - Context isolation

๐Ÿ”Œ /mcp

Manage MCP servers and integrations

# 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):

{ "mcp": { "servers": { "puppeteer": { "command": "npx", "args": ["@anthropic-ai/mcp-server-puppeteer"] }, "sentry": { "command": "npx", "args": ["@anthropic-ai/mcp-server-sentry"], "env": { "SENTRY_AUTH_TOKEN": "your-token" } } } } }

Debug Configuration

Use debug flags to identify configuration issues:

# Launch with MCP debugging claude --mcp-debug # Use verbose mode for detailed output claude --verbose

โš ๏ธ Permission Best Practices

Start with conservative permissions and gradually allow more tools as you become comfortable with Claude's behavior in your environment.

๐Ÿ“ CLAUDE.md Files

CLAUDE.md is a special file that Claude automatically pulls into prompts to provide project-specific context and instructions.

๐Ÿ“‚ File Hierarchy

Claude reads CLAUDE.md files in priority order:

  1. User's home directory (~/.claude/CLAUDE.md)
  2. Project root directory
  3. Current working directory
  4. Parent directories (walking up the tree)

๐Ÿ’ก Local vs Shared Files

  • CLAUDE.md - Shared team configuration (commit to git)
  • CLAUDE.local.md - Personal settings (add to .gitignore)
  • Use local files for personal preferences and credentials
  • Use shared files for team standards and project info

โœจ Essential Components

๐Ÿ› ๏ธ Tech Stack

Declare tools, frameworks, and versions used in your project

# Tech Stack - Node.js 18+ - React 18.2 - TypeScript 5.0 - Tailwind CSS 3.4

๐Ÿ“ Project Structure

Outline key directories and their purposes

# Project Structure - src/components/ - Reusable UI components - src/lib/ - Core business logic - src/pages/ - Next.js pages - tests/ - Test files

โšก Key Commands

List important scripts and commands

# 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"

Pro Tip: Use keywords like "think hard" or "ultrathink" to extend Claude's reasoning time for better planning. Learn more about Extended Thinking modes โ†’

โšก Implementation Phase

Execute the plan with verification steps:

"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"] } }

๐Ÿš€ 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

# Add to .mcp.json { "servers": { "puppeteer": { "command": "npx", "args": ["@anthropic-ai/mcp-server-puppeteer"] } } }

๐Ÿ“Š Error Monitoring

Connect to Sentry for error analysis and debugging

# Add to .mcp.json { "servers": { "sentry": { "command": "npx", "args": ["@anthropic-ai/mcp-server-sentry"], "env": { "SENTRY_AUTH_TOKEN": "your-token" } } } }

๐Ÿ’ก Pro Tips

๐ŸŽฏ Iteration and Improvement

The 2-3 Iteration Rule

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
  • Trigger Phrases: "think" (4K), "think hard" / "megathink" (10K), "ultrathink" (32K)
  • CLI Only: Extended thinking triggers ONLY work in Claude Code CLI terminal, not web or API
  • Cost: $0.06 (basic) to $0.48 (ultrathink) per task - use /cost to monitor
  • Best For: Architecture design, complex debugging, migration planning, refactoring
  • Avoid For: Simple syntax fixes, formatting, well-specified tasks with clear steps

โš ๏ธ TERMINAL-ONLY FEATURE

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."

โšกโšก Tier 2: Enhanced Thinking (10K tokens)

Triggers: "think hard", "megathink", "think deeply"

Processing Time: 15-45 seconds

Cost: ~$0.15 per task

Best For:

  • API architecture design
  • Database schema planning
  • Performance optimization
  • Migration strategies
  • Complex algorithmic problems
# Example usage claude "Think hard about migrating our REST API to GraphQL."

โšกโšกโšก Tier 3: Maximum Thinking (32K tokens)

Triggers: "ultrathink", "think harder", "think intensely"

Processing Time: 45-180 seconds

Cost: ~$0.48 per task

Best For:

  • System architecture redesign
  • Critical migration strategies
  • Debugging race conditions
  • Novel algorithm development
  • Refactoring 10,000+ line components
# 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
  • Cache Invalidation: Changing thinking modes mid-session breaks cache and increases costs
  • No Thinking Visibility: Thinking process removed in v2.0.0 (previously showed colored text)
  • Context Window Exhaustion: Extended thinking fills context window quickly, Claude may forget earlier conversation parts

Model Requirements

Models Supporting Extended Thinking:

  • โœ… Claude 3.7 Sonnet
  • โœ… Claude 4 Opus
  • โœ… Claude 4 Sonnet
  • โœ… Claude Sonnet 4.5

NOT Supported: Claude 3.5 Sonnet (legacy), Claude 3.5 Haiku, Claude 3 Opus, all Claude 2.x models

Known Issues

  • Token Consumption Spikes: Ultrathink can cause token count to spike above 1.2M with no output (GitHub Issue #1194)
  • Redacted Thinking Blocks: Topics involving child safety, cyber attacks, or weapons may have thinking encrypted/hidden
  • Failed Diffs: Manual file edits during session invalidate cache, causing expensive re-processing
  • 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.