[BUG] `claude --agent <name> --print` hangs indefinitely on cold start with local agents
[BUG] claude --agent <name> --print hangs indefinitely on cold start with local agents
Summary
claude --agent <name> --print with a local agent (.claude/agents/) hangs indefinitely on the first invocation from a given directory. Running claude --print without --agent from the same directory first "warms it up", after which the --agent run succeeds. The warmup is per-directory — warming up directory A does not help directory B within the same project.
Environment
- Claude Code Version: 2.1.39
- Platform: Linux (Ubuntu 24.04)
Minimal Reproduction
Setup
mkdir -p /tmp/test-repo/.claude/agents
cd /tmp/test-repo && git init
cat > .claude/agents/greeter.md << 'EOF'
---
name: greeter
description: Simple test agent
model: haiku
---
Always start your response with "I AM THE GREETER AGENT."
EOF
Step 1: --agent --print hangs on cold start
cd /tmp/test-repo
echo "Say hello" | timeout 30 claude --agent greeter --model haiku --print
# Exit code 124 (timeout). Zero output.
Step 2: --print without agent works fine
cd /tmp/test-repo
echo "Say hello" | timeout 30 claude --model haiku --print
# Works. Produces output.
Step 3: --agent --print now works from same directory
cd /tmp/test-repo
echo "Say hello" | timeout 30 claude --agent greeter --model haiku --print
# Works! "I AM THE GREETER AGENT. Hello! ..."
Step 4: warmup is per-directory
mkdir -p /tmp/test-repo/subdir
# Warmup from subdir:
cd /tmp/test-repo/subdir
echo "hi" | timeout 30 claude --model haiku --print # works
# Agent from a DIFFERENT subdir:
mkdir -p /tmp/test-repo/other
cd /tmp/test-repo/other
echo "hi" | timeout 30 claude --agent greeter --model haiku --print
# HANGS — warmup from subdir/ did not help other/
Reproduction Rate
- Cold
--agent --print: 100% hang (3/3 automated, many manual) - After same-directory warmup: 100% success
- Cross-directory warmup: does not help (still hangs)
Debug Log Analysis
Using --debug-file, the hanging run stops at:
2026-02-12T00:27:50.137Z [DEBUG] [STARTUP] Commands and agents loaded in 106ms
Then nothing for 29s until timeout kills it:
2026-02-12T00:28:19.291Z [DEBUG] Getting matching hook commands for SessionEnd with query: other
A working run (after warmup) continues immediately:
2026-02-12T00:12:00.410Z [DEBUG] [STARTUP] Commands and agents loaded in 96ms
2026-02-12T00:12:00.410Z [DEBUG] [LSP MANAGER] initializeLspServerManager() called
2026-02-12T00:12:00.419Z [DEBUG] [STARTUP] MCP configs loaded in 199ms
...
2026-02-12T00:12:00.822Z [DEBUG] Stream started - received first chunk
The hang occurs right after agent loading, before LSP/MCP initialization begins.
What doesn't help
--disable-slash-commands— still hangs--dangerously-skip-permissions— still hangs--allowedTools— still hangs--debug-file— still hangs (but captures useful logs)
Impact
Breaks all scripted --agent --print workflows (batch judging with xargs, CI pipelines, etc.). The only workaround is to run a dummy claude --print (no agent) from each directory before the real --agent invocation, which is fragile and adds latency.
Possibly Related
- #21600 —
claude -phangs with.claude/skills/SKILL.md(similar symptom but different root cause —--disable-slash-commandsdoesn't fix ours) - #23265 — cold-start first invocation failure pattern
🤖 Generated with Claude Code
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗