Skip to content

Claude Code host adapter: permissions, hooks, session context - #6

Draft
mths-mcfs wants to merge 21 commits into
mainfrom
feat/host-claude
Draft

mths-mcfs wants to merge 21 commits into
mainfrom
feat/host-claude

Conversation

@mths-mcfs

@mths-mcfs mths-mcfs commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Claude Code host adapter (src/hosts/claude/**): every binding call inside run is authorized the way Claude Code would authorize the native tool call.

loadPolicy(ctx)
  parent Claude argv (Linux /proc, macOS ps): --settings, --permission-mode, --allowedTools, --disallowedTools, --setting-sources, --add-dir
  settings: managed (+ managed-settings.d) > CLI > local > project > user, plus hooks of enabled plugins
  invalid JSON / wrong types / unparseable deny rule → PolicyLoadError (every call denied)
checkStatic(prepared)                       no I/O
  deny rules → "may match at run time" → ask rules → uncertain bash → allow rules → permission mode
authorize(prepared)
  PreToolUse hooks matching the native name (+ `if`), in parallel, native JSON payload
  deny > ask(defer) > allow; failure/timeout → deny; >1 updatedInput → deny unsupported-config
postToolUse                                  block/exit 2 → warning (cannot undo)
src/hosts/claude/
├── bash.ts          # sh-syntax (mvdan/sh WASM) → simple commands, wrappers, bash -c, file targets, uncertain
├── rules.ts         # Tool(spec), Bash wildcards, gitignore-style Read/Edit paths
├── settings.ts      # sources, precedence, workspace trust, plugins (zod at the boundary)
├── parent-args.ts   # best-effort parent Claude argv
├── hooks.ts         # native payload, command/http hooks, output parsing, updatedInput mapping
├── adapter.ts       # ClaudeHostAdapter
├── context.ts       # FileHookContextStore + createClaudeContextProvider
└── context-hook.ts  # runContextHook(stdin), the companion PreToolUse hook

Evidence

  • Before: no Claude adapter; the server used the placeholder StaticHostAdapter.
    After: npm run verify green, 147 tests in src/hosts/claude (also green on Node 22.23):
    • rule tables: echo ok && rm -rf x, $(rm -rf x), `rm x`, FOO=1 rm x, timeout 5 rm x, sudo rm x, bash -c 'rm x', /bin/rm, xargs rm, find -exec rm, <(rm z) → deny; unbalanced quotes, eval, heredoc with $(), $CMD x, … | bash → ask
    • path rules: //, ~/, / (per source), ./, bare any-depth, symlink to a denied file, rule written through a symlinked dir
    • permission mode × tool table (default, acceptEdits, plan, dontAsk, auto, bypassPermissions, unknown)
    • hooks: exit 2, JSON deny/ask/defer/allow, legacy block, continue:false, updatedInput, crash, exit 1, invalid JSON, timeout (child killed), matcher exact vs regex, parallel conflicts, duplicates run once, disableAllHooks, prompt/unknown type → unsupported-config, if, exec form placeholders, plugins, http hooks against a local server, byte-identical tool_input.command
    • context: record read once and deleted, ../x refused, symlink not followed, model _ctx ignored
  • Real host (Claude Code 2.1.325, claude -p --setting-sources project --strict-mcp-config, model claude-haiku-5-5): the hook's tool_use_id equals _meta["claudecode/toolUseId"]:
    server: "meta":{"progressToken":2,"claudecode/toolUseId":"toolu_015BtEEuxG4a1zDFkaD8eES6"}
    hook:   "tool_use_id":"toolu_015BtEEuxG4a1zDFkaD8eES6"
    
    End to end with the built runContextHook + createClaudeContextProvider and --permission-mode acceptEdits:
    ctx: {"permissionMode":"acceptEdits","toolUseId":"toolu_0158DunUo4EfeNvufNcWZsgL",
          "sources":{"sessionId":"env","toolUseId":"meta","cwd":"ctx-file","permissionMode":"ctx-file",...}}
    

Merge Danger

Door: two-way

Nothing outside src/hosts/claude imports the new code yet; the integrator wires it into createRuntime and agent-code-mode hook.

Blast Radius: contained

One new runtime dependency, sh-syntax (MIT, no dependencies, ~4 MB with its WASM). Picked over shell-quote (tokenizer only: no backticks, no $( inside quotes, no heredocs) and bash-parser (unmaintained): it is the shfmt parser, maintained, and has a synchronous entry, which checkStatic needs (no I/O, sync).

Decisions

  • Auto mode, changed from the original brief (https://code.claude.com/docs/en/permission-modes, "How the classifier evaluates actions": an allow rule resolves a call before the classifier, and with Code Mode the code goes to the classifier once). If an allow rule from any source, including the parent --allowedTools, approves this server's run (mcp__agent-code-mode__run, mcp__agent-code-mode, or an anchored glob such as mcp__agent-code-mode__*), the classifier never saw the script, so inner calls no rule decides get only auto mode's step 2: reads and edits inside the working directories are allowed and everything else asks. Without such a rule, inner calls with no rule are allowed. Deny and ask rules apply to every call either way. The server name defaults to agent-code-mode (an adapter option). Alternative: always allow in auto mode, as the first version did.
  • Recognized rm/rmdir critical-path removals (root, top-level directories, home, the working directory and its parents, a bare * under a working directory, a recursive removal of a target only known at run time, more than one glob level) are never approved by an allow rule, a hook or any mode: they ask, and dontAsk denies them (same doc, "Critical paths"). Alternative: let bypass/auto run them.
  • Bash file targets: every non-option operand of the file commands (cat, head, tail, less, sed, awk, grep, rg, cut, sort, diff, jq, cp, mv, dd, tee, rm, ...) is checked against Read/Edit rules, including a sed script or grep pattern, which is harmless to over-match. Symlinked operands are resolved with realpath in authorize (the contract keeps checkStatic free of I/O), also for a hook's rewritten command.
  • Bash names that rebind commands (alias, hash -p, enable) and more than 64 nested wrappers make the call ask; a run-time word where it could change which rule matches (git "$OP" origin) makes it ask when a deny or ask rule could match.
  • Proposed contract addition, PolicySnapshot.readFilter?: (absPath: string) => boolean, which the tools layer applies to every grep and glob result. The Claude policy already exposes it as payload.isReadDenied. Until the integrator wires it, a recursive grep or glob can return a Read-denied file such as .env.
  • A permission rule (deny, ask or allow, from any source including the parent --allowedTools/--disallowedTools) in a form the docs do not define fails the policy load, so every call is denied with unsupported-config and the message names the rule and its file. Native Claude Code ignores such rules (Bash[rm] denies nothing). Defined forms: Tool or Tool(specifier) with a [A-Za-z0-9_]+ tool name, mcp__server and mcp__server__tool without a specifier, and tool-name globs without a specifier, matched as the docs say (https://code.claude.com/docs/en/permissions, "Tool name wildcards"). In deny and ask, a glob must match the full tool name, so * matches every tool, B* matches Bash and mcp__* matches only MCP tools, not Bash. In allow, a glob counts only after a literal mcp__<server>__ prefix (mcp__server__*, mcp__github__get_*), and unanchored allow globs (*, B*, mcp__*) approve nothing, so they do not count as approving run for auto mode either. Still load errors: a glob with a specifier (B*(x)) and an MCP rule with a specifier. Alternative: skip malformed rules with a warning, which fails open.
  • Hook allow does not lift a permission-mode prompt (in default mode a Bash call with no allow rule is still refused as ask-unavailable even if a hook allows it); natively the hook allow skips the prompt. Alternative: evaluate the mode after hooks, which breaks the static re-check of hook rewrites.
  • Fail-closed beyond native Claude: exit code 1, plain-text stdout on exit 0, continue:false and an invalid matcher regex all deny; native Claude lets the call go ahead. onFailure: "continue" restores pass-through per hook.
  • dontAsk mode follows the docs, not the brief's "deny everything": reads inside the working directories stay allowed.
  • acceptEdits does not auto-approve filesystem Bash commands (mkdir, mv, rm ...) as native Claude does: Bash still asks.
  • Bash matching is stricter than Claude: deny/ask also match after sudo, env, exec, xargs with flags, find -exec, the basename of /bin/rm, and inside sh -c; a deny rule that could match a run-time value ($X) makes the call ask; allow rules still only see Claude's documented wrappers.
  • Tool(param:value) rules that collide with a command name (Bash(timeout:*)) are read both ways for deny/ask.
  • gitignore ! carve-outs are ignored: they never re-allow anything.
  • Project and repository-supplied local allow rules and additional directories apply only when the workspace is trusted in the Claude config (same as native in -p); local settings are held too when untrusted, without the native git-tracked check.
  • Sandbox containment always sets network off: Claude filters network by domain through a proxy, which a boolean cannot express. Writable roots also include the MCP roots and session cwd.
  • The Bash hook payload uses the call's working directory as cwd, and adds run_in_background: false and a generated description; Grep adds head_limit.
  • Unsupported, refused rather than ignored: prompt/agent/mcp_tool hooks, shell: "powershell", exec-form hooks on Windows, plugins declaring hooks in their manifest. Skill and agent frontmatter hooks are not seen.
  • async/asyncRewake hooks run in the background and their result is ignored (they cannot block natively either).
  • Flags reaching Claude Code other than through the parent process argv (Agent SDK control channel, env) are invisible; on macOS ps splits arguments on spaces, so a --settings JSON with spaces fails the load (fail closed).
  • Contract gap, not changed here: PreparedCall.args carries the normalized path, so the "path as the script wrote it" check is only as good as what the tool runtime keeps in args.path; proposed requestedPath on read/write/edit/grep/glob effects. Grep/glob filtering: see the readFilter item above.

🤖 Generated with Claude Code

mths-mcfs and others added 8 commits November 15, 2026 02:30
Add the project skeleton (package, TypeScript strict ESM, vitest, CI on
Linux, macOS and Windows, Apache-2.0 LICENSE and NOTICE, CLAUDE.md and
AGENTS.md) and the frozen contracts the sandbox, host adapter, tool and
benchmark parts build against.

The run path is executable end to end with test fakes: MCP tools/call ->
FakeSandbox -> Dispatcher (prepare, static rules, hooks, re-prepare on
updated args, commit) -> StaticHostAdapter -> MemoryToolRuntime, with
mutation ordering, cancellation, transactions with rollback, output caps
with overflow files, and a command hook runner that kills the process
group on timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Commit a dispatcher-owned deep-frozen copy of each prepared call; deep
  freeze now descends into objects that are already frozen.
- Bound every await on adapter and runtime code by the run's abort signal
  or a grace: prepare, PostToolUse (which now receives the signal),
  loadPolicy (the run deadline starts before it), in-flight calls on stop,
  rollback and dispose.
- Kill the command hook's whole process group on every completion path,
  so a backgrounded descendant cannot outlive the hook.
- Send protocol and validation errors through the capped result
  formatter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implements HostAdapter and the context store for Claude Code in
src/hosts/claude: settings from every source with Claude's precedence,
deny/ask/allow permission rules (Bash with a real shell parser, Read/Edit
gitignore-style paths), permission modes, PreToolUse/PostToolUse command and
http hooks with the native payload (fail-closed), sandbox containment,
protected paths, and the companion hook that records trusted session context
keyed by the tool-use id.

Adds sh-syntax (mvdan/sh compiled to WASM, synchronous, no dependencies) to
parse Bash commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Auto mode: inner calls are allowed only when the run script reached
  Claude's classifier, that is when no allow rule approved the run tool;
  otherwise only reads and edits inside the working directories pass.
- Critical-path rm/rmdir removals always ask (dontAsk denies).
- Bash: parse env -S strings, skip shell option operands (-O, -o,
  --rcfile), strip every wrapper level (cap → ask), ask on alias/hash,
  match run-time words and absolute binaries by every static prefix.
- File targets of sed, awk, grep, cp, dd and other file commands, with
  symlinks resolved in authorize.
- Policy exposes isReadDenied for grep/glob result filtering.
- Hooks deduplicate per event, not across events.
- Context records are claimed with an atomic rename.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rename() let two concurrent readers win on Windows; O_EXCL creation of a
claim file is atomic on every platform. The grep/glob filter test uses the
POSIX-only in-memory runtime, so it is skipped on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A rule like `Bash[rm]` or `Read[./.env]` matched nothing, so a deny the
user meant silently did not apply. Any deny, ask or allow rule that is not
`Tool`, `Tool(specifier)` or an MCP form without a specifier now fails the
policy load, naming the rule and its file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deny and ask globs (`*`, `B*`, `mcp__*`) match the full tool name; allow
globs count only after a literal `mcp__<server>__` prefix, and unanchored
allow globs approve nothing, as the permissions docs define. Forms the docs
do not define still fail the policy load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mths-mcfs and others added 10 commits November 18, 2026 21:51
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Validate adapter decisions with a schema, reject non-string tool names and
  refresh the call summary after a hook rewrite.
- Keep overflow output out of non-private state directories and off Windows.
- Match path patterns across newlines and treat "..name" as inside a root.
- Run a single deadline from the start of the run, counting policy loading,
  and give the sandbox the time left rounded up.
- Roll back only after queued writes and edits end, report a pending
  rollback, and dispose the journal after the rollback has really finished.
- Make the fake sandbox check its deadline before steps and calls, yield
  between steps, and tie its deadline and sleeps to one signal.
- Describe the placeholder runtime the default server serves, with a
  runnable example.
- Resolve in-memory paths against the session cwd and roots (Windows paths
  included), track file revisions for rollback, and run grep and glob in a
  stoppable worker thread.
- Accept only a single --host option in serve.
- Skip spawning a hook whose run was already cancelled and stop recording
  calls in the default runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Fake runtime: cap concurrent search workers per runtime; extra searches wait in a cancelable queue and a slot is reused only after its worker exits.
- Fake runtime: build the search job after a slot is held, send grep content only for files that pass the name filter, and reject a search that would copy more than the text limit.
- Fake runtime: count edit occurrences and build the diff without per-match or per-line arrays.
- Normalize Windows drive paths in the fake runtime and path patterns, and restore original revisions on rollback.
- Run: check the deadline before opening a transaction and word the pending-rollback warning accurately.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…untime

Network-share (UNC) paths are not supported: POSIX resolution folds their
leading `//` while protected-path patterns keep it, so a protected share
could go unrecognized. The fixed root, seeded files, session cwd and roots,
and call paths now refuse UNC paths before any call is prepared.

Edit and write preparation now size the change from cheap counts first and
refuse, before building the edited text or the diff, an edit with more than
MAX_EDIT_REPLACEMENTS (50,000) replacements or a diff over MAX_DIFF_LINES
(200,000) lines. Changes under the budget produce the same text and diff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The session roots are checked for network-share (UNC) paths even when a
  fixed root replaces them, so a UNC session root is refused, not ignored.
- setFile and revision refuse UNC paths like every other path entry point.
- The diff line budget counts the rows the diff actually has: a text that
  ends with a line break no longer counts one extra row. Edit preparation
  works out whether the edited text ends with one from where the replaced
  occurrences sit, still before building the text or the diff, so diffs
  of up to MAX_DIFF_LINES rows are prepared and only larger ones refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep POSIX paths with redundant leading slashes local.
Return actionable guidance when an edit exceeds the replacement limit.
Stop glob after its first extra match and skip setup for cancelled searches.
Match local protection patterns and resolved paths with the same leading-slash normalization.
Use one resolved key for in-memory reads, writes and file revisions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mths-mcfs
mths-mcfs changed the base branch from feat/scaffold to main November 19, 2026 16:33
Since the scaffold review, ensureStateDir refuses win32 because it cannot
verify owner and mode bits there. The companion hook called it before
writing each record, swallowed the error and wrote nothing, so every
context lookup on Windows came back empty. Run the strict check on POSIX
only and keep creating the context directory on Windows as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mths-mcfs
mths-mcfs marked this pull request as ready for review November 19, 2026 16:48
mths-mcfs and others added 2 commits November 19, 2026 20:09
- Deny bash writes to protected host paths; ask for write targets only known at run time.
- Deny bash when sandbox read/write exclusions cannot be contained; managed filesystem settings lock the sandbox switch.
- Auto mode no longer assumes a classifier verdict and drops wildcard shell allow rules.
- Re-run the full static decision on link-resolved bash targets, including on Windows.
- Track cwd-changing wrappers, `>&` file output, `--`, read-write commands, option file values and brace expansion in the shell analyzer.
- Match allow rules against source word spelling; effectful find actions and exec wrappers need exact rules.
- Refuse restrictive path rules with escapes or ranges; make path containment case- and `..x`-aware.
- Read project and local settings from Claude's live working directory and anchor their `/path` rules there.
- Validate mode values and locks, apply disableAutoMode, and ignore auto/bypass defaults from project and local settings.
- Plan mode refuses changes before allow rules.
- Apply blockReads/WritesOutsideWorkingDirectories.
- Enforce allowedHttpHookUrls and httpHookAllowedEnvVars before any request.
- Verify context record provenance and claim records by atomic rename; on Windows the companion hook writes no record, since none can be trusted.
- Also load the main checkout's local settings (not on Windows, at home or on roots owned by others); its scalar values win; verify worktree trust both ways.
- Apply managed hook controls before reading plugin hooks and keep managed-enabled plugin hooks.
- Drop grants and refuse restrictions read from a lossy macOS command line.
- Honor the dispatcher signal in PostToolUse hooks; run hooks in the session cwd.
- PreToolUse failures always block; only command hooks run in the background.
- Run `shell: bash` hooks under bash; shell-form hooks are unsupported on Windows; invalid matchers are unsupported.
- Stream HTTP hook bodies with a cap; keep URLs and arguments out of hook errors.
- Bound settings reads to regular files of limited size; validate plugin enablement booleans.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Skip the pruning test where no record is written and assert that none is on Windows.
- Protect the canonical location of every protected path and ask when a write target cannot be canonicalized (dangling link, errors other than a missing entry).
- Refuse bash under the sandbox when Read/Edit deny rules or the read block would need filesystem exclusions the containment cannot express.
- Keep the working-directory boundary for redirection-only input under a blanket Bash allow rule.
- Track file access by option and operand position, mark unknown attached option values, count escape parity for globs and braces, and read tilde prefixes as Bash does.
- Slice parsed words by UTF-8 byte offsets.
- Treat wrapper options that may change the child directory (combined flags, long options, sudo -i, env -S) as unknown directories.
- Require exact allow rules for the documented exec wrappers and find -rm / -files0-from.
- Anchor project, local and CLI rules at the primary directory, add it to the working directories, and run hooks in the session's current directory.
- Leave repository-only additional directories out of the block-outside checks.
- Match allowedHttpHookUrls against the parsed URL and fetch that same URL.
- Verify the context directory on the writer side with the reader's private-directory check.
- Resolve hook controls once and deny plugin hooks whose source cannot be verified where command-sourced plugins are disabled.
- Scan joined macOS command lines word by word instead of using the exact-argv parser.
- Validate every hook matcher that is not match-all or an exact list, so a malformed one denies.
- Start default when a repository default mode is rejected.
- Verify ownership and identity of worktree metadata before inheriting trust.
- Stop forwarding hook runner diagnostics in failure reasons.
- Deny mode-sensitive calls on Windows when no trusted live mode is known, checked on the real platform.
- Anchor sandbox write grants at their settings source.
- Build context validation fixtures in a private context directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mths-mcfs

Copy link
Copy Markdown
Owner Author

NEEDS_HUMAN on f8c79ae. Two correction commits still leave five blockers and seven major findings. Nine of the underlying checks would need a third correction, which is where the review loop stops.

The remaining design question is how the adapter can establish the effects of a shell call and verify the active Claude policy before it grants access. It can limit the calls it accepts to those it can verify with the current contract, or rely on host-provided policy and containment that enforce the missing checks. The Windows fallback also needs to establish permissions before approving reads when the live mode is unknown.

Linux and macOS CI passed. The Windows context test passed, and the Windows job failed on the absolute path fixture for the sandbox settings test. That fixture needs a fully qualified path. Windows job

One full review and two confirmation rounds verified 28 fixes. The correction commits are 173b3b1 and f8c79ae. The PR went from 2,900 to 3,329 added lines of code and from 1,334 to 1,755 added lines of tests, with no documentation changes. Both correction commits exceeded the 300-line target after their reduction passes.

Real Claude session behavior on Windows and Mac still needs verification. The adapter remains standalone. The design concerns matter when it starts authorizing live tool calls.

Authorization choices to resolve before a later merge

These choices apply once the authorization defects and Windows CI failure are resolved.

🔐 Require explicit permission for common shell file changes in Accept Edits

  • What changes. Accept Edits automatically permits in-workspace file edits through the file tools. Common shell actions such as creating directories or moving files still need an allow rule.
  • Who it affects. People running coding scripts in Accept Edits mode.
  • On rollout. Scripts that rely on Accept Edits for routine shell file changes can stop at the permission check once the adapter is active.
  • Where it came from. An implementation choice.
  • How to change it. Apply the native Accept Edits rules to recognizable shell file operations in approved directories.

🔐 Require explicit permission for read-only shell commands

  • What changes. Manual and Accept Edits require a shell permission even for inspection commands Claude normally approves on its own.
  • Who it affects. People running shell inspections in Manual or Accept Edits mode.
  • On rollout. Routine shell inspection can be refused once the adapter is active.
  • Where it came from. An implementation choice.
  • How to change it. Honor native read-only approvals for commands whose effects the adapter can verify.

🔐 Keep critical directory removals behind approval in every mode

  • What changes. Recognized critical-directory removals always require confirmation. Code Mode refuses them because it has no confirmation channel, even when the host allows an operator to disable that prompt.
  • Who it affects. Operators who explicitly disable the native removal prompt in isolated environments.
  • On rollout. The adapter refuses these calls once it is active.
  • Where it came from. An implementation choice.
  • How to change it. Honor the host's explicit removal approval setting for eligible sessions.

🔐 Keep file restrictions in force where a local exception exists

  • What changes. The adapter keeps a file restriction in force even when the same settings file defines an exception that Claude honors.
  • Who it affects. People who use permission exceptions to keep a subset of restricted files accessible.
  • On rollout. Some files covered by those exceptions can remain unavailable in Code Mode once the adapter is active.
  • Where it came from. An implementation choice.
  • How to change it. Honor the documented exceptions within the settings file that grants them.

🔐 Apply shell restrictions through more command wrappers

  • What changes. The adapter evaluates restrictions on the command a wrapper is asked to run. It also treats more shell operands as possible file paths, so a restricted path written as an argument can trigger a refusal.
  • Who it affects. Operators who use shell wrappers or file commands under scoped permission rules.
  • On rollout. Some wrapped commands or commands with path-like arguments can require approval once the adapter is active.
  • Where it came from. An implementation choice.
  • How to change it. Use the host's wrapper and operand rules for recognized commands while retaining conservative handling for uncertain effects.

🔐 Extend shell write access to folders shared with the tool server

  • What changes. When shell containment is on, the adapter treats every folder the host shares with the tool server as a writable workspace folder.
  • Who it affects. People who share several folders with the tool server and administrators setting shell write boundaries.
  • On rollout. Contained shell calls can gain write access to shared folders once the adapter is active.
  • Where it came from. An implementation choice.
  • How to change it. Limit shell write access to directories approved by Claude's workspace and containment settings.

🔐 Use only settings and plugin hooks for calls inside the script

  • What changes. A policy defined within a Claude skill or subagent applies to native calls in that scope. Code Mode checks the hooks defined in settings and installed plugins for its inner calls.
  • Who it affects. Teams that attach access restrictions to individual skills or subagents.
  • On rollout. Calls inside a script can proceed without a skill- or subagent-specific guard once the adapter is active.
  • Where it came from. The request left the behavior open.
  • How to change it. Include the active skill and subagent guards when authorizing calls or refuse to run under an unknown hook scope.

🔐 Refuse Windows calls that require a shell command hook

  • What changes. On Windows, a matching command hook in the shell form stops a call before it runs. A matching hook scheduled after a call reports a warning.
  • Who it affects. Windows users and administrators who use shell commands to enforce policy or log tool calls.
  • On rollout. Once the adapter is active, calls can stop at a Windows hook that the native Claude shell could run.
  • Where it came from. An implementation choice.
  • How to change it. Support the host's selected Git Bash or PowerShell runner and check each configured hook in that runner.

🔐 Limit Windows operations without verified session context

  • What changes. The Windows companion hook supplies no live session context. Code Mode refuses shell calls and file changes when it cannot verify the live permission mode.
  • Who it affects. Windows users who rely on session permissions or the companion hook.
  • On rollout. Shell calls and file changes can stop after the adapter is enabled. File reads still depend on the applicable policy.
  • Where it came from. An implementation choice.
  • How to change it. Restore a Windows context channel that verifies the live session and its permission mode.

🔐 Limit permissions derived from Mac launch options

  • What changes. With only a flattened Mac command line, Code Mode withholds grants and uses Manual for a visible permissive launch mode unless the live mode is verified. It refuses the policy if it detects restrictions it cannot read accurately.
  • Who it affects. Mac users who set permissions or workspace access at launch.
  • On rollout. Affected launch configurations can lose approvals or stop calls.
  • Where it came from. An implementation choice.
  • How to change it. Establish a trusted source for the exact launch arguments or effective settings and restore launch options from that source.

🔐 Disable shell calls in Plan mode

  • What changes. While Claude plans, Code Mode refuses shell calls even when a user has an exact allow rule for a read-only invocation.
  • Who it affects. Users who inspect projects through shell commands while planning.
  • On rollout. Once the adapter is active, these inspection calls stop in Plan mode.
  • Where it came from. An implementation choice.
  • How to change it. Identify shell calls that are verifiably read-only and permit the ones the host would allow before plan approval.

🔐 Use only exact shell allow rules in Auto mode

  • What changes. Auto mode drops all wildcard shell allow rules, including narrowly scoped patterns. Users need a separate exact rule for each approved invocation.
  • Who it affects. Auto mode users and administrators who save narrowly scoped shell permissions.
  • On rollout. Once the adapter is active, shell calls that depended on a narrow wildcard can be refused.
  • Where it came from. An implementation choice.
  • How to change it. Honor verified narrow wildcard permissions while continuing to omit broad grants and require approval for unreviewed work.

🔐 Require every HTTP hook list to approve

  • What changes. When several active settings files list approved destinations or header variables, each list must approve them. A destination listed in only one file can stop a call, and a variable listed in only one file can be removed from the header.
  • Who it affects. Teams that share HTTP hook settings across user, project and organization configuration.
  • On rollout. Once the adapter is active, hooks can be refused or lose credential headers when the lists differ.
  • Where it came from. An implementation choice.
  • How to change it. Use the host's scoped list-merging rules while preserving organization restrictions and validating the destination before sending.

🔐 Extend the outside-directory file write block to shell calls

  • What changes. The setting that blocks the file tools from writing outside working directories also refuses shell calls the adapter recognizes as outside writes.
  • Who it affects. People who keep the file write block enabled and separately approve shell work outside their project.
  • On rollout. Once the adapter is active, some previously permitted shell calls stop at the file write boundary.
  • Where it came from. An implementation choice.
  • How to change it. Apply the file write setting to the file tools and use the host's dedicated shell containment policy to control shell writes.

🔐 Keep the outside-read block on directories added only in local project settings

  • What changes. With the outside-directory read restriction on, Code Mode refuses reads in directories added only through the project's local settings. Claude permits those directories when the local settings file is untracked, and Code Mode cannot establish that status.
  • Who it affects. People who keep their working directory list in private local project settings.
  • On rollout. Reads of those directories need an addition from an eligible settings source or an explicit session directory addition.
  • Where it came from. An implementation choice.
  • How to change it. Verify that the local settings file is untracked before counting its directory additions.
Other behavior choices

❓ Interpret an ambiguous shell rule as two restrictions

  • What changes. A restriction that can mean either the timeout utility or a tool's runtime limit applies to both. A rule written to restrict that utility can also restrict ordinary shell calls.
  • Who it affects. Operators who already restrict the timeout command by name.
  • On rollout. Some previously usable shell calls can be refused once the adapter is active.
  • Where it came from. The request left the behavior open.
  • How to change it. Follow the host's interpretation for the ambiguous rule or require the operator to disambiguate it.

🧩 Drop notifications from background hooks

  • What changes. Claude can normally show the result of a background hook on a later turn. Code Mode discards that result, including notifications that the hook asked Claude to act on.
  • Who it affects. People who use background hooks to report quality checks or warn about completed calls.
  • On rollout. These notifications stop appearing for Code Mode calls once the adapter is active.
  • Where it came from. An implementation choice.
  • How to change it. Route background hook results to the session that started them.

@mths-mcfs mths-mcfs added the review-loop:needs-human O loop de revisão precisa de uma pessoa para continuar label Nov 20, 2026
@mths-mcfs
mths-mcfs marked this pull request as draft November 20, 2026 02:29
@mths-mcfs

Copy link
Copy Markdown
Owner Author

Decisions recorded for the next review round (the owner decided on 2026-11-19):

  • Design: accept only what the adapter can verify. The adapter stops inferring shell effects from the command text. A Bash call proceeds only through an exact allow rule or inside the OS containment that enforces the filesystem and network limits; anything else is an ask, which is denied without an interactive channel.
  • The thirteen restrictive authorization choices, the ambiguous timeout rule and dropped background hook results: approved as is.
  • Shell write access to folders shared with the tool server: close it. Shell writes stay inside the working directories Claude approved.
  • Skill and subagent hooks: close it. Code Mode refuses to run when the configuration defines skill or subagent hooks it cannot apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-loop:needs-human O loop de revisão precisa de uma pessoa para continuar

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant