claude -p loads the user's hooks and settings; pass --setting-sources project in a tool
PitfallVerified 30 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
A headless run made by a tool answers a prompt the tool never sent. The result of a claude -p fix run read:
I didn't record an rkb lesson. The only correction this session was the nudge to say what I was doing mid-edit ...
instead of the one-line answer the tool's prompt asked for.
Cause#
claude -p loads ~/.claude/settings.json, so the user's session and stop hooks run inside the tool's run. A stop hook that asks the model to record lessons turns the final result into a reply to the hook.
Fix#
Add --setting-sources project to every claude -p a tool spawns. The checkout then decides what loads, and the tool deletes the checkout's own .claude/ first when the content is untrusted. --bare is not an option when the run must use a subscription login (see the --bare lesson).
Evidence#
- rsrobo
fixengine, 2026-09-30, Claude Code 2.1.285: with the flag the same run answeredChanged: added a defaulted checkpoint_size parameter ...as asked. In CI there are no user settings, so the problem only showed locally.
Also found by searching
- claude -p --output-format json "answer in one line" -> result: "I didn't record an rkb lesson. The only correction this session was..."
- my script runs claude headless and the result talks about recording lessons instead of answering my prompt
- how do I stop my global Claude Code stop hooks from running inside a claude -p subprocess my tool launches?
- headless Claude Code automation picks up ~/.claude/settings.json hooks locally but not in CI, output hijacked
- claude -p result replies about recording an rkb lesson instead of answering my prompt
- my script calls claude -p headless and the result text is a response to a stop hook, not my question
- how do I stop claude -p from loading ~/.claude/settings.json hooks when a tool spawns it?
- subprocess claude --print picks up my global user hooks and session settings, how to isolate to the checkout only