Skip to content

model policy: check Claude's Agent tool; linked-machine and agent-option follow-ups (#802, #128) - #978

Merged
scuttletoby merged 9 commits into
mainfrom
fork/model-policy-batch11
Nov 22, 2026
Merged

scuttletoby merged 9 commits into
mainfrom
fork/model-policy-batch11

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Fixes #802. Part of #128: forked skills are checked or refused here; what is left (skills T3 cannot read, a same-name skill in a place T3 does not read, the instance's own alias mapping) is #987.

What and why

#128: Claude's own Agent tool now follows the model policy. The owner decided on 2026-11-15 that while the policy is on, every call that starts a built-in sub-agent must name an allowed model. Until now T3 checked only its MCP routes (delegate_task, create_threads, t3_thread_launch, t3_thread_configure). Claude's Agent tool, or Task in older Claude Code, never reached the server.

  • apps/server/src/fork/claudeAgentModelPolicy.ts (new) is a PreToolUse hook for Agent and Task. It reads the call's model and effort and checks them with the same makePickCheck the MCP routes use, on the new route "Agent".
    • enforce refuses a pick outside the rows, a call that names no model, and a call with inherit. The refusal shows the rows and how to fix the call.
    • advise lets the call run and adds a note.
    • A pick inside the rows gets its row's useFor.
    • With the policy off, or on a host without settings, nothing is checked.
  • The alias (opus) is read as the full id from this machine's Claude model list, which is the same mapping T3 uses for the sub-agent it shows. A row matches when it names the alias (as delegate_task reads a row saved as opus) or that full id. The refusal says which alias and effort pass, or that none does. A name the list does not map stays as given, so it matches no row.
  • The Skill tool is checked too. A skill with context: fork, or one that names model or effort, must name a model from the rows in its frontmatter. A skill that runs inline and names neither is not checked. A skill T3 cannot find or read is refused under enforce and gets a note under advise.
  • While a policy is on when the query opens, the matcher sets onFailure: "block", so a hook that times out refuses. With the policy off it is left out, so a Claude Code older than 2.1.295 still opens.
  • A fork call is read like any other call: under enforce it must name an allowed model, as the owner decided and as the model guard (fork-kit/model-guard) already reads it. Claude itself runs a fork on the session's own model and ignores the model the call names.
  • Workflow agent() calls stay with the model guard, because the script is code and this hook does not read it.
  • The hook fails closed. Any error while checking refuses the call, and so do a settings read that dies and a saved policy that does not parse. A hook that throws would otherwise count as a non-blocking error and let the call through.
  • Wiring is fork-only. makeClaudeMcpProfiles (claudeMcpProfile.ts) puts the matcher first in options.hooks.PreToolUse of every plan, including no profile, t3-only and bare builtinTools: none. The upstream adapter already spreads mcpProfileOptions and its hooks into each query, so no upstream file changes.

#802, point 1: Settings marks across machines (done). personModelPickMarks now takes the machine whose settings hold the picks. It reads only that machine's instance with the pick's instance id. A provider that has no machine id still counts. ModelPolicySettings.tsx passes the scope's target.environmentId.

#802, point 2: what the sending machine cannot know.

  • Ultracode default only on the receiver (done). A pick sent to a linked machine (pickOfRemote) now sets ultracodeDefaultUnknown. A claudeAgent row then reads a pick that leaves ultracode out both ways, with ultracode and without, because the receiver's model list may turn ultracode on by default. If the row does not allow both readings, the pick is refused, and the hint says: Name the option ultracode in target.options: { "id": "ultracode", "value": false } runs the effort named, true runs ultracode. A pick for this machine still reads the catalog's real default. Rows of other drivers (codex) are not affected.
  • A control only the receiver's agent has (kept fail closed, explained). The pick is still refused here.
    • Why not trust the receiver: the capabilities this machine holds for a linked machine list option ids without the roles that say which one sets the effort. Letting an unknown id through could let an unchecked effort control past the policy whenever the receiver is in advise or off.
    • What changed: the refusal now says so and gives the way out ("start that agent on this machine once so its model list describes it"). The docs say the same.

#802, point 3: one driver, several effort ids (kept fail closed, explained). The pick must still name every id. The issue allows this ("Fails closed; say so in the refusal or the docs, or check per instance").

  • Why not check per instance: which instance on the receiver runs the pick is not known here.
  • What changed: the refusal now names each id, why, and the two ways out (a model whose driver has a fixed effort id, or start the task where one instance runs it). The docs say the same.

#802, point 4: options that pick an agent or a mode (done). While the policy is on, the server now refuses OpenCode agent, Kiro mode and the ACP session mode _t3/session-mode, even when the model list describes them.

  • The refusal says what to leave out and where to put the model and effort instead.
  • The ids are the model guard's DRIVER_MODEL_OPTION_IDS plus ACP's ACP_SESSION_MODE_OPTION_ID. The model guard's test (fork-kit/model-guard/tests/guard.test.py) reads modelPolicy.ts, so the lists cannot drift apart; app code reads no fork-owned file. A server test keeps the session mode equal to ACP's own constant.
  • The Settings marks (a person's own picks) are not affected.

Umbrella: #876. #731 and #899 (machine install / enforce) are not touched.

Tests: each fix fails without it

Each fix was undone on its own, its tests were run, and then the fix was restored:

Fix undone Test that fails
point 1: match by machine (modelPolicySettings.logic.ts) reads the instance of the machine whose settings hold the picks, not another machine's with the same id (#802)
point 2: ultracode both ways (contracts) a pick for a linked machine that leaves ultracode out reads both ways on a Claude row
point 2: pickOfRemote sets ultracodeDefaultUnknown (server) sent to a linked machine: the model's ultracode default counts both ways
point 2: the linked-machine note on an unread control refuses it, on a known driver and on a pick for a linked machine; leaving it out is inside
point 3: the several-ids text several effort ids for one driver: the refusal names each and why (fail closed)
point 4: agent/mode options (contracts) 2 tests, including refuses an option that picks an agent or a mode while the policy is on, even when described
point 4 (server routes) 5 tests across modelPolicyCheck, delegateOwnOptions, launchMcpProfile (all routes, here and sent)
#128: the hook wired into every plan every query carries the model policy's check of Claude's Agent tool (#128)
#128: the hook itself claudeAgentModelPolicy.test.ts is new: enforce, advise, off, no settings, alias, fork, Task, and failing closed

Older tests changed because of the fixes:

  • Picks sent to a linked machine for a claudeAgent row now name ultracode.
  • The ACP session-mode case expects the agent-option refusal.

Run locally:

  • packages/contracts modelPolicy: 31 passed.
  • apps/server/src/fork: 58 files, 1220 tests passed.
  • apps/web settings/fork unit tests: 69 passed.
  • effect-tsgo typecheck of contracts, server and web: clean.
  • vp lint: no errors.
  • vp fmt --check: clean.
  • Seam check (fork-seam-check.cjs, as CI runs it): passes against main. fork-seams: announce the ClaudeSkills.ts lines #978 adds #990 (announce) is merged, so this PR moves the 3 ClaudeSkills.ts lines from announced to added in .github/fork-seams.json. Schema, upstream-files and seam-check tests pass.
  • After the merge of main: the model policy's PreToolUse hook goes into the plan before main's lazy options wrapper, so adding it reads no options early. Main's lazy-options test now expects that hook as the only option.

Round 1 review (code and state lenses)

Finding Done Test that fails without it
MAJOR (state): an alias row (opus) blocks every Agent call Done. The pick keeps the name given (namedAs), so a row naming the alias or the full id matches; the refusal lists the Agent aliases and efforts that pass, or says none does contracts a pick read as a full id from the name it gave (namedAs) matches a row naming either; server a row saved with the alias matches the alias the call names, in both modes, rows no alias reaches: ...
MAJOR (code): a forked skill starts a sub-agent without the Agent tool Partly. Skill calls are checked from the skill's frontmatter (discoverClaudeSkills finds it); unfound or unreadable is refused under enforce (fail closed). Left, in #987: skills T3 does not read (bundled, MCP, commands, add-dir), and a same-name skill in a place T3 does not read enforce: checks the frontmatter of a skill that runs forked or names a model, fails closed: a skill T3 cannot find or read is refused under enforce
CI red (Lint, fork-owned-reads) Done. The list check moved to the model guard's test; fork-owned-reads.test.py passes locally and fails on the old test guard.test.py test_agent_picking_options_are_the_servers_model_policy_ones
minor: no onFailure: "block" Done, while a policy is on when the query opens (off: left out for older Claude Code) a hook that fails or times out refuses while a policy is on (onFailure block); adapter test
minor: alias read through the shared catalog Documented next to the Agent paragraph. The upstream adapter does not pass its instance's catalog to the fork's plan; kept in #987 n/a (docs)
minor: docs omit the fork's ignored effort Done n/a (docs)
minor: no test pins one hook per query Done: each opened query (two turns) has exactly one policy matcher, first, and one refusal every query carries the model policy's check of Claude's Agent tool once (#128)
minor: repeat of an accepted remote delegate_task is refused Not changed, on purpose. Upstream's repeat sends the launch again with its named model, and a receiver's replay that names a model can start a run on it (checkLaunch). Skipping the check on a repeat would send an unchecked pick to a receiver in advise or off n/a

State: runs again (the hook is added once per query, two turns tested; the same call gets the same answer), stops half-way (a throw, a dying settings read or an unreadable skill refuses; a timeout refuses under onFailure: "block"), old state (alias rows saved before now match the alias).

Round 2 review (state: not safe; code: safe)

Finding Done Test that fails without it
MAJOR (state #1): an inline skill naming no model, with an unquoted : in a value (description: Review the code: bugs and style), reads as unreadable: refused under enforce, a note under advise Fixed at the root: the check reads the frontmatter with T3's skill list parser (parseSkillFrontmatter in ClaudeSkills.ts, with its : repair), one source. It is exported there and its parsed result carries the whole record: 3 upstream seam lines, announced first in #990 (list only). Frontmatter still broken after the repair is refused under enforce, as before enforce: checks the frontmatter of a skill that runs forked or names a model (inline-colon: allowed under enforce, no note under advise; fork-colon: its model is read and refused); fails closed: a skill T3 cannot find or read is refused under enforce (colon-broken)
minor (state #2): Claude Code older than 2.1.295 with a policy on refuses every new query, with a "remove onFailure" error Docs say it plainly (docs/fork/README.md, model policy): 2.1.295 or newer is required while a policy is on, in advise too. A version warning is in #987 (point 4) n/a (docs)
minor (state #3): a SKILL.md T3 drops lets a later same-name skill be checked #987 point 5 n/a
minor (state #4): the check reads the disk, Claude Code runs the copy it loaded #987 point 6 n/a
minor (code #1): a $name mention in a turn's text becomes a native /name command: no Skill call, the hook never runs #987 point 7 (suggests the SDK's UserPromptExpansion hook) n/a
minor (code #2): under enforce, bundled, plugin and MCP skills are refused Already #987 point 1, documented n/a
minor (code #3): the refusal's "copy into .claude/skills" hint may not hold for bundled skills that cannot be shadowed #987 point 8 n/a

Round-2 minors in one comment: #987 (comment)

State question

  • Runs again: the hook and the checks are pure reads of the policy and the pick. The same call gets the same answer every time, and the tests call each case twice. The hook holds no state of its own.
  • Stops half-way: a refused call has started nothing. If the hook dies mid-check, the call is refused. A Claude session that stops between calls leaves nothing behind.
  • Old saved settings: nothing new is saved and no setting changes shape. A saved policy is read as before. A saved policy that does not parse still refuses every agent pick, and that includes Agent calls now.
  • Empty state:
    • A policy with no rows refuses every agent pick under enforce, as before.
    • Policy off, or a host without settings, checks nothing.
    • No Claude model list loaded: the bundled list maps the aliases.
  • Sub-agents and sessions started before the change:
    • A Claude session that was already open has no hook until T3 opens a new query process (a new turn on a new process, or a restart).
    • Sub-agents it already started keep running; the check applies to calls only.
    • The policy is read on each call, so a policy changed mid-run counts from the next call.
  • Linked machines on an older version: what a sender refuses is never sent. A receiver on an older version still checks with its own list, as before. The new ultracode rule only makes the sender stricter.
  • Agents used to the old rules:
    • Under enforce, a Claude pick sent to a linked machine without ultracode is now refused (the hint says to name it). An OpenCode agent or ACP session-mode option is also refused, and so is an Agent call without a model.
    • Under advise, each of these runs with a note.

General vs project

All of this is general. The models, efforts and modes come from the modelPolicy setting (each machine's own config) and from each machine's model lists. Nothing names a project, repo, machine or person. The agent-option ids come from the drivers (OpenCode, Kiro, ACP) and are the same list the model guard already uses. The Claude tool names (Agent, Task) and the fork type are Claude Code's own.

🤖 Generated with Claude Code

…ine's pick leaves open

Claude's own Agent tool (and Task in older Claude Code) is now checked against
the model policy as each call is made. A PreToolUse hook is added to every
Claude query through the fork's profile plan: enforce refuses a pick outside the
rows or naming no model, advise lets it run with a note, and an inside pick gets
its row's useFor. The alias is read as this machine's full id. A fork call must
name an allowed model too, as the model guard reads it. Any error while
checking refuses the call.

#802:
- Settings marks read the instance of the machine whose settings hold the
  picks, not another machine's instance with the same id.
- A Claude pick sent to a linked machine that leaves the ultracode option out
  is read both ways, because that machine may turn ultracode on by default.
  The refusal says to name the option.
- An option that picks an agent or a mode (OpenCode agent, Kiro mode, ACP
  session mode) is refused while the policy is on, even when the model list
  describes it. A test keeps the list in step with the model guard's.
- A control that only a linked machine's agent has, and several effort ids for
  one driver, still fail closed. The refusals now say why and what to do.

Fixes #802
Fixes #128

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

Copy link
Copy Markdown
Owner Author

lens: state · reviewer: lens agent · read at: 9543d16
verdict: not safe to merge
covered: the full diff (16 files); issues #802 (all four points) and #128 with the owner decision of 2026-11-15; the PR body; the paths the change meets at run time: ClaudeAdapterV2.ts (where a query opens and merges the plan's hooks), ScheduledTaskService.ts (how a scheduled task launches), OrchestratorMcpService.ts delegateTask (where a pick sent to a linked machine is checked), ProviderInstanceRegistryHydration.ts (what the Claude driver is built with), and the Agent tool's input schema in the pinned Claude Agent SDK.
checks: ran the PR's changed tests: server claudeAgentModelPolicy, claudeMcpProfile.adapter, delegateOwnOptions, launchMcpProfile, modelPolicyCheck (5 files, 124 passed); contracts modelPolicy (31 passed); web modelPolicySettings.logic (19 passed). I undid three fixes one at a time, and each turned its test red: ultracodeDefaultUnknown: true in pickOfRemote (sent to a linked machine: the model's ultracode default counts both ways), the hook's catch changed to allow (fails closed: ...), and the plan wiring reverted to the old code (every query carries the model policy's check of Claude's Agent tool (#128), so the new test fails on the old code). Each file was restored and the worktree is clean.
state: old rows: rows with full ids work as before, but a row that names an alias (opus) no longer matches any Agent call (major below). Saved person picks and scheduled tasks: not checked, as before. ScheduledTaskService launches with threadLaunch.launch and not through a checked route, so a saved task's modelSelection, with an agent or mode option or without ultracode, still runs. Inside that thread, Agent calls are now checked. Linked machines: nothing saved changes shape. An agent's new Claude pick sent to a linked machine without ultracode is refused under enforce unless its row allows ultracode, and the refusal says to name it. Remote tasks that were already accepted are not checked again: the check runs only on the live call (OrchestratorMcpService.ts:2841). OpenCode agent, Kiro mode and ACP _t3/session-mode: threads that already have one keep running, because no check runs per turn. Only a new agent launch, configure, delegate or create that names one is refused, with the agent-option fix text. Running and resumed threads: the upgrade restarts the server. Claude's query process is the server's child, and the hook is a callback in the server, so no query can keep running past the upgrade without it. Each resumed thread opens its next query with the hook. A refusal is a PreToolUse deny with a reason Claude reads, and bypass mode does not skip it. Policy changes count from the next call, since settings are read on each call. In production the hook does find the settings: the driver is built where ServerSettingsService is required (ProviderInstanceRegistryHydration.ts:43), so this is not the "no settings: nothing checked" path. Stops half-way: a check that dies or throws refuses the call, and a catalog read that fails falls back to the bundled catalog. It leaves only a log line behind (verified by undoing the catch, above). Runs again: the hook is added once per query and never stacked. withAgentModelPolicy wraps a fresh plan each time a query opens and changes nothing in place. The matcher is built once per adapter. The adapter adds its other hooks under SubagentStart and Stop and leaves PreToolUse as the plan gives it. A live query that is reused keeps the hooks it opened with.
blocker: none
major: under enforce, a saved policy row that names a Claude alias (for example model opus) refuses every Agent call, and the agent cannot fix it. The reason is that claudeAgentCallPick reads the call's alias as the full id (apps/server/src/fork/claudeAgentModelPolicy.ts:29), while rows are matched by row.model === model (packages/contracts/src/modelPolicy.ts:454), so the row opus never matches claude-opus-5-5. The Agent tool's model accepts only aliases (sonnet|opus|haiku|fable in the pinned SDK's AgentInput), so no call passes. The refusal adds to the confusion: it lists opus under Allowed and tells the agent to name an alias, which it already did. The MCP routes read the same row as allowed, because pickOfSelection keeps the name as given. Settings only warns about alias rows and still saves them, so a machine with enforce on and such a row loses Claude's Agent tool on its first query after the upgrade. No test has an alias row, since the tests use MODEL_POLICY_START_ROWS, which name full ids. Fix: let a row that names the alias as given also match an Agent call, as the MCP routes already do. Or at least say in the refusal that a person must change the alias row to the full id, and add a test with an alias row.
minor: the hook maps the alias with the driver-wide ModelCatalog.current("claudeAgent") (claudeAgentModelPolicy.ts:63). The adapter reads a sub-agent's model with the instance's own scoped catalog and routes. If an instance's Claude Code maps an alias to another model, the check reads a different id than the one that runs
minor: no test pins one policy hook per query. The adapter test (claudeMcpProfile.adapter.test.ts:263 and :276) checks with .some, so a hook added twice would still pass. Counting the "Model policy" answers for one Agent call would pin it
minor: the check of a remote delegate_task runs before remoteDelegation.delegate dedupes by clientRequestId (OrchestratorMcpService.ts:2841). An agent that repeats an accepted Claude call without ultracode after the upgrade gets a refusal, although the task exists and runs. This is rare, but the message reads as if nothing started
minor: reach, outside this PR's state question: sub-agents that Claude starts without an Agent or Task call (for example a skill that runs in a sub-agent with the model from its own frontmatter) are not covered by this hook, nor by the model guard as far as I read. The #128 decision says "every call that starts a built-in sub-agent", so this may be worth an issue

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: lens agent (Claude Opus 5.5) · read at: 9543d16
verdict: not safe to merge
covered: the full diff (16 files), issues #802 and #128 with the owner decision of 2026-11-15, the PR body; the Claude adapter's query path (ClaudeAdapterV2.ts: one makeClaudeQueryOptions call site, mcpProfiles per turn, hooks spread in both branches), makePickCheck / answerPick, pickOfSelection / pickOfRemote, checkModelPolicyPick, the SDK's HookCallbackMatcher and Agent input types (agent SDK 0.3.321), the model guard's hook entry and matcher.
checks: ran the changed test files: server fork tests 5 files, 124 passed; contracts modelPolicy 31 passed; web modelPolicySettings.logic 19 passed. Undid three fixes one at a time; each named test failed and passed again once restored: the hook wiring in makeClaudeMcpProfiles (every query carries the model policy's check of Claude's Agent tool (#128)), ultracodeDefaultUnknown in pickOfRemote (sent to a linked machine: the model's ultracode default counts both ways), the per-machine match in personModelPickMarks (reads the instance of the machine whose settings hold the picks ... (#802)). Read Claude Code 2.1.326's skill loader for the frontmatter keys below; not run live (no servers here).
state: runs again: the hook and the checks are pure reads of the settings and the pick, read on each call, so the same call gets the same answer. Stops half-way: a refused call starts nothing; a throw or a rejected check refuses (the catch in the hook), a settings read that fails refuses (answerPick with no policy), a catalog read that fails falls back to the bundled list. Old state: no setting changes shape; an unreadable saved policy refuses Agent calls too under enforce. Empty state: no rows refuses every Agent call under enforce; off or no settings service checks nothing. Sessions: every Claude query T3 opens (new, resume, restart, sub-thread, scheduled run) goes through planFor and withAgentModelPolicy (claudeMcpProfile.ts:742), so all carry the hook; a process opened before this version has none until reopened, as the docs say.
blocker: none
major: a skill that runs forked starts a sub-agent without the Agent tool, so it is never checked, and the PR closes #128. Claude Code's skill frontmatter reads model, effort, context: fork and agent: an agent can invoke (or first write, under .claude/skills/) a skill with context: fork and a model outside the rows, and the Skill call starts a built-in sub-agent on that model. The hook matches only Agent|Task (apps/server/src/fork/claudeAgentModelPolicy.ts:22, matcher at :94), and the model guard's matcher has no Skill either. The owner's decision is "every call that starts a built-in sub-agent must name an allowed model". Fix: under a policy that is on, check (or refuse) Skill calls whose skill runs forked or sets model/effort, or say in the docs that these are not covered and keep #128 open with a follow-up instead of Fixes #128.
minor: the matcher has no onFailure: "block" (claudeAgentModelPolicy.ts:93). The SDK's default is continue: a hook that times out (or returns output that fails validation) lets the Agent call through. The model guard's hook entry sets onFailure: "block" for exactly this reason. The hook's own catch covers throws, and its reads are in-process, so a timeout is unlikely, but the PR says "any error while checking refuses". Either add it (it makes the query fail at startup on a Claude Code too old to know the option) or say in the docs that a timed-out hook lets the call through.
minor: the Agent call's alias is read through T3's catalog (claudeAgentModelPolicy.ts:29), not through the mapping the installed Claude Code uses. docs/fork/README.md:360 keeps the rule that an alias is not read as its model because "a provider may move an alias", and :350 now reads it as one for Agent. The Agent tool takes only aliases, so reading them is needed, but a Claude Code whose opus maps to another model (an older binary path, or an alias override in its environment) runs a model the check did not read. Say so in the docs next to the Agent paragraph.
minor: the docs say Claude runs a fork on the session's model and ignores the one it names; it also ignores the effort a fork names (the SDK's Agent input says so), so a fork's checked effort is not the one that runs. Add "and effort" in the Agent paragraph of docs/fork/README.md.

Focus answers: an Agent or Task call (sub-agent type, fork, inherit, no model, non-string model or effort) cannot get a model outside the rows under enforce; the one way around found is the forked skill above, plus Workflow agent() calls, which the PR leaves to the model guard and says so. Linked-machine picks: a Claude row now reads a pick without ultracode both ways and the hint names it; correct and documented. Agent and mode options are refused on all four routes, here and sent; checked with the tests above.

🤖 Generated with Claude Code

…t fails refuses

- A row saved with a Claude alias (opus) now matches an Agent call naming it, as the MCP routes
  read it; a full-id row matches the alias that maps to it. The refusal says which alias and effort
  pass, or that none does.
- Claude's Skill tool is checked: a skill with context: fork, or one naming model or effort, must
  name a model from the rows; a skill T3 cannot find or read is refused under enforce.
- onFailure "block" on the hook while a policy is on, so a hook that times out refuses.
- The agent-option lists are kept in step by the model guard's test, so app code reads no
  fork-owned file.
- Tests pin one policy hook per query; docs name the fork's ignored effort and the alias mapping.

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

Copy link
Copy Markdown
Owner Author

lens: state r2 · reviewer: lens agent (Claude Opus 5.5) · read at: 1d5cee6
verdict: not safe to merge
covered: the diff since 9543d16 (the fix commit 1d5cee6 on its own; the merge of main brings only the usage-pacing change #974, not read here); both round-1 reports, the PR body's round-1 table, issue #987; the paths the fix meets at run time: discoverClaudeSkills and its frontmatter parser (ClaudeSkills.ts), the live-query key (claudeEffectiveQueryPolicyKey in ClaudeAdapterV2.ts, planKey in claudeMcpProfile.ts), the Claude binary setting (default claude on the PATH), and the pinned Claude Agent SDK 0.3.321's initialize handling of onFailure: "block".
checks: ran the PR's changed tests: server claudeAgentModelPolicy, claudeMcpProfile.adapter, claudeMcpProfile, delegateOwnOptions, launchMcpProfile, modelPolicyCheck (6 files, 184 passed); contracts modelPolicy (32 passed); web modelPolicySettings.logic (19 passed); fork-kit/model-guard/tests/guard.test.py (98 passed). None of them needed loopback, so none was left out. I undid three fixes one at a time, and each turned its test red: the namedAs match in checkModelPolicyPick (a row saved with the alias matches the alias the call names, in both modes), onFailure: "block" (a hook that fails or times out refuses while a policy is on), and a settings read that fails read as "off" instead of "on" (same test). Each file was restored. A throwaway test (deleted after, worktree clean) ran the hook on a user skill that runs inline, names no model and has description: Review the code: bugs and style: T3's skill list shows it, and the hook refuses it under enforce (major below). Not run: a live Claude Code (no servers here), so Claude Code's own skill reload and same-name order are read from docs and code comments, not observed.
state: runs again: the hook is one shared callback; the matcher is built again for each query T3 opens (yield* agentPolicy per plan) and added once, first; the adapter test pins one per opened query over two turns. Each Skill call reads the skill folders again (no cache), so the same call on the same disk gets the same answer. Resume and restart: each new Claude process gets the matcher for the policy as it is when it opens. A live query reused for the next turn keeps the matcher it opened with: onFailure is not part of the live-query key, so it is not reopened when the policy changes. Policy switched on mid-session: the next call is checked, because the hook reads the settings on each call; only a hook that times out still lets the call through until T3 opens a new process. The docs say this ("while a policy is on when the process opens"). Switched off mid-session: nothing is checked from the next call on; the blocking matcher stays, which does no harm on a Claude Code new enough to have opened. Old settings: alias rows saved before now match (round 1, fixed). Older Claude Code: with the policy on, in advise too, the SDK refuses to open any query on a Claude Code older than 2.1.295 (minor below). Settings read failing: when a query opens, a failing read counts as "on" (blocking matcher); during a call it refuses. Skills that change on disk between turns: T3 reads the file at the call, but Claude Code may run the copy it loaded earlier (minor below). Empty state: no rows refuses every Agent call and every checked Skill call under enforce.
round 1, fixed at the root: an alias row (opus) blocked every Agent call. The pick keeps the name given (namedAs), a row naming the alias or the full id matches, and the refusal lists the aliases and efforts that pass. Undoing the match turns the test red.
round 1, fixed: no test pinned one hook per query; the matcher has onFailure: "block" while a policy is on; the docs name the fork's ignored effort.
round 1, rightly left, in part (point 2, forked skills): checked from the skill's frontmatter. Skills T3 cannot find are refused under enforce. The parts that can read a different file or model than the one that runs (same name, the instance's alias mapping) are in #987, and the PR says "Part of #128" instead of closing it.
round 1, rightly left, docs only (point 5, the shared catalog's alias mapping): the docs say it next to the Agent paragraph, and #987 item 3 keeps it.
round 1, rightly left, unchanged on purpose (point 8, a repeated remote delegate_task): skipping the check on a repeat would send an unchecked pick to a receiver in advise or off. The extra refusal on a rare repeat is the safer side.
blocker: none
major: the hook refuses skills that run inline and name no model when their frontmatter has an unquoted : in a value. This contradicts the PR and the docs: "a skill that runs inline and names neither is not checked". skillFrontmatter (apps/server/src/fork/claudeAgentModelPolicy.ts:142, the parse at :147) uses plain yaml.parse, and that throws on a line like description: Review the code: bugs and style. The hook then reads the skill as unreadable (:197), so under enforce the call is refused with "T3 cannot read the frontmatter", and under advise every call gets a fail-closed note and a warning log. T3's own skill list reads the same file, because parseSkillFrontmatter repairs exactly this case (apps/server/src/provider/Drivers/ClaudeSkills.ts:72, "Repair Claude's accepted ': ' scalars"), and its comment says Claude Code accepts it. Skills already on disk are often written this way, so turning on enforce refuses skills that start no sub-agent, and the agent cannot fix it: the refusal tells a person to copy the skill. Fix: read the frontmatter with the same repair as the skill list (share the parse step), and add a test with an inline skill whose description has : .
minor: with the policy on (enforce or advise), every new Claude query fails on a Claude Code older than 2.1.295. The SDK refuses initialize when a matcher sets onFailure: "block" and the CLI does not report hook_on_failure_supported. The instance's default binary is claude from the PATH, not the SDK's bundled one, so this depends on what is installed. Threads already open keep running until T3 opens a new process, so the failures start later, at different times. The error the person sees tells them to "remove onFailure: "block" from your hooks", which they cannot do. The docs (docs/fork/README.md:387) only imply it ("with the policy off it is left out, so an older Claude Code still opens"). Say it plainly: with a policy on, Claude Code 2.1.295 or newer is required, in advise too. Better still, use the version T3 already probes (ClaudeProvider.ts --version) to warn in Settings or in the refusal.
minor: a skill T3 reads but drops is replaced by the next same-name skill, and the hook does not refuse it. discoverClaudeSkills skips a SKILL.md whose read fails or whose frontmatter is malformed even after the repair (ClaudeSkills.ts:840, first name wins at :859). The hook then reads a later root's skill of that name (claudeAgentModelPolicy.ts:188). If Claude Code reads the dropped file (it parses YAML its own way), it runs a file the check did not read. This is close to #987 item 2. Worth adding there: "a same-name skill T3 drops, not only one in a place T3 does not read".
minor: skills that change on disk between the check and the run. The hook reads SKILL.md when the call is made, while Claude Code runs the skill as it loaded it (at start, or at its last reload of the skill folders). An agent that rewrites a forked skill's model just before the Skill call can make the check read the new file while the old one runs. This was not verified live (no Claude Code here). Worth a line in #987, since the root fix there ("get the resolved skill from Claude Code") covers it too.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code r2 · reviewer: lens agent (Claude Opus 5.5) · read at: 1d5cee6
verdict: safe to merge
covered: the diff since 9543d16 (own commit 1d5cee6: claudeAgentModelPolicy.ts, modelPolicyCheck.ts, claudeMcpProfile.ts, contracts modelPolicy.ts, the guard test, docs and their tests; the merge of main brings only #974); both round-1 reports, the PR body's round-1 table and issue #987. Also read: discoverClaudeSkills (ClaudeSkills.ts), how the Claude adapter turns skill mentions in a turn's text into a native slash command (ClaudeSkillDispatch.ts, ClaudeAdapterV2.ts makeClaudeUserMessage and the turn and steer paths), the pinned agent SDK's HookCallbackMatcher.onFailure and UserPromptExpansion types, and Claude Code 2.1.326's bundled skill table (built-in plugin skills with context: "fork", and a cannotBeShadowed flag on bundled skills).
checks: ran the changed tests: server claudeAgentModelPolicy, claudeMcpProfile.adapter, claudeMcpProfile, modelPolicyCheck (4 files, 118 passed); contracts modelPolicy (32 passed); fork-kit/model-guard/tests/guard.test.py (98 OK); .github/scripts/fork-owned-reads.test.py (4 ok). No test needed loopback; none was skipped. Undid two fixes one at a time, and each turned its tests red: the namedAs match in checkModelPolicyPick (contracts a pick read as a full id from the name it gave (namedAs) matches a row naming either, server a row saved with the alias matches the alias the call names, in both modes), and the onFailure: "block" choice (the matcher returned without it whatever the policy; a hook that fails or times out refuses while a policy is on (onFailure block) and the adapter's every query carries the model policy's check of Claude's Agent tool once (#128) both failed). Both files restored; the worktree is clean.
state: runs again: the hook and the skill read are pure reads of the settings, the skill files and the call, so the same call gets the same answer (the skill tests call each refusal twice). The matcher is built per query open and added once, first (the adapter test counts it on every opened query over two turns). Stops half-way: a throw refuses (the catch), a settings read that dies refuses and sets onFailure: "block", a skill file that cannot be found, read or parsed refuses under enforce, and a timeout refuses while a policy was on when the query opened. Old state: alias rows saved before (opus) now match the Agent call that names opus; full-id rows match as before; nothing saved changes shape. Empty state: no rows refuses every Agent call and every forked skill under enforce; off or no settings checks nothing and leaves onFailure out. A policy turned on while a query is live keeps the hook (it reads the settings on each call) but without onFailure: "block" until a new process opens; the docs say so ("while a policy is on when the process opens").
round 1, fixed (state lens): an alias row refused every Agent call. Fixed at the root: the pick keeps the name given (namedAs) and a row naming the alias or the full id matches (packages/contracts/src/modelPolicy.ts:461); the effort is still the row's; the refusal lists the aliases and efforts that pass, or says none does and that delegate_task takes the full id. Only the Agent and Skill picks set namedAs, so the MCP routes are unchanged.
round 1, partly fixed and rightly left (code lens): a forked skill started a sub-agent without the Agent tool. The Skill tool is now checked from the skill's frontmatter (context: fork, model, effort), an inline skill that names neither is not checked, and a skill T3 cannot find or read is refused under enforce and noted under advise. The PR now says Part of #128 and only Fixes #802; the rest is in #987. That is the fix round 1 asked for.
round 1, fixed: no onFailure: "block" (now set while a policy is on, verified by undoing it); no test pinned one hook per query (now lengthOf 1, first, one refusal); the docs omitted the fork's ignored effort (added).
round 1, rightly left: the alias mapping through T3's shared Claude list (docs only, #987 point 3; the upstream adapter does not pass its catalog to the fork's plan); a repeated remote delegate_task is still checked (unchanged on purpose: a repeat sends the launch again with its model, so skipping the check would send an unchecked pick).
blocker: none
major: none
minor: a skill can still start a sub-agent without the Skill tool, through the turn's text. The Claude adapter turns a $name mention of any skill T3 lists into a native /name slash command (apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts:3008 and :3247, planClaudeSkillDispatch), and Claude Code expands it as a command, with its frontmatter context: fork, model and effort, without a Skill call and so without this PreToolUse hook (matcher apps/server/src/fork/claudeAgentModelPolicy.ts:281). An agent can put such a mention in the text it sends through delegate_task, create_threads or t3_thread_send; the target's model is checked, but the skill's model runs. This is not new in this PR, and the PR does not claim it (Part of #128). #987 does not list it, so please add it there. The SDK's UserPromptExpansion hook (expansion_type: "slash_command", command_name) could run the same frontmatter check.
minor: under enforce, every skill T3 cannot read is refused, including everyday ones that start no sub-agent: Claude Code's bundled skills (simplify) and its built-in plugin skills, MCP skills and commands. This fails closed, the refusal says why, and the docs (docs/fork/README.md:382) and #987 point 1 say so, so I do not hold the PR for it. A person who later turns on enforce loses these skills for agents.
minor: the refusal's way out, "a person puts a copy in the project's .claude/skills" (apps/server/src/fork/claudeAgentModelPolicy.ts:161), works only if Claude Code then runs the copy. Claude Code 2.1.326 has a cannotBeShadowed flag for bundled skills. For such a skill, T3 would read the copy while Claude Code runs the bundled one, which is #987 point 2 opened by T3's own advice. Say "a skill under another name", or add this case to #987 point 2.

Focus answers: alias rows: the alias and the full id both match, in both modes; the refusal lists what passes, or says none does and what still runs. Skill: context: fork, model or effort in the frontmatter is checked like an Agent call; an inline skill without them is not checked; an unreadable skill is refused under enforce (fail closed, explained, documented). This blocks everyday bundled skills for agents under enforce (minor above). onFailure: "block" only while a policy is on, and off or no settings leave it out (verified by undoing it). The guard test move: the list check is in guard.test.py, and fork-owned-reads passes; app code names fork-kit only in comments. The hook is added once per query: pinned by the adapter test.

🤖 Generated with Claude Code

scuttletoby and others added 2 commits November 22, 2026 16:43
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rser

The Skill check parsed SKILL.md frontmatter with plain yaml.parse, which
throws on an unquoted ": " in a value (description: Review the code: bugs
and style). Claude Code and T3's skill list accept that, so an inline skill
naming no model read as unreadable: refused under enforce, a note under
advise. The check now uses parseSkillFrontmatter from ClaudeSkills.ts (one
source for the repair step): exported there, with the whole frontmatter
record on its parsed result (3 seam lines, announced in fork-seams.json
first).

Docs: with a policy on, in advise too, Claude Code 2.1.295 or newer is
required; an older one refuses every new query.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scuttletoby added a commit that referenced this pull request Nov 22, 2026
List only: announces the 3 upstream lines #978 adds to
apps/server/src/provider/Drivers/ClaudeSkills.ts (export
parseSkillFrontmatter and keep the whole frontmatter record on its parsed
result), in a new entry with "added": [] and its lines under "announced".

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
scuttletoby and others added 3 commits November 22, 2026 16:55
…ines added

The announce (#990) is on main, so the three ClaudeSkills.ts lines move from
"announced" to "added". The model policy's PreToolUse hook now goes into the
plan before main's lazy options wrapper, so adding it reads no options early.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main's test of a plan fixed only as its process opens expected empty
options; on this branch every plan carries the model policy's Agent and
Skill hook, so the test checks that hook is the only option.

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

Copy link
Copy Markdown
Owner Author

not a lens: narrow check after round 2

Verdict: SAFE TO MERGE (head e20902db6e22ef439e2acdc57833e37bdbab11bb)

  1. Round-2 state blocker fixed at the root (92b297e). skillFrontmatter (apps/server/src/fork/claudeAgentModelPolicy.ts:142) now reads through parseSkillFrontmatter, which ClaudeSkills exports (apps/server/src/provider/Drivers/ClaudeSkills.ts:111). The ": " repair now lives in one place, and the policy no longer has its own yaml parse. The tests at apps/server/src/fork/claudeAgentModelPolicy.test.ts:345-348 and :376/:385/:408 cover three cases:

    • an inline skill with a ": " description gets {} under both enforce and advise;
    • fork-colon still has its model read and refused (claude-sonnet-5-5 … in no row);
    • frontmatter that is still broken after the repair (colon-broken) is refused under enforce.

    Undo check: I put the old yaml.parse reader back and the file fails at inline-colon (a fail-closed refusal instead of {}). With the fix restored, it passes.

  2. Merge ba17877, claudeMcpProfile.ts. The hook is added inside planFor on the raw plan, before fixedWhenOpened (apps/server/src/fork/claudeMcpProfile.ts:792). withAgentModelPolicy spreads the plain plan.options, not the lazy getter, and planKey does not read options, so nothing is read early and the tool set is not fixed early. Every success path in planFor goes through that line, and the only refusal paths return errors, not plans. makeClaudeAgentModelPolicyHook always yields a matcher, with onFailure: "block" when the policy is on. The adapter's only plan source is mcpProfiles (ClaudeAdapterV2).

    Undo check: I moved the hook back to the outer plan wrapper (after the lazy wrap). That fails "the set is fixed only once the plan opens a process" (set lean instead of all).

    The changed test (apps/server/src/fork/claudeMcpProfile.test.ts:300) is not weakened: options keys must be exactly ["hooks"] and the PreToolUse matchers exactly the policy's one. A non-blocking nit: it does not also pin Object.keys(options.hooks) to ["PreToolUse"].

  3. .github/fork-seams.json. Compared with main, the only change is the ClaudeSkills.ts entry moving from announced to added. Those 3 lines match ClaudeSkills.ts:36, :99 and :111 exactly. Nothing else changed.

  4. Merge e20902d, FORK_CHANGES.md. I compared it with main, ignoring column padding. Only the Model policy row differs (Agent tool / skill wording, plus the Owner question: must Claude's built-in sub-agents name an allowed model when the policy is on? #128 link). No other row is lost or changed.

Tests: I ran claudeAgentModelPolicy (11), ClaudeSkills (26), claudeMcpProfile (55) and claudeMcpProfile.adapter (12) one at a time on the head. All passed.

🤖 Generated with Claude Code

@scuttletoby
scuttletoby merged commit 51f4873 into main Nov 22, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Model policy: follow-ups from the #793 reviews (Settings marks across machines, sender-side catalog, merged catalogs, agent options)

1 participant