Repository navigation
Description
What happened
LifeOSHooks sandbox breaks subagent Bash in auto mode
Summary
Environment: LifeOS 8.761.0, Claude Code 2.1.322, macOS, auto mode, LIFEOS_SUBAGENT_SANDBOX=on, LifeOSHooks plugin loaded.
Problem. The plugin rewrites a subagent's Bash call into a sandbox-exec wrap after the auto-mode classifier has reviewed it. Claude Code then refuses the call: "a hook changed this call's input after auto mode reviewed it". Re-issuing the rewritten command, as the refusal suggests, fails the same way, because it gets wrapped again. Calls the classifier does not review (echo) still run. Git, tests and file writes do not, so subagents cannot do shell work in auto mode.
Cause. pluginPlan (the bridge's plan op) in hooks/SubagentGitSandbox.hook.ts always returns wrapInline(wrap, profile). Nothing recognises a command that is already that exact wrap.
Suggested fix. Treat a command that is exactly wrapInline(inner, profile) for the current profile as already sandboxed: return it unchanged, and give inner to the classic PreToolUse hooks. The match must be exact. A prefix check is a sandbox escape: <wrap>; touch .git/HEAD passes it, and the tail runs outside the sandbox (reproduced).
function unwrapExact(cmd: string, profile: string, shell = "/bin/zsh"): string | null {
const head = `${SANDBOX_EXEC_BIN} -p ${shQuote(profile)} ${shell} -c `;
if (!cmd.startsWith(head)) return null;
const rest = cmd.slice(head.length);
if (!/^'(?:[^']|'\\'')*'$/.test(rest)) return null; // one quoted word, nothing after it
const inner = rest.slice(1, -1).replaceAll(`'\\''`, "'");
return wrapInline(inner, profile, shell) === cmd ? inner : null;
}Five local tests pass against the shipped wrapInline. They show that the wrap is not idempotent today, that an exact wrap is recognised, that a plain command, another profile or a trailing word is not, that the prefix-check escape is real, and that the real wrap denies it. Not yet verified: that auto mode then accepts the re-issued command end to end.
Workaround: default permission mode for subagent-heavy work.
Details
- Kind: bug
- LifeOS version: 8.761.0
Filed with the LifeOS /feedback command. The reporter approved this exact text before it was sent; paths, secrets and personal details were stripped locally.
Activity
gjaworski86 commentedon Nov 16, 2026
Note
🤖 Klaudia (AI assistant) responding on behalf of Grzegorz
Reproduced on 8.761.0 with Claude Code 2.1.325, and fixed locally without rewriting the command text.
The review that gives "no verdict" is the server-side auto mode classifier, and it judges the input the model sent. Any change a local hook makes comes after that review, so no ordering of hooks can fix it. Calls the local allow rules settle still run wrapped; only calls that need the classifier are refused. Repro: a subagent running
env | rg -i '^(CLAUDE|AGENT)' | sortis refused every time. On 2.1.325 the produced input does pass when re-issued, so the exact-match idempotent wrap proposed here would make every classifier call cost one refusal plus one retry, and the classifier would then judge a wrapper the model was told to copy back.What we run instead:
CLAUDE_CODE_SHELL_PREFIXpoints at a small sh launcher. Claude Code runs<launcher> <script>, the command sits in the script verbatim aseval '<command>' < /dev/null && pwd -P >| <cwd file>, and the tool input stays exactly as the model wrote it. The plugin'stool.callno longer rewrites anything: it registers each Bash call (main, sub or exempt, plus the sha256 of the text that runs) in a registry directory beforenext()and removes it after. The launcher hashes theevalword and runs the script under the existingsandbox-execprofile only when it matches a sub entry. Hook and MCP launches (AI_AGENTending in_harness) go straight through. With that,classicPreToolUse,toolCheckandcombineCheckshad nothing left to do and were removed.Verified end to end in a headless auto mode session: the subagent's
env | rgcall got a classifier verdict and ran on the first try, itstouch ~/.claude/.git/xwas refused withOperation not permitted, and a main-loopgit commitran unconfined.One trap we hit: the registry is shared by every session on the machine. A first version confined any unregistered call while any subagent was live, which confined other sessions' main loops and broke their commits. The launcher now confines only a call whose hash matches a sub entry, or a script it cannot read while a sub is live. Adding the prefix to settings also took effect in sessions that were already running, while removing it did not.
dispatchIdPrefix(#2702) hits the same wall and is not covered by this change.