Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#2562"
goal_ref: "別Claude sessionから無関係contextがoperatorへ無断注入されることを抑えつつnative peer coordinationを残し、Herdr経由のcross-Task terminal control/readをTask-awareにASK/DENYする"
change_kind: workflow
dedupe_key: "task-context-v1:cross-session-message-guard"Parent Issue
Parent Goal Ref
- Goal: Herdr上で最大8程度のClaude Code / Claude-GPT operatorを並列利用しても、Tab位置に依存せずcurrent Taskを識別し、ACTIVEな別primary target誤配送はbinding/claimを変更しないadvisoryとして検知しつつClaude処理は継続し、人間はAttention対象だけを把握でき、/clear・/quit・Herdr cold restartを跨いでTask Contextを復元できる状態にする(2026-09-10: 実装: Task ContextのUserPromptSubmit wrong-session guardをadvisory-only化し通常workflowをhard blockしない #2625 contract cascadeによりadvisory-onlyへ更新)。
- Desired Destination(parent scope): Herdr上で最大8程度のNative Claude / Claude-GPT operatorを並列利用しても、Tab位置・worktree・branchをTask identityにせずcurrent Taskを安定識別し、wrong-primary promptをbinding/claimを変更しないadvisoryとして検知しつつClaude処理を継続させ、/clear・/quit・Herdr cold restartを跨いで必要なTask Contextを復元し、人間は既存Herdr/statusLine上のTask・Activity・Attention・runtime healthを見れば運用できる状態にする(v1はlocal SQLiteをlive state SSOTとする薄いcontrol-planeに限定)。Task Contextはordinary workflowのadmission controllerではない。
Current Validated Scope
- 本Issueのwrite-capable scopeは
.claude/settings.json、.claude/hooks/task_context/**、scripts/task-context/**、tests/task-context/**に限定される。既存hook_entry.py/ helper 構造(実装: Native Claude operatorにTask Context hooks・wrong-session guard・statusLine/Herdr projectionを配線する #2564 / PR feat: Native Claude operatorにTask Context hooks・wrong-session guard・statusLine/Herdr projectionを配線する #2615 で確立済みのcanonical implementation structure)を再利用し、別系統のtop-level hook architectureを新設しない。 - 実装: Native Claude operatorにTask Context hooks・wrong-session guard・statusLine/Herdr projectionを配線する #2564(Native operator hook wiring)・実装: workflow trusted signalsとIssue/PR Task equivalenceをTask Contextへ統合する #2565(trusted signal boundary)がmerge済みであることを前提とする。
- runtime-smoke側の設定変更やClaude-GPT統合固有のwiringはこのIssueのwrite-capable scope外(後続child)。
Remaining Parent Gaps
- 本Issueは cross-session inbound guard と cross-Task Herdr control guard のみを扱う。Claude-GPT統合(実装: Claude-GPTをcanonical Task Context DBとoperator runtime profileへ統合する #2567)、runtime-smoke検証(実装: worktree-agent-runtime-smokeにrun-scoped isolated Task Context検証を追加する #2568)、cold restart(実装: Herdr cold restartでTask BindingとNative/Claude-GPT runtime flavorを自動復元する #2569)、integrated acceptance(検証: Task Context v1統合runtime acceptanceをNative/Claude-GPT/Herdrで実証する #2570)は本Issueでは塞がない。
Depends On
- 実装: Native Claude operatorにTask Context hooks・wrong-session guard・statusLine/Herdr projectionを配線する #2564 — Native operator Task Context hook/projection wiring
- 実装: workflow trusted signalsとIssue/PR Task equivalenceをTask Contextへ統合する #2565 — trusted signal authority boundary
Outcome
通常の人間向けHerdr/Native Claude operatorはproject/local設定でcrossSessionInboundを明示的に固定せず、Claude Code native inbound semantics(未設定時のruntime default挙動)を維持する。その上でTask Context-aware PreToolUse guardが、SendMessageの宛先種別(target kind: independent session / in-session subagent / Agent Teams teammate / background・local session / unknown)を現行runtimeのfixtureに基づき区別する。in-session subagent/Agent Teams teammateとのcoordinationは原則Task Contextを理由にASK/DENYしない。既知のsame-Task independent sessionはTask Context理由のdecisionなし、既知のcross-Task independent sessionはASK、宛先Taskを安全に解決できないindependent sessionもASKとする。判別不能であることだけを理由に通常のsubagent/team communication全体をASKにはしない。
この保証はTask Context-managed senderのoutbound tool call(known cross-Task independent sessionへの送信)に限定される。unmanaged/external senderからのinboundを人間承認前に一律で止めるという保証は行わない——inboundはClaude Code native inbound policyの責務であり、crossSessionInboundをproject-wideにhold等へ固定することもしない。Task Contextはsecurity boundaryではなく、managed operator間のmistake-prevention layerである。
Task Contextはnative Claude messagingの独自router/message busにはならず、Task state authority boundaryとHerdr cross-Tab control/readの誤操作防止だけを担当する。
In Scope
- project
.claude/settings.jsonでは通常operatorのcrossSessionInboundを明示的に固定しない(Claude Code native default挙動に委ねる)。 SendMessageのPreToolUse guardは宛先のtarget kindを解決してから分類する:- same-Task independent session: Task Contextだけを理由にblockしない(decisionなし)。
- known cross-Task independent session: ASK。
- in-session subagent / Agent Teams teammate: Task Contextを理由にASK/DENYしない(原則PASS)。
- background/local session: 通常operatorとして同じsame-Task/cross-Task判定に従う。
- 宛先Taskを解決できない(unknown)independent session: ASK。
notify_when_idle(message本文を伴わないidle通知購読)も同一のtarget resolverを使い、same-Task=PASS、cross-Task=ASKとする。- broadcast (
to:"*"等)は現行Claude Codeでサポートされたtool shapeとして確認できていないため、固定ACの対象にせず、実行時にunsupportedとしてClaude native rejectionへ委ねる(現行runtime fixtureでサポートが確認された場合のみ再導入する)。
- inter-session messageはtransportを問わず user authorization / Task completion / Activity transition / Task rebind signalではないことをTask Context contract/testに固定する。
- Native Claude
ListAgentsはTask Context理由でblockしない。 - native peer address/session-nameとTask identityを対応させる独自peer registry/routerは作らない。
- Herdr CLI/control surfaceをTask-aware PreToolUse guardで分類する(現行Herdr CLI commandの有限集合):
- metadata-only discovery (
agent list/get,pane list/get等): ALLOW/no-decision。 - terminal/content read (
agent read,pane read,pane wait-output,terminal session observe): known cross-Taskの場合ASK、same-Taskはdecisionなし。 - input/control (
agent prompt,agent send-keys,pane run,pane send-text,pane send-keys, writableterminal session control, attach/takeover系): known cross-Taskの場合ASK、same-Taskはdecisionなし。 - 宛先Task unresolved(
--machine等でlocal Task解決不能な場合を含む): ASK。 - runtime-smoke isolated namespaceへのhuman/operator cross-control、またはruntime-smokeからhuman/operator namespace controlへの越境: DENY(既存isolation contractを弱めない)。
- Herdr guardはgeneric shell sandboxへ拡大しない。alias、
bash -lc、任意wrapper、直接socket accessまで遮断するsecurity frameworkは作らない。上記finite setに限定する。
- metadata-only discovery (
herdr agent promptをClaude peer messagingの正規channelにせずcross-session terminal controlとして扱う。- cross-Task readもcontext contaminationを起こし得るためguard対象に含める。
- EventJournalには次のbounded metadataのみを記録し、message body・terminal output・full Bash commandは保存しない:
transport/operation/target_kind/source_task_id/destination_task_id(不明時はnull) /decision/reason_code。 - Agent Teams
TaskCompleted/TeammateIdle等をTask Context Activity completionとして扱わない。 - hook hot pathを不必要に重くしない:
SendMessage向けのhookは狭いmatcher(matcher: "SendMessage")を使い、Herdr向けのBash guardはmatcher: "Bash"+ argument-awareiffilter(例:if: "Bash(herdr *)")を使い、無関係なBash呼び出しではguardプロセスをspawnしない。このBash argument filterはbest-effortであり、hard security enforcementではない——Task Contextはmanaged operator間のmistake-prevention layerであり、security sandboxを提供しないため、この限定で目的に対して十分である。
Out of Scope
- message本文のLLM分類。
- 独自message queue / peer registry / delivery service。
- native
SendMessagepoint-to-pointの全面禁止。 - 全Herdr CLI操作をsecurity sandbox化すること。
- runtime-smoke側の設定変更(必要な場合は専用child 導入: Herdr / Claude Code Task Contextで安定識別・誤操作防止・Attention Managementを実現する #2562 Workstream 6で扱う)。
- Claude-GPT generated settings統合(専用child)。
- unmanaged/external senderからのinboundを止める保証(Claude Code native inbound policyの責務)。
Acceptance Criteria
- AC1: Native operatorの
crossSessionInboundはproject/local設定で明示固定されず、native default挙動が維持される。 - AC2: known cross-Task independent sessionへの
SendMessageはPreToolUseでASKされ、human approval前にreceiver Claude contextへ自動配送されない。same-Task independent session、およびin-session subagent/Agent Teams teammateとのpoint-to-pointはTask Contextだけを理由にblockされない。 - AC3: human approval後に
approvedや別Issue指示のpeer messageを受信しても、それだけではTask/Activity/Bindingが変化しない。 - AC4:
notify_when_idleはsame-Task=PASS、known cross-Task independent session=ASKとして同一target resolverで判定される。to:"*"等のbroadcastは現行runtimeでsupportedと確認できない限りACの対象にせず、Claude native rejectionに委ねる。 - AC5: known cross-Task independent sessionへのHerdr content-read(
agent read/pane read/pane wait-output/terminal session observe)とtext-control(agent prompt/agent send-keys/pane run/pane send-text/pane send-keys/ writableterminal session control/ attach・takeover系)はsilent auto-executionされずASKになる。same-Task operation、およびmetadata-only discoveryはTask Contextだけを理由にblockされない。 - AC6: runtime-smoke isolation boundaryへのcross-controlはDENYであり、既存
refuse/peer-tool deny contractを後退させない(既存worktree-agent-runtime-smokeのisolation regression確認で検証する)。 - AC7: peer message本文・他Tab terminal contentをTask Context DB/EventJournalへ保存しない。EventJournalのフィールドは
transport/operation/target_kind/source_task_id/destination_task_id(null許容) /decision/reason_codeのbounded metadataに限定される。 - AC8: Agent Teams lifecycle eventをTask Context workflow completionとして誤認しない。
Verification Commands
# AC1
# AC2
# AC3
# AC4
# AC5
# AC6
# AC7
# AC8
$ uv run --locked pytest tests/task-context -qNative peer delivery / Herdr cross-Tab decisionのAC2/AC5 runtime evidenceは、既存worktree-agent-runtime-smoke(isolation regression確認専用、crossSessionInbound=refuse + SendMessage/ListAgents deny固定のため本Issueのcross-Task ASK自体は再現できない)ではなく、本Issue専用の使い捨て(disposable)isolated Native Claude + Herdr canaryから取得する。generic harnessは新設しない。
Runtime Verification Applicability
decision: immediate
applicable_acs: [AC1, AC2, AC3, AC5]
reason: "cross-Task/same-Task SendMessage guard semanticsとHerdr cross-Tab PreToolUse decisionは実runtime境界で確認する必要がある"
execution_environment: "本Issue専用の使い捨て(disposable) isolated Native Claude + Herdr canary; canonical Task Context test state。既存worktree-agent-runtime-smokeはAC6のisolation regression確認にのみ使用し、cross-Task SendMessage/Herdr ASK evidenceの取得には使用しない。"
skip_conditions: "対象runtime(Herdr/Claude native)を用意できない開発環境ではruntime検証をskipし、static/unit testsのみをbaselineとして扱う。skip時はruntime AC PASSを主張しない。"
fallback_policy: "static/unit testsのみをruntime PASSの代替にしない。"
artifact_requirements: "本Issue専用の使い捨てisolated canaryから取得したbounded evidence(実行ログ抜粋、生成されたSendMessage/Herdr control decision等)をIssue commentへpublic-safeな形で添付する。"Allowed Paths
.claude/settings.json.claude/hooks/task_context/**scripts/task-context/**tests/task-context/**docs/dev/hook-boundaries.mdtests/test_hook_boundaries_doc.py
Scope Delta(2026-09-20)
PreToolUse への新規配線(.claude/settings.json)は、docs/dev/hook-boundaries.md の
hook_boundaries_manifest_v1(機械可読 SSOT)と tests/test_hook_boundaries_doc.py の
ALLOWED_ADDED_HANDLERS allowlist(base/head 間の hook topology delta を明示登録制で
検証する既存 CI gate)を同期しないと check_hook_boundaries.py / python-test-core が
fail する。これは意味論変更ではなく、新規 (hook_entry, PreToolUse) handler 登録を
既存 SSOT/allowlist に機械的に反映するだけの CI-required hygiene であり、In Scope の
固定契約(キー集合・スキーマ・型定義)は変更しない。上記 2 ファイルを Allowed Paths に
追加する。
Stop Conditions
- native Claude messagingをTask Context独自routerへ置換しないと成立しない場合。
- cross-Task操作をすべてDENYしなければ成立しない場合。
- peer message本文/terminal contentの永続保存が必要になる場合。
- runtime-smokeの既存isolationを弱める変更が必要になる場合。
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
- Claude Code cross-session messaging(
crossSessionInbound/SendMessage/ListAgents/notify_when_idle) - Claude Code
PreToolUsehook設計(matcher/ argument-awareiffilter) - Herdr CLI/control surfaceのTask-aware分類
- pytest(deterministic unit/integration tests)
Required Design References
- 導入: Herdr / Claude Code Task Contextで安定識別・誤操作防止・Attention Managementを実現する #2562
- 実装: Native Claude operatorにTask Context hooks・wrong-session guard・statusLine/Herdr projectionを配線する #2564
- 実装: workflow trusted signalsとIssue/PR Task equivalenceをTask Contextへ統合する #2565
.claude/settings.json.claude/hooks/task_context/.claude/skills/worktree-agent-runtime-smoke/SKILL.md
Activity
[-]実装: Task Contextにcross-session inbound holdとcross-Task Herdr control guardを追加する[/-][+]実装: Task ContextにTask-aware cross-session messaging guardとcross-Task Herdr control guardを追加する[/+]squne121 commentedon Sep 20, 2026
結論
#2566 は、現状のまま実装へ渡すには契約上の穴が残っています。特に問題なのは「Task-aware な
SendMessage判定に必要な宛先→Task の対応方法が未定義」「任意 inbound を人間承認前に止められるという保証が native semantics と一致しない」の2点です。2026年9月20日時点で #2566 は open / コメント0件 / Close する実装PRなしでした。依存する #2564 は PR #2615、#2565 は PR #2661 で実装済みです。main の
.claude/settings.jsonもcrossSessionInboundを固定していないため AC1 の土台はありますが、Task Context のPreToolUseguard 自体はまだ main にありません。今回の優先条件を考えると、
crossSessionInbound=holdの全面強制や shell sandbox の強化ではなく、「誤操作防止の薄い UX guard」であることを明確化してから実装するのが適切です。敵対的レビュー findings
Severity | Finding | 失敗シナリオ / 問題 | 修正方針 -- | -- | -- | -- P0 | SendMessage 宛先から Task を引く根拠がない | Claude Code の SendMessage は、別sessionだけでなく subagent・Agent Teams teammate にも同じ tool を使います。PreToolUse が得るのは session_id と tool_input ですが、#2566 は「peer registryを作らない」としつつ、recipient name → native session ID → Binding → Task の解決方法を定義していません。unresolved→ASK にすると普通のsubagent/team連携まで大量にASKになる可能性があります。公式にも ListAgents/SendMessage はこれらを同一名前空間で扱うとあります。 (Claude) | 実装前に現在の Claude Code で SendMessage の PreToolUse fixture を採取し、independent_session / subagent / teammate / background agent / unknown の識別可能性を固定する。in-session agent通信は原則PASS、independent sessionだけTask比較とする。判別不能なケースだけASK。 P0 | Allowed Paths が現在の実装構造とずれている | Issue は .claude/hooks/task_context_* を許可していますが、#2564以降の正規実装は .claude/hooks/task_context/** です。Stop Conditionを文字通り適用すると、既存adapterへ自然に追加できません。別トップレベルhookを作れば回避できますが、実装分散になります。 | Allowed Paths を .claude/hooks/task_context/** に修正。既存 hook_entry.py / helper 構造を継続利用する。 P1 | 「human approval前に inbound text が入らない」は一般には保証できない | crossSessionInbound 未設定時、現在の Claude Code は permission mode の組み合わせにより 自動配信する場合があります。例えばreceiverが通常のpermission prompt modeでsenderも同系統ならdeliveryです。したがって、#2566 の outbound guard を通っていない別sessionからの inbound までは防げません。 (Claude) | hold をproject-wide固定するのではなく、保証範囲を「Task Context-managed senderからのcross-Task outboundは承認なしに送信されない」へ狭める。外部/unmanaged senderからの inbound はnative policyに従うと明記。これが最も低摩擦。 P1 | 指定されたruntime verification経路が自己矛盾している | #2437 / PR #2454 により current worktree-agent-runtime-smoke は意図的に crossSessionInbound=refuse + SendMessage / ListAgents deny を固定しています。#2568 AC10もこの強いisolationを維持要求しています。つまり #2566 AC2 の「実 SendMessage → ASK」をこの harness では発火させられません。 | AC2/AC5 のruntime証拠は 使い捨て isolated Herdr session + Native Claude の専用canary で取る。runtime-smokeは isolation regression の確認だけに使う。 P1 | broadcast ("*"等) 契約が現行 upstream と一致しない | 現行 Agent Teams 公式文書は、全teammateへ送る場合は「recipientごとに1メッセージ」と明記しています。現在の公開 cross-session docs にもbroadcastはありません。古いtool形状を前提にACを固定している可能性が高いです。 (Claude) | * => ASK を固定契約から削除し、実runtime fixtureで to:"*" が現在も有効と確認できた場合だけ復活させる。unsupportedならClaude native rejectionへ任せる。 P1 | notify_when_idle が完全に抜けている | 現行 SendMessage はメッセージなしの one-shot idle subscription にも使え、後でnoticeが届き、asking sessionがidleなら新しいturnを開始します。cross-Task contaminationを扱うならこれは政策対象です。 (Claude) | same-Task notify_when_idle → PASS、cross-Task → ASK。message bodyがなくても同じtarget resolverを使う。 P1 | Herdr の guard 対象 surface が現在の CLI より狭い | 現行 Herdr には Issue記載の agent read/prompt/send-keys, pane read/send-* /run 以外にも terminal session control, terminal session observe, terminal attach, agent attach, pane wait-output 等があります。terminal session control は実際に writable live stream なので、既存列挙だけでは同じcross-Task controlを迂回できます。 (Herdr) | security sandbox化は不要。代わりに「content read / text-control」の有限集合を現行CLIから明示し、そこだけTask-aware ASKする。layout操作全般まで広げない。 P2 | Bash全体に重いguardを載せると過去のhot-path改善を逆行する | PR #2615 fix_delta 6 は、当時 no-op だった Task Context PreToolUse wiringをhot-pathから削除しています。現在のsettingsにも複数のBash PreToolUse siblingがあり、matching hooksは並列実行されます。 (Claude) | matcher:"SendMessage" と、Herdr用は matcher:"Bash" + if:"Bash(herdr *)" を使い、無関係なBashではprocessすらspawnしない。現行Claude Codeの if はsubcommandも見るbest-effort filterで、まさにこの用途向きです。 (Claude) P2 | 親契約が stale | #2566 の Parent Goal Ref はまだ「wrong-primaryをClaude処理前に止める」旧契約ですが、#2625 によって親 #2562 は advisory-only に変更済みです。cross-session機能そのものには直結しませんが、実装agentが古いfail-closed思想を復活させる誘因になります。 | #2562/#2625 の現行 wording に同期。「Task Contextはordinary workflowのadmission controllerではない」を #2566 にも明記。特に直すべき設計境界
一番大きい修正は、inbound protection と outbound mistake prevention を混同しないことです。
現在の Claude Code は receiver 側に
accept / hold / refuseという global な inbound policyを提供しますが、Task-aware な inbound policyは提供していません。未設定時はpermission modeによりdeliver/holdが決まります。 (Claude)したがって「same-Taskは自動、cross-Taskだけ承認」というUXを保ちたいなら、Task Contextが実現できるのは基本的にsender側 PreToolUseです。ここで
crossSessionInbound=holdを固定すると arbitrary inbound は止められますが、same-Task coordinationまで毎回止まり、今回の「ワークフローを邪魔しない」という優先順位に反します。私は #2566 の Outcome を実質的に次の契約へ寄せるのがよいと考えます。
これなら独自routerもdaemonも不要です。
Herdr側は「薄く」実装するのがよい
Herdrについても shell command を完全解析して防御する必要はありません。Claude Code自身が現在、PreToolUse hook の
if:"Bash(herdr *)"のようなargument-aware filteringを提供しており、解析不能commandではhookを起動するbest-effort設計だと明記しています。公式も hard enforcement にはpermission systemを使うよう注意しています。 (Claude)このIssueはsecurity boundaryではないので、むしろそれで十分です。
bash -lc、alias、任意wrapper、手書きPythonからHerdr socketを叩くケースまで防ごうとすると、個人開発のcontrol-planeとして過剰になります。対象は direct/canonical Herdr CLI に限定し、たとえば以下の区分で十分です。
metadata-only (
agent list/get,pane list/get) → no decisionterminal/content read (
agent read,pane read,pane wait-output,terminal session observe) → known cross-Task ASKinput/control (
agent prompt/send-keys,pane run/send-text/send-keys, writableterminal session control, takeover系attach) → known cross-Task ASKsame-Task → no Task Context decision
target unresolved /
--machine等でlocal Task解決不能 → ASKruntime-smoke namespace境界 → DENY
これは Herdr の現在の pane/agent/terminal modelとも整合します。 (Herdr)
Acceptance Criteria も少し組み替えるべきです
現在 AC2 と AC4 がかなり重複しているので、その枠を upstream drift 対策へ使う方が価値があります。実装前の必須fixtureとして、少なくとも「independent session same Task」「independent session different Task」「named/raw-ID subagent」「Agent Teams teammate」「
notify_when_idleonly」「現在のto:"*"の実挙動」を現在インストールされているClaude Codeから採取し、guard classifierのgolden fixtureにすることを推奨します。また EventJournal は
transport,operation,target_kind,source_task_id,destination_task_id|null,decision,reason_code程度に閉じ、message, raw terminal output, full Bash commandを保存しないことをsentinel testで直接検証するとよいです。これは新しいsecurity frameworkではなく、後から「なぜASKされたか」を調べられる最低限のobservabilityです。推奨アクション
#2566 は impl-review-loop に入れる前に、一度 issue-refinement-loop でcontract correctionするのを推奨します。 特に実装開始条件は次の4点です。
Allowed Paths を
.claude/hooks/task_context/**に修正する。SendMessage.to→ target kind / Task の解決契約を、current-runtime fixtureに基づいて決定する。「任意inboundを承認前に止める」という過剰保証を削り、managed outbound guardへ保証範囲を限定する。
runtime-smokeではSendMessage ASKを検証できないため、#2566専用の使い捨て Native+Herdr canaryをruntime evidence sourceにする。
この4点を直せば、大掛かりなsecurity/harnessを追加せず、通常のsame-Task coordinationはほぼ無摩擦、事故りやすいcross-Task操作だけASKという、親 #2562 の目的にかなり素直な実装になります。
## 結論#2566 は、現状のまま実装へ渡すには契約上の穴が残っています。特に問題なのは「Task-aware な
SendMessage判定に必要な宛先→Task の対応方法が未定義」「任意 inbound を人間承認前に止められるという保証が native semantics と一致しない」の2点です。2026年9月20日時点で #2566 は open / コメント0件 / Close する実装PRなしでした。依存する #2564 は PR #2615、#2565 は PR #2661 で実装済みです。main の
.claude/settings.jsonもcrossSessionInboundを固定していないため AC1 の土台はありますが、Task Context のPreToolUseguard 自体はまだ main にありません。今回の優先条件を考えると、
crossSessionInbound=holdの全面強制や shell sandbox の強化ではなく、「誤操作防止の薄い UX guard」であることを明確化してから実装するのが適切です。敵対的レビュー findings
SendMessage宛先から Task を引く根拠がないSendMessageは、別sessionだけでなく subagent・Agent Teams teammate にも同じ tool を使います。PreToolUse が得るのはsession_idとtool_inputですが、#2566 は「peer registryを作らない」としつつ、recipient name → native session ID → Binding → Task の解決方法を定義していません。unresolved→ASK にすると普通のsubagent/team連携まで大量にASKになる可能性があります。公式にもListAgents/SendMessageはこれらを同一名前空間で扱うとあります。 (Claude)SendMessageの PreToolUse fixture を採取し、independent_session / subagent / teammate / background agent / unknownの識別可能性を固定する。in-session agent通信は原則PASS、independent sessionだけTask比較とする。判別不能なケースだけASK。.claude/hooks/task_context_*を許可していますが、#2564以降の正規実装は.claude/hooks/task_context/**です。Stop Conditionを文字通り適用すると、既存adapterへ自然に追加できません。別トップレベルhookを作れば回避できますが、実装分散になります。.claude/hooks/task_context/**に修正。既存hook_entry.py/ helper 構造を継続利用する。crossSessionInbound未設定時、現在の Claude Code は permission mode の組み合わせにより 自動配信する場合があります。例えばreceiverが通常のpermission prompt modeでsenderも同系統ならdeliveryです。したがって、#2566 の outbound guard を通っていない別sessionからの inbound までは防げません。 (Claude)holdをproject-wide固定するのではなく、保証範囲を「Task Context-managed senderからのcross-Task outboundは承認なしに送信されない」へ狭める。外部/unmanaged senderからの inbound はnative policyに従うと明記。これが最も低摩擦。worktree-agent-runtime-smokeは意図的にcrossSessionInbound=refuse+SendMessage/ListAgentsdeny を固定しています。#2568 AC10もこの強いisolationを維持要求しています。つまり #2566 AC2 の「実 SendMessage → ASK」をこの harness では発火させられません。broadcast ("*"等)契約が現行 upstream と一致しない* => ASKを固定契約から削除し、実runtime fixtureでto:"*"が現在も有効と確認できた場合だけ復活させる。unsupportedならClaude native rejectionへ任せる。notify_when_idleが完全に抜けているSendMessageはメッセージなしの one-shot idle subscription にも使え、後でnoticeが届き、asking sessionがidleなら新しいturnを開始します。cross-Task contaminationを扱うならこれは政策対象です。 (Claude)same-Task notify_when_idle → PASS、cross-Task → ASK。message bodyがなくても同じtarget resolverを使う。agent read/prompt/send-keys,pane read/send-* /run以外にもterminal session control,terminal session observe,terminal attach,agent attach,pane wait-output等があります。terminal session controlは実際に writable live stream なので、既存列挙だけでは同じcross-Task controlを迂回できます。 (Herdr)matcher:"SendMessage"と、Herdr用はmatcher:"Bash"+if:"Bash(herdr *)"を使い、無関係なBashではprocessすらspawnしない。現行Claude Codeのifはsubcommandも見るbest-effort filterで、まさにこの用途向きです。 (Claude)特に直すべき設計境界
一番大きい修正は、inbound protection と outbound mistake prevention を混同しないことです。
現在の Claude Code は receiver 側に
accept / hold / refuseという global な inbound policyを提供しますが、Task-aware な inbound policyは提供していません。未設定時はpermission modeによりdeliver/holdが決まります。 (Claude)したがって「same-Taskは自動、cross-Taskだけ承認」というUXを保ちたいなら、Task Contextが実現できるのは基本的にsender側 PreToolUseです。ここで
crossSessionInbound=holdを固定すると arbitrary inbound は止められますが、same-Task coordinationまで毎回止まり、今回の「ワークフローを邪魔しない」という優先順位に反します。私は #2566 の Outcome を実質的に次の契約へ寄せるのがよいと考えます。
これなら独自routerもdaemonも不要です。
Herdr側は「薄く」実装するのがよい
Herdrについても shell command を完全解析して防御する必要はありません。Claude Code自身が現在、PreToolUse hook の
if:"Bash(herdr *)"のようなargument-aware filteringを提供しており、解析不能commandではhookを起動するbest-effort設計だと明記しています。公式も hard enforcement にはpermission systemを使うよう注意しています。 (Claude)このIssueはsecurity boundaryではないので、むしろそれで十分です。
bash -lc、alias、任意wrapper、手書きPythonからHerdr socketを叩くケースまで防ごうとすると、個人開発のcontrol-planeとして過剰になります。対象は direct/canonical Herdr CLI に限定し、たとえば以下の区分で十分です。
agent list/get,pane list/get) → no decisionagent read,pane read,pane wait-output,terminal session observe) → known cross-Task ASKagent prompt/send-keys,pane run/send-text/send-keys, writableterminal session control, takeover系attach) → known cross-Task ASK--machine等でlocal Task解決不能 → ASKこれは Herdr の現在の pane/agent/terminal modelとも整合します。 (Herdr)
Acceptance Criteria も少し組み替えるべきです
現在 AC2 と AC4 がかなり重複しているので、その枠を upstream drift 対策へ使う方が価値があります。実装前の必須fixtureとして、少なくとも「independent session same Task」「independent session different Task」「named/raw-ID subagent」「Agent Teams teammate」「
notify_when_idleonly」「現在のto:"*"の実挙動」を現在インストールされているClaude Codeから採取し、guard classifierのgolden fixtureにすることを推奨します。また EventJournal は
transport,operation,target_kind,source_task_id,destination_task_id|null,decision,reason_code程度に閉じ、message, raw terminal output, full Bash commandを保存しないことをsentinel testで直接検証するとよいです。これは新しいsecurity frameworkではなく、後から「なぜASKされたか」を調べられる最低限のobservabilityです。推奨アクション
#2566 は impl-review-loop に入れる前に、一度 issue-refinement-loop でcontract correctionするのを推奨します。 特に実装開始条件は次の4点です。
.claude/hooks/task_context/**に修正する。SendMessage.to→ target kind / Task の解決契約を、current-runtime fixtureに基づいて決定する。この4点を直せば、大掛かりなsecurity/harnessを追加せず、通常のsame-Task coordinationはほぼ無摩擦、事故りやすいcross-Task操作だけASKという、親 #2562 の目的にかなり素直な実装になります。
squne121 commentedon Sep 20, 2026
推奨アクションは、#2566 を実装へ渡す前に、指定コメント
5748944771を OWNER の operator-selected human context としてissue-refinement-loopに投入し、contract correction を完了させることです。GitHub の現行状態では #2566 は open、依存 #2564/#2565 は completed、指定コメントのauthor_associationはOWNERでした。コメントの主要指摘は現在の公式仕様とも整合します。
SendMessageは independent session だけでなく subagent / Agent Teams teammate にも共通で、notify_when_idleも同じ tool を使います。またcrossSessionInbound未指定時は sender/receiver の permission mode に応じて deliver/hold が決まるため、「任意の inbound を常に人間承認前に止める」という契約は強すぎます。([Claude]1) Herdr 側もpane read、pane wait-output、agent read/prompt/send-keys、terminal session control/observeなど実際に read/control surface が広いため、コメントの「有限集合を現在の CLI に合わせる」という修正が妥当です。([Herdr]2) Claude Code のif: "Bash(...)"は argument-aware ですが best-effort filter なので、security boundary ではなく mistake-prevention layer とする今回の設計に合います。([Claude]3)現行
issue-refinement-loopは implementation Issue が approved + fresh readinessgoになった後、root thread が同一 turn で canonical root transition を実行する設計です。そのため、下のプロンプトでは手動で impl を先走らせず、router がinvoke_impl_review_loopを返した場合だけ自動 handoff を許可しています。通常の refinement iteration では人間確認を求めません。対象リポジトリは
squne121/loop-protocolです。Issue:
#2566
今回の authoritative anchor comment:
#2566 (comment)
使用する skill:
https://github.com/squne121/loop-protocol/tree/main/.claude/skills/issue-refinement-loop
あなたは既に Claude Code の auto mode で起動済みです。Issue #2566 に対して、current
mainの.claude/skills/issue-refinement-loop/SKILL.mdとその normative references / scripts を正本として、issue-refinement-loopを最後まで自律実行してください。今回の anchor comment
5748944771は、私が明示的に対象として選択した repository OWNER の human context です。URL だけから origin を推測するのではなく、この指示を authority としてpreflight.run.with_human_contextlane を使用してください。agent_reportや unlabeled anchor として扱わないでください。「人間承認不要」とは repo loop iteration の通常継続について人間確認を挟まないという意味です。Claude Code の permission mode は既に auto mode なので変更しないでください。
bypassPermissions、--dangerously-skip-permissions等へ変更せず、skill のloop_iteration_approval_gate.default_required: falseをそのまま使用してください。通常の needs-fix、Issue body rewrite、fresh review、fresh readiness、controlled GitHub mutationについて「続けますか?」等の確認を私に求めず、自律的に進めてください。まず current
mainを fresh に読み、Issue #2566 本文、anchor comment、親 #2562、#2625、依存 #2564/#2565、その実装 PR、.claude/settings.json、.claude/hooks/task_context/**、scripts/task-context/**、tests/task-context/**、worktree-agent-runtime-smokeの isolation contract を確認してください。過去コメント内の repository state や upstream 仕様を current truth としてコピーせず、fresh evidence を優先してください。SubAgent を必ず使用してください。canonical Step 1 の
codebase-investigatorを起動して repository evidence、existing Task Context architecture、current hook wiring、Allowed Paths、親契約、runtime-smoke isolation、関連 Issue/PR を調査させてください。anchor comment は Claude Code / Herdr の現行仕様に依存する dispositive external claims を含むため、planner / skill の web-research routing が applicable と判断する場合はweb-researcherも起動し、Anthropic/Claude Code と Herdr の一次資料を優先して確認してください。SubAgent は fire-and-forget にしないでください。起動した全 SubAgent の agent/session ID を把握し、それぞれの final result と terminal completion を取得するまで必ず待ってください。途中経過、timeout 待ち、部分出力、Herdr 上の
working状態を completion とみなさないでください。各 phase は、その phase が依存する SubAgent がcompletedまたは skill が定義する typed failure に到達して join されるまで先へ進めないでください。nested SubAgent delegation は行わせないでください。SubAgent の結果は evidence であり、LOOP_STATE、routing、最終 verdict、GitHub mutation の authority は root/main thread に保持してください。anchor comment の adversarial findings を単純転記するのではなく、fresh repository/runtime/upstream evidence に照らして contract correction を行ってください。ただし、この OWNER anchor が明示している以下の方向性は通常の「新規 scope change」として人間へ差し戻さず、trusted human-context contract update として処理してください。
Issue #2566 の Allowed Paths は stale な
.claude/hooks/task_context_*ではなく current canonical implementation structure の.claude/hooks/task_context/**に同期してください。既存hook_entry.py/ helper 構造を再利用する前提とし、別系統の top-level hook architecture を新設しないでください。SendMessageguard の契約は、current Claude Code における実際の target shape を根拠にしてください。independent session、subagent、Agent Teams teammate、background/local session、unknown、およびnotify_when_idleを区別できるかを current runtime fixtureまたは authoritative current docsで確認してください。in-session subagent/team coordination は原則 Task Context を理由に ASK/DENY せず、independent session についてだけ Task identity comparison を行う設計を優先してください。既知 same-Task は no Task Context decision、既知 cross-Task は ASK、independent-session で destination Task を安全に解決できない場合は ASK としてください。判別不能だからという理由だけで通常 subagent/team communication 全体を ASK にしないでください。to:"*"等の broadcast 契約は、現在の Claude Code で本当に有効な tool shape であることを fixture / current authoritative docs で確認してください。現在 unsupported なら固定 AC から除去し、Claude native rejection に任せてください。historical assumption を互換性のためだけに残さないでください。inbound protection と outbound mistake prevention を分離してください。
crossSessionInbound=holdを project-wide に固定して arbitrary inbound isolation を実現しようとしないでください。保証範囲は、Task Context-managed sender から既知 cross-Task independent session への outbound operation が Task Context guard を経由して ASK になることまでとしてください。unmanaged/external sender からの inbound は Claude Code native inbound policy の責務であり、Task Context が Task-aware isolation を保証するとは書かないでください。Task Context は security boundary ではなく managed operator 間の mistake-prevention layer です。親 #2562 は #2625 により advisory-only 契約へ更新済みなので、#2566 の Parent Goal Ref / Desired Destination に残る「wrong-primary を Claude 処理前に止める」旧 wording を current parent contract と同期してください。ordinary workflow の admission controller を復活させないでください。
Herdr guard は generic shell sandbox に拡大せず、current Herdr CLI の direct/canonical content-read / text-control surface を finite set として整理してください。metadata-only operation は no Task Context decision、terminal/content read は known cross-Task ASK、text/input/control/takeover は known cross-Task ASK、same-Task は no Task Context decision、local Task を解決不能な target は ASK、runtime-smoke namespace と human/operator namespace の crossing は既存 isolation contract に従って DENY としてください。
agent read/prompt/send-keys、pane read/wait-output/run/send-text/send-keys、terminal session observe/control、attach/takeover 系について current CLI を確認してください。alias、bash -lc、任意 wrapper、直接 socket access まで完全遮断する security framework は作らない前提を Issue に明記してください。hook hot path を不必要に重くしないでください。current Claude Code が対応していることを確認した上で、
SendMessageは狭い matcher、Herdr Bash guard は argument-awareiffilter 等を利用する方向を contract に反映してください。ただし Bash argument filter は best-effort であり hard security enforcement ではないことと、今回それで問題ない理由を mistake-prevention scope と結び付けてください。EventJournal は bounded metadata のみに限定してください。少なくとも transport / operation / target_kind / source_task_id / destination_task_id|null / decision / reason_code 程度を上限の目安とし、message body、terminal output、full Bash command を保存しないことを acceptance/test contract で検証可能にしてください。
runtime verification も修正してください。existing
worktree-agent-runtime-smokeは cross-session isolation regression の確認に使い、そこで #2566 のSendMessage -> ASKを証明しようとしないでください。cross-Task SendMessage / Herdr cross-Tab decision の runtime evidence が必要なら、#2566 用の disposable isolated Native Claude + Herdr canary を最小限の evidence source としてください。generic harness を新設しないでください。AC2/AC4 など重複 AC は必要なら整理し、current-runtime drift に対する fixture coverage、
notify_when_idle、target-kind resolution、EventJournal no-content sentinel、managed outbound の保証境界を検証可能な形にしてください。Acceptance Criteria は implementation detail の羅列ではなく、実装 agent が判定可能な observable contract にしてください。issue-refinement-loopの canonical routing を勝手に再実装しないでください。Step 0 / planner、investigation、conditional web research、canonical Step 2 root review pipeline、必要なら Step 2.5 semantic design review、Step 4 controlled issue-editor rewrite、fresh readback、fresh review、fresh contract readiness を skill の SSOT 通りに進めてください。canonical Step 2 の代わりに legacyissue-reviewerSubAgent を独自起動して verdict を作らないでください。max_iterations は current skill の既定 3 を使用してください。needs-fix が auto-continuable である限り各 iteration を人間承認なしで継続してください。body 更新後は prior review/readiness を再利用せず fresh body SHA に束縛された review/readiness を取得してください。
停止は current skill が定義する genuine hard stop のみに限定してください。具体的には、fresh evidence を尽くしても owner/value judgment が本当に必要、trusted authority が矛盾、環境・runtime failure が Issue rewrite では解消不能、max_iterations 到達、destructive/heavy mutation が未承認、新規 Issue split が本当に必要、外部権限昇格が必要、など typed
human_judgment_required/operator_intervention_requiredに該当する場合です。今回の OWNER anchor が既に具体的に承認している Allowed Paths 修正、managed-outbound への保証縮小、parent advisory wording 同期、専用 disposable canary への verification source 修正だけを理由に人間へ差し戻さないでください。refinement の成功条件は単なる reviewer
approveではありません。fresh Issue body に対する canonical approval と freshCONTRACT_REVIEW_RESULT_V1.status == "go"、freshness gate を満たしてimplementation_readyまで到達してください。approved termination に到達したら、current
issue-refinement-loopが要求する root-owned synchronous transition を同じ root/main turn で実行してください。root_entry_router.pyの fresh result がinvoke_impl_review_loopなら、人間確認を挟まず canonical handoff に従ってください。rerun_contract_review、rerun_base_preflight、stop等ならその typed route に従い、自然言語判断でinvoke_impl_review_loopを捏造しないでください。refinement が ready になる前に implementation を開始しないでください。root transition が
impl-review-loopを実際に起動した場合も、merge 自体は実行しないでください。実装側の current skill が許す merge 直前状態までの作業だけに従ってください。最後に、実行した SubAgent と各 terminal status、anchor classification、Issue body の before/after SHA、主要 contract corrections、fresh review verdict、fresh readiness result、termination reason、root transition result、残存 blocker があればその typed reason を短く報告してください。過去コメントの結論ではなく、今回取得した fresh evidence に基づく結果だけを最終報告にしてください。
この形なら、指定コメントを authority として使いつつ、コメント内の upstream 情報自体は fresh evidence で再検証し、通常の修正ループでは止まらない指示になります。
squne121 commentedon Sep 20, 2026
root-owned entry router audit
route: invoke_impl_review_loop
reason: fresh_review_go_live_equality
squne121 commentedon Sep 20, 2026
issue-refinement-loop 完了報告(Issue #2566)
OWNER anchor comment(#2566 (comment)、author_association: OWNER,
preflight.run.with_human_contextlane で trusted human context として処理)を根拠に contract correction を実施しました。実行経過
.claude/hooks/task_context/**の canonical structure、親 導入: Herdr / Claude Code Task Contextで安定識別・誤操作防止・Attention Managementを実現する #2562 の advisory-only 契約(実装: Task ContextのUserPromptSubmit wrong-session guardをadvisory-only化し通常workflowをhard blockしない #2625 反映済み)、依存 実装: Native Claude operatorにTask Context hooks・wrong-session guard・statusLine/Herdr projectionを配線する #2564/実装: workflow trusted signalsとIssue/PR Task equivalenceをTask Contextへ統合する #2565 の merge 状況を確認。SendMessagetarget shape(independent session / in-session subagent / Agent Teams teammate / background・local / cloud / remote control session、notify_when_idleサポート)とto:"*"broadcast 非サポートを一次資料で確認。verdict: approve(構造チェックのみ)。assessment: findings(blocker 2件 / high 1件 / medium 4件 / low 3件)。issue-editor): Allowed Paths の canonical path 同期(.claude/hooks/task_context_*→.claude/hooks/task_context/**)、SendMessage target kind taxonomy 追加、runtime evidence source の disposable canary 化、broadcast/notify_when_idle/Herdr CLI surface/Parent Goal Ref/EventJournal bounded fields/hot path軽量化を反映。body_sha256:ad9fda7a...591→16ca37fe...c06。verdict: approve。effective_verdict: approve。結論
implementation_readyに到達。fresh Issue body(body_sha256: sha256:16ca37fe5f223ae12563afcc387e2a5968c63960b3d86abe1eefca89b5a70c06)に対する canonical approval と fresh contract readiness(deterministic + semantic 両 approve)を満たしました。root_entry_router.py::run_root_transition()の fresh 判定:route: invoke_impl_review_loop(reason: fresh_review_go_live_equality、reviewed_body_sha256 == observed_live_body_sha256、reviewed_base_sha == observed_base_sha)。同一 turn 内でimpl-review-loopへ handoff します。squne121 commentedon Sep 20, 2026
implement-issue: 実装完了 (2026-09-20)
.claude/worktrees/issue-2566-task-context-task-aware-cross-session-meworktree-issue-2566-task-context-task-aware-cross-session-meuv run --locked pytest tests/task-context -q— 384 passed /pnpm typecheck/pnpm lint/pnpm test(1939 passed)/pnpm build/uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py(24 passed)/uv run ruff check— いずれも成功。実装概要
SendMessage/notify_when_idleの宛先種別(in-session subagent / same-Task independent session / known cross-Task independent session / unknown independent session / unaddressed broadcast)を、既存のexecution_runs(SubagentStart のagent_id)・tab_bindings(session⇔Task)・runtime_locations(Herdr pane locator⇔Binding)だけで解決する純粋な target-kind resolver を新設(scripts/task-context/task_context_target_kind.py)。新しい peer registry/router は作っていない。task_context_hook_flows.on_pre_tool_useを実装し、Herdr CLI の finite guarded subcommand 集合(metadata-only discovery / content-read / control)も同一 resolver で判定する。ListAgentsを含む他の tool は従来どおり observability-only のまま。hook_entry.pyに_VALID_DECISIONSへ"ask"を追加し、実際の Claude CodehookSpecificOutput.permissionDecision(allow/deny/ask)契約へ変換する。decision == "pass"のときは何も出力せず、既存の hard deny(例:worktree-agent-runtime-smokeのSendMessage/ListAgentsdeny)を上書きしない設計。pre_tool_use_classifier.looks_like_herdr_commandによる argument-aware な early exit を持ち、herdrで始まらない Bash コマンドはtask-contextctlsubprocess を spawn しない。.claude/settings.jsonにPreToolUsehook entry(matcher: "SendMessage"/matcher: "Bash")を追加。crossSessionInboundは明示固定していない(AC1)。transport/operation/target_kind/source_task_id/destination_task_id/decision/reason_codeの bounded metadata のみを記録する(AC7、既存 allowlist へ additive 拡張)。Runtime Verification(AC1/AC2/AC3/AC5、
decision: immediate)本実装セッションには disposable な isolated Native Claude + Herdr canary 環境が利用できなかったため、runtime evidence は SKIP している(Issue 本文の skip_conditions に従い、runtime PASS は主張しない)。static/unit pytest(実
hook_entry.pysubprocess 起動を含むtests/task-context/test_pre_tool_use_subprocess.py等)が PASS baseline。実 Herdr + 複数 Native Claude session による canary 検証は、disposable canary 環境が用意できる後続の実行で別途行う想定。fix: PreToolUse hook boundaries manifest / allowlist を同期する
fix: Herdr CLI global selector/attach parsing・PreToolUse hot-path・AC6…
squne121 commentedon Sep 20, 2026
impl-review-loop: 完了 (2026-09-21T00:00:00Z)
fix: SendMessage.to の independent session を Claude Code 自身の on-disk s…
feat: Task Context に Task-aware cross-session messaging guard と cross…