Fix: Claude Code Tool Execution Timed Out Error
How to handle and prevent tool execution timeout errors in Claude Code.
You’re running a command and suddenly:
Error: Tool execution timed out after 120000ms
The operation took too long and Claude gave up.
Why This Happens
Claude Code has timeouts to prevent hanging:
| Operation | Default Timeout |
|---|---|
| Bash commands | 120 seconds |
| File reads | 30 seconds |
| Network requests | 30 seconds |
If an operation exceeds its timeout, it’s killed.
Common Causes
1. Long-running commands
# These can timeout
npm install # Large dependencies
npm run build # Complex builds
npm test # Full test suites
2. Large file operations
# May timeout on huge files
cat very-large-file.log
3. Network-dependent operations
# Can timeout on slow networks
npm install from-remote-registry
curl slow-api.example.com
4. Infinite loops
Code that never completes:
while true; do echo "forever"; done
Solutions
1. Run commands directly
For long operations, run them yourself:
# In your terminal (not through Claude)
npm install
npm run build
npm test
Then return to Claude:
The build completed successfully. Now let's review the output.
2. Break up large operations
# Instead of
Run all tests
# Do this
Run tests for the auth module only
3. Use background execution
Run npm test in the background
Claude will start it and move on without waiting.
4. Request streaming output
Run npm install and show output as it happens
Sometimes seeing progress helps identify where it’s stuck.
Increasing Timeouts
Per-command timeout
Some commands support custom timeouts in CLAUDE.md:
## Long-running commands
- `npm install` may take up to 5 minutes
- `npm run build` may take up to 10 minutes
Settings configuration
In .claude/settings.json:
{
"timeouts": {
"bash": 300000,
"read": 60000
}
}
This increases bash timeout to 5 minutes.
Preventing Timeouts
1. Use faster alternatives
# Instead of npm install
npm ci # Faster for CI, uses lockfile
# Instead of full test suite
npm test -- --bail # Stop on first failure
2. Limit scope
# Instead of
find / -name "*.log"
# Do this
find ./logs -name "*.log"
3. Add progress indicators
For scripts, add output:
#!/bin/bash
echo "Starting build..."
npm run build
echo "Build complete"
The output keeps the connection alive.
4. Split into steps
# Instead of
Build and deploy everything
# Do this
Step 1: Run npm run build
Step 2: Run npm test
Step 3: Run ./deploy.sh
Each step gets its own timeout.
Handling Timeout Gracefully
Check if operation completed
After a timeout:
Check if npm install completed successfully
Sometimes it finishes but times out reporting.
Resume from where it stopped
The build timed out at the test phase.
Resume from running tests.
Manual intervention
For operations that always timeout:
This command will take too long for Claude.
Please run in your terminal:
npm run full-test-suite
Then tell me the results.
Debug Long Operations
Find what’s slow
# Time each step
time npm install
time npm run build
time npm test
Check for hangs
# Run with verbose output
npm install --verbose
Monitor progress
# Watch for activity
npm run build 2>&1 | tee build.log
Quick Fixes
| Problem | Solution |
|---|---|
| npm install timeout | Run directly in terminal |
| Test suite timeout | Run tests in batches |
| Build timeout | Use incremental builds |
| File read timeout | Read smaller chunks |
| Script timeout | Add progress output |
Settings Reference
{
"timeouts": {
"bash": 120000,
"read": 30000,
"write": 30000,
"network": 30000
}
}
All values in milliseconds.
When Timeouts Are Good
Timeouts protect you from:
- Runaway processes
- Infinite loops
- Hung network requests
- Resource exhaustion
Don’t set timeouts too high. Better to run long operations manually than risk hanging Claude.