Mahesh Jaganiya

How I Cut My Zsh Startup Time from 5s to 0.6s Using Claude Code

A quick guide to optimizing zsh configuration for faster terminal startup using lazy loading and removing dead code.

#terminal#zsh#performance#claude-code

My terminal was sluggish. Every new tab took forever. I finally decided to fix it.

The Problem

I asked Claude Code to review my zsh config:

Review my ~/.zshrc for issues, redundancies, and performance problems

It immediately spotted issues:

  • Duplicate BUN_INSTALL blocks
  • Dead ZSH_THEME overridden by Powerlevel10k
  • Synchronous nvm and jenv loading
  • 100+ lines of commented boilerplate

Benchmarking

Before making changes, I needed numbers:

Benchmark my current zsh startup time

Claude ran this:

for i in 1 2 3 4 5; do /usr/bin/time zsh -i -c exit; done

Before: ~5.0 seconds average. Ouch.

The benchmark also revealed a gitstatus initialization error that was causing timeouts—something I never noticed in normal usage.

The Fix

Optimize for fast startup: lazy-load what you can, remove dead code, keep it minimal. Create a backup first.

Claude created ~/.zshrc.backup then rewrote the config.

Key Optimizations

1. Lazy load nvm (biggest win, ~500ms saved)

# Instead of loading nvm on every shell start...
export NVM_DIR="$HOME/.nvm"
nvm() {
  unset -f nvm node npm npx
  [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
  [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
  nvm "$@"
}
node() { nvm --version >/dev/null 2>&1; unset -f node; node "$@"; }
npm() { nvm --version >/dev/null 2>&1; unset -f npm; npm "$@"; }
npx() { nvm --version >/dev/null 2>&1; unset -f npx; npx "$@"; }

nvm only loads when you actually use node, npm, nvm, or npx.

2. Lazy load jenv (~100ms saved)

jenv() {
  unset -f jenv
  eval "$(command jenv init -)"
  jenv "$@"
}

3. Enable DISABLE_UNTRACKED_FILES_DIRTY

DISABLE_UNTRACKED_FILES_DIRTY="true"

Faster git status checks in large repos—your prompt updates quicker.

4. Remove the cruft

  • Deleted duplicate PATH exports
  • Removed 100+ lines of commented oh-my-zsh boilerplate
  • Removed auto nvm use on shell start (was checking for .nvmrc every time)

Results

MetricBeforeAfterImprovement
Startup~5.0s~0.6s8x faster
Lines1978159% smaller

Takeaways

  1. Benchmark first — You can’t improve what you don’t measure
  2. Lazy load heavy tools — nvm and jenv don’t need to run on every shell
  3. Keep backups — One command away from reverting
  4. Remove dead code — Those commented lines aren’t helping anyone

The whole process took about 5 minutes with Claude Code. My terminal is snappy again.


Prompts used:

  1. Review my ~/.zshrc for issues, redundancies, and performance problems
  2. Benchmark my current zsh startup time
  3. Optimize for fast startup: lazy-load what you can, remove dead code, keep it minimal. Create a backup first.