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.
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_THEMEoverridden 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 useon shell start (was checking for.nvmrcevery time)
Results
| Metric | Before | After | Improvement |
|---|---|---|---|
| Startup | ~5.0s | ~0.6s | 8x faster |
| Lines | 197 | 81 | 59% smaller |
Takeaways
- Benchmark first — You can’t improve what you don’t measure
- Lazy load heavy tools — nvm and jenv don’t need to run on every shell
- Keep backups — One command away from reverting
- 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:
Review my ~/.zshrc for issues, redundancies, and performance problemsBenchmark my current zsh startup timeOptimize for fast startup: lazy-load what you can, remove dead code, keep it minimal. Create a backup first.