7 Ways to Speed Up Claude Code: Performance Optimization Guide

Speed up Claude Code with 7 proven techniques — from project configuration and context optimization to model selection and hardware tips.

·9 min read

Why Claude Code Feels Slow

Claude Code is a powerful AI coding agent, but it can be slow — especially on large projects or complex tasks. The good news: most slowdowns are fixable with configuration changes and workflow adjustments.

This guide covers 7 proven ways to speed up Claude Code, from quick wins to advanced optimizations.

---

#1: Exclude Unnecessary Files from Indexing

This is the single biggest performance gain for most users. Claude Code scans your project directory at startup, and if it's wading through node_modules, build output, or dependency caches, it'll be slow.

Quick Fix: Add ignorePatterns

Create or edit .claude/settings.json:

{
  "ignorePatterns": [
    "node_modules/**",
    ".next/**",
    "dist/**",
    "build/**",
    "coverage/**",
    "*.log",
    "cache/**",
    ".git/**",
    "vendor/**",
    "*.min.js",
    "*.min.css"
  ]
}

Before/After Benchmark

| Project Size | Without ignorePatterns | With ignorePatterns | Speed Gain | |-------------|----------------------|-------------------|------------| | Small (< 500 files) | 3-5s startup | 1-2s startup | 2-3x faster | | Medium (2K-5K files) | 15-30s startup | 2-5s startup | 5-10x faster | | Large (10K+ files) | 60s+ startup | 3-8s startup | 10-20x faster |

> 💡 Pro tip: Run find . -type f | wc -l to see how many files Claude is scanning. Anything over 5,000 is a red flag.

External Links: - Claude Code Settings Reference — full settings documentation

---

#2: Use the Right Model for Your Task

Claude Code supports multiple models. Faster ≠ worse for many tasks.

Model Selection Guide

| Task | Recommended Model | Speed | Quality | |------|------------------|-------|---------| | Simple refactoring | Haiku 3.5 | ⚡ Fastest | ✅ Good | | Code generation | Sonnet 4 | ⚡ Fast | 🏆 Best balance | | Code review | Sonnet 4 | ⚡ Fast | 🏆 Best output | | Complex architecture | Opus 4 | 🐢 Slow | 🏆 Best reasoning | | Quick edits | Haiku 3.5 | ⚡ Fastest | ✅ Good enough | | Documentation | Haiku 3.5 | ⚡ Fastest | ✅ Excellent |

How to Switch Models

# Use Haiku for fast, simple tasks
claude --model claude-haiku-3-5-20241022

# Use Sonnet for everyday coding (default) claude --model claude-sonnet-4-20250514

# Use Opus for complex reasoning claude --model claude-opus-4-20250514

Or set a default model in .claude/settings.json:

{
  "model": "claude-sonnet-4-20250514"
}

> 💡 Pro tip: Start complex tasks with Opus, then switch to Haiku for iterations. Use Haiku for 80% of your daily work.

External Links: - Anthropic Models Overview — comparison of speed/capability - Anthropic API Pricing — understand cost vs speed

---

#3: Reduce Context Size

Claude Code's speed is inversely proportional to context size. More context = slower responses.

Before Starting a Session

# See how large your project is
find . -name ".ts" -o -name ".tsx" -o -name ".js" -o -name ".jsx" | xargs wc -l | tail -1
# If >50,000 lines of code, you'll benefit from context reduction

Strategies for Smaller Context

| Strategy | Time Saved | Effort | |----------|-----------|--------| | Use @file references instead of read command | 30-50% | Low | | Start fresh sessions per feature | 20-40% | Low | | Remove irrelevant context from CLAUDE.md | 10-20% | Medium | | Split large files (< 500 lines) | 15-25% | Medium | | Use ignorePatterns (see #1) | 50-80% | Low |

Practical Example: The 80/20 Context Rule

Instead of:

Read the entire src/ directory and tell me how to improve error handling

Try:

@src/lib/api-client.ts @src/middleware.ts — review error handling in these two files

The second approach uses a fraction of the context and gets you a more focused answer.

---

#4: Use --print Mode for One-Shot Queries

The terminal UI with WebSockets has overhead. For quick questions or tasks, use --print mode:

# Regular mode (slower, with UI):
claude "Add error handling to src/api/users.ts"

# Print mode (faster, no UI): claude --print "Add error handling to src/api/users.ts"

When to Use --print

| Use Case | Mode | Why | |----------|------|-----| | Quick code generation | --print | No UI overhead | | One-shot refactoring | --print | Start and get answer | | Script/integration | --print | Machine-readable output | | Complex multi-step | Regular | Need conversation | | Debugging sessions | Regular | Need back-and-forth | | File edits with review | Regular | Need diff feedback |

---

#5: Set Up Keyboard Shortcuts and Scripts

Speed isn't just about the AI — it's about your workflow.

Alias for Fast Startup

Add to your shell profile:

# ~/.zshrc or ~/.bashrc

# Quick Claude Code - Haiku for speed alias cq='claude --model claude-haiku-3-5-20241022 --print'

# Full Claude Code session alias cl='claude'

# Claude Code with explicit project alias clp='claude --projectRoot .'

# Quick task with file scope quick_task() { if [ -z "$1" ]; then echo "Usage: qt 'your prompt here'" return 1 fi claude --model claude-haiku-3-5-20241022 --print "$1" } alias qt='quick_task'

Usage

# Fast one-shot
cq "Generate a type for User with id, name, email, and role"

# Quick task using alias qt "@src/store.ts add undo/redo to the state manager"

---

#6: Optimize Your Hardware

Claude Code is cloud-based, so hardware matters less for inference speed. But it matters for startup time and file processing.

Hardware Checklist

| Component | Impact | Recommendation | |-----------|--------|---------------| | CPU | File indexing speed | Modern multi-core (Intel i5+/Apple M1+) | | RAM | Large project handling | 16GB minimum, 32GB recommended | | SSD | File read speed | NVMe SSD > SATA SSD > HDD | | Network | API response time | >50Mbps, <50ms latency to Anthropic API |

Network Speed Test

# Test latency to Anthropic API
time curl -s -o /dev/null https://api.anthropic.com

# Test actual API speed time claude --print "Write 'hello' in Python" 2>&1 # Should take <5 seconds for simple prompts on Haiku

If your API requests are consistently slow, check: - Are you on Wi-Fi vs ethernet? - Is your VPN adding latency? - Are you geographically far from Anthropic's nearest region?

---

#7: Optimize Your Prompts

Prompt quality directly affects performance. A clear, specific prompt gets a faster, better response.

Before (Slow, Vague):

Fix my code

(Claude has to read your entire project, guess what needs fixing, and produce a broad response.)

After (Fast, Specific):

@src/utils/validation.ts — line 45-67: The regex for email validation allows invalid emails. 
Fix it to use a proper email regex that:
1. Requires @ symbol
2. Requires a domain with at least one dot
3. Rejects spaces

This prompt leads to: - Less context needed (only one file) - Less guessing (specific problem) - Faster response (narrow scope) - Better result (clear requirements)

The FAST Prompt Formula

| Element | Example | |---------|---------| | File | @src/utils/validation.ts | | Area | line 45-67 | | Symptom | Regex allows invalid emails like "test@test" | | Task | Fix with proper regex that validates correctly |

FAST prompts are 2-3x faster than vague prompts and produce better results.

---

Performance Benchmarks

| Optimization | Speed Gain | Effort | Applies To | |-------------|-----------|--------|------------| | ignorePatterns | 2-10x | Low | All projects | | Right model choice | 2-5x | Low | All tasks | | Reduce context | 1.5-3x | Medium | Large projects | | --print mode | 1.5-2x | Low | One-shot tasks | | Optimized prompts | 2-3x | Low | All tasks | | Hardware upgrade | 1.5-2x | High | Old machines | | Keyboard shortcuts | 1.2-1.5x | Low | Daily use |

---

Quick Start: My Fast Claude Code Setup

Copy this .claude/settings.json to get started:

{
  "model": "claude-sonnet-4-20250514",
  "ignorePatterns": [
    "node_modules/**",
    ".next/**",
    "dist/**",
    "build/**",
    "coverage/**",
    "*.log",
    "cache/**",
    ".git/**",
    "vendor/**",
    "*.min.js",
    "*.min.css"
  ],
  "permissions": {
    "allowPaths": ["src/"]
  }
}

And add these aliases to your shell profile:

# Fast Claude Code (one-shot)
alias cq='claude --model claude-haiku-3-5-20241022 --print'
# Full session
alias cl='claude'

Related Articles: - Claude Code Memory Systems Explained — optimize context usage - Effective Claude Code Prompts — write faster prompts - Fix: Claude Code Not Working with Your Project — resolve slow-down issues - Claude Code Hooks Automation Guide — automate performance optimizations

Ad Unit Placeholder

Related Articles