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 SizeWithout ignorePatternsWith ignorePatternsSpeed Gain
Small (< 500 files)3-5s startup1-2s startup2-3x faster
Medium (2K-5K files)15-30s startup2-5s startup5-10x faster
Large (10K+ files)60s+ startup3-8s startup10-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

TaskRecommended ModelSpeedQuality
Simple refactoringHaiku 3.5⚡ Fastest✅ Good
Code generationSonnet 4⚡ Fast🏆 Best balance
Code reviewSonnet 4⚡ Fast🏆 Best output
Complex architectureOpus 4🐢 Slow🏆 Best reasoning
Quick editsHaiku 3.5⚡ Fastest✅ Good enough
DocumentationHaiku 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

StrategyTime SavedEffort
Use @file references instead of read command30-50%Low
Start fresh sessions per feature20-40%Low
Remove irrelevant context from CLAUDE.md10-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 CaseModeWhy
Quick code generation--printNo UI overhead
One-shot refactoring--printStart and get answer
Script/integration--printMachine-readable output
Complex multi-stepRegularNeed conversation
Debugging sessionsRegularNeed back-and-forth
File edits with reviewRegularNeed 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

ComponentImpactRecommendation
CPUFile indexing speedModern multi-core (Intel i5+/Apple M1+)
RAMLarge project handling16GB minimum, 32GB recommended
SSDFile read speedNVMe SSD > SATA SSD > HDD
NetworkAPI 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

ElementExample
File@src/utils/validation.ts
Arealine 45-67
SymptomRegex allows invalid emails like "test@test"
TaskFix with proper regex that validates correctly
FAST prompts are 2-3x faster than vague prompts and produce better results.

---

Performance Benchmarks

OptimizationSpeed GainEffortApplies To
ignorePatterns2-10xLowAll projects
Right model choice2-5xLowAll tasks
Reduce context1.5-3xMediumLarge projects
--print mode1.5-2xLowOne-shot tasks
Optimized prompts2-3xLowAll tasks
Hardware upgrade1.5-2xHighOld machines
Keyboard shortcuts1.2-1.5xLowDaily 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

Related Articles