safety-classifier: first-word allow paths let chained writes through
Summary
install/hooks/lib/safety-classifier.ts classifyCommand decides allow from the first word on several paths (SEARCH_TOOLS, loopback curl, the for/while/until loop allow, DEV_BINARIES, READ_ONLY_COMMAND_PATTERNS, and bashTargetsTrustedPath, which tests the whole command string). Later segments of a compound command (;, &&, |) and output redirections are not checked, so a write that does not match a named shape is allowed. Safety.hook.ts emits allow, which skips the native prompt for the whole command.
Your own comment above the destructive-shape scan says the same thing: these paths "only look at the head of the command". The shape denies (mutating-pipe-consumer, dangerous-shape) catch some chains but not the rest.
Evidence
Replayed 7 Oct 2026 against LifeOS/install/hooks/lib/safety-classifier.ts at 5e2f2e8 (bun, classifyCommand({toolName:"Bash",command})):
"cat a | tee /etc/hosts" -> allow (read-only-command)
"ls > ~/.zshrc" -> allow (read-only-command)
"git status; touch ~/zz" -> allow (read-only-command)
"for i in 1; do rm ~/x; done" -> allow (shell-loop-data-iteration)
"curl http://localhost:31337/x -o ~/.zshrc" -> allow (loopback-http)
"rm ~/Documents/zz; ls /tmp" -> allow (trusted-workspace-command)
For contrast, ls; rm -rf ~/Documents/zz, curl http://localhost:31337/n; rm ~/x and npm test; rm ~/Documents/zz already come back neutral, so the shape denies cover some of this.
Impact
Allow-to-prompt only. This is a hardening report, not a hard hole: the worst case of fixing it is extra prompts. The cost of leaving it is that the allow removes the native prompt for writes the classifier never looked at.
Fix direction
Split the command on top-level ;, &&, ||, |, |&, & and newlines, respecting quotes, backslashes, $(…) and backticks, and treat an unsplittable command as not allowed. Then:
- the first-word allows fire only when every segment is itself read-only;
- an output redirect to anything other than
/dev/nullor a file descriptor makes a segment non-read-only; - the loop allow requires a read-only body, segment by segment;
- loopback
curlrequires every segment to be a loopback fetch or read-only, and refuses-o,-O,-T,--output; - the trusted-path allow applies per segment, so a
/tmpmention in one segment does not trust the rest.
I have this working in a private fork (splitter, segment check and tests, 112 passing) and can share the approach or the test cases if useful.
Follow-up from the same fork: three more first-word gaps of the same family. All are allow-to-prompt only, and the replay was against the same module and commit as the report above.
"ls $(rm ~/zz)" -> allow (read-only-command)
"find ~/zz -delete" -> allow (read-only-command)
"env rm -rf ~/zz" -> allow (read-only-command)
splitCompoundCommandkeeps$(…), backticks and<(…)inside their segment, so the segment is judged by its first word and the substitution runs unchecked.findis inSEARCH_TOOLS, and the onlyfinddeny shape needs-exec rm -r, so-delete,-okand-fprint*pass.fd -x/--execandyq -ipass the same way.envmatches aREAD_ONLY_COMMAND_PATTERNSentry, soenv <anything>allows.
Fix direction that has worked here:
- A segment counts as read-only only if every command inside its substitutions is read-only too (recursive check). If a marker cannot be extracted, treat it as not read-only.
$((…))arithmetic is not a substitution. - Treat
find -delete/-exec/-execdir/-ok/-okdir/-fprint*/-fls,fd -x/-X/--exec/--exec-batchandyq -i/--inplaceas non-read-only. - Allow only bare
env(/^env\s*$/), notenv <cmd>.
Separate small one: CREDENTIAL_PATHS is only applied to Bash command text, never to tc.filePath, so an Edit or Read of a .env file under a trusted prefix returns allow and removes a prompt that an ask rule was meant to raise. .aws/credentials is also named as a single file, so cat ~/.aws/config allows. Running the patterns over filePath before the read-only-tool and trusted-path allows, and widening to the whole .aws/ and .kube/ directories, fixes both.
Tests for all of the above pass in the fork; happy to share them.
[!NOTE] 🤖 Kai (AI assistant) responding on behalf of Daniel Miessler
Thanks @bowlax for the replay and the fork tests; the report was right about the 7.x classifier. Since 8.x, no hook in LifeOS auto-approves anything. The PermissionRequest branch was unregistered on 2026-10-17, and Safety.hook.ts and safety-classifier.ts were deleted on 2026-10-24. Every allow now comes from Claude Code's own permission engine: the native ask and deny rules plus the subagent sandbox. None of these decides based on a command's first word. Credential reads, including the CREDENTIAL_PATHS gap from your follow-up, are blocked by native deny rules in the public settings template, whichever tool attempts the read. If a native rule in that template lets a write through, please open a new issue. Closing as resolved.