[BUG] claude -p headless invocations consistently time out via launchd (macOS) — "API Error: The operation timed out."
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When running claude -p as a subprocess from a launchd job on macOS, the process hangs for 10–20+ minutes and then fails with no output files. The same prompt works correctly when run interactively in a
Claude Code session.
Environment:
- macOS (Darwin 25.5.0)
- Claude Code CLI, invoked via launchd plist as a scheduled job
- Model: claude-sonnet-4-6
Steps to reproduce:
- Create a launchd plist that runs claude -p "..." --dangerously-skip-permissions --allowedTools "..." on a schedule
- Trigger the job (either by schedule or via launchctl start)
- Monitor the log
Expected behavior:
The command completes and writes output within a few minutes.
Actual behavior:
The process stays alive for 10–20+ minutes, produces no output, then exits with this error in the log:
API Error: The operation timed out.
What I tried:
- Added --dangerously-skip-permissions to rule out permission prompt hangs — no change
- Split the prompt into two separate claude -p calls (a "pull" phase and a "narrate" phase) to reduce complexity — both phases still time out
- Running the same prompt interactively in a Claude Code session succeeds immediately
Impact:
Automated/scheduled use of claude -p is unreliable. Any workflow that depends on headless claude -p execution via launchd (or likely cron) cannot be trusted to complete.
What Should Happen?
Expecting the script to call the MCP pull the data, and then return it for processing and building a narrative around the data.
Error Messages/Logs
Steps to Reproduce
Steps to reproduce:
- Create a launchd plist that runs claude -p "..." --dangerously-skip-permissions --allowedTools "..." on a schedule
- Trigger the job (either by schedule or via launchctl start)
- Monitor the log
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.179 (Claude Code)
Platform
AWS Bedrock
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
_No response_
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗