The Error

Command timed out after 120000ms

The Fix

# When invoking long-running commands, set a longer timeout (up to 600000ms)
# In your prompt, instruct Claude to use the timeout parameter:

# Example: for a build that takes 3 minutes
# Tell Claude: "Run the build with a 300000ms timeout"

# Or use background execution for commands that don't need immediate output:
# Tell Claude: "Run this in the background"

Why This Works

Claude Code’s Bash tool defaults to a 120-second (120000ms) timeout. Commands like npm install on large projects, full test suites, or Docker builds regularly exceed this. The timeout parameter accepts values up to 600000ms (10 minutes), and background execution removes the limit entirely by running asynchronously.

If That Doesn’t Work

# Break the command into smaller chunks
npm install --prefer-offline  # faster, uses cache
npx jest --testPathPattern="src/module"  # subset of tests

# Or split a large build:
tsc --noEmit --project tsconfig.json 2>&1 | head -50

Splitting work into bounded operations keeps each call under the timeout ceiling.

Prevention

Add to your CLAUDE.md:

For commands expected to exceed 60 seconds (builds, full test suites, large installs), always specify timeout: 300000 or use background execution. Never rely on the default 120s timeout for CI-scale operations.