headless-claude
The flags that make
claude -pactually behave in scripts, agents, and cron.
python3 headless_claude.py "summarize CHANGES.md in 3 bullets" # prints the command (dry)
python3 headless_claude.py --apply "summarize CHANGES.md in 3 bullets" # runs it
python3 headless_claude.py --apply --cwd ~/proj "fix the failing test" # in a repo
Why these flags
A bare claude -p in an automated context can hang on a permission prompt, fire
your editor/notify/Stop hooks, and load your whole user memory (slow). For
unattended use you almost always want:
| flag | effect |
|---|---|
--setting-sources project |
don't load USER ~/.claude hooks/settings; skip auto-memory → fast, no side effects |
--permission-mode bypassPermissions |
no interactive approval gate — a script can't answer one |
neutral --cwd |
don't drag in a project's CLAUDE.md / file tree |
Escape hatches: --allow-hooks (keep your hooks), --safe (let it prompt). BYOK — uses
your logged-in plan, no API key.
Behavior
- Default: print the exact command (dry), exit 0.
--apply: run it, stream stdout. Missingclaude/ nonzero exit / timeout →FATAL+ exit 2.
Requires
- The
claudeCLI on PATH, logged in. No Python packages.