Repository navigation
Closed
Labels
state/queuedQueued for implementation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: research
parent_issue: "#813"
goal_ref: "context-mode MCP を Claude Code に段階的導入し、大出力を扱う read-only 調査補助として運用する"
change_kind: research-onlyParent Issue
Current Objective
upstream context-mode #756 の cwd bug が loop-protocol の worktree 運用に影響するかを検証し、ctx_execute を許可するか quarantine 継続するかの判断材料を作る。
Background
upstream #756 では、Claude Code が worktree にいるにもかかわらず ctx_execute が main checkout 側で実行される問題が報告されている。read-only コマンドであっても、cwd が違えば rg / git log / test log 参照結果が誤る。
本 Issue の目的は「ctx_execute を許可できるか判断する」ことではなく、「許可しない理由を runtime evidence として固定する」ことである。初期判断は quarantine 継続とし、その根拠を artifact に記録する。
Outcome
current project policy で ctx_execute が明示 deny であることを構造化 parse で確認し、Bash と ctx_execute の cwd / repo root / branch / HEAD SHA の比較 probe 結果(probe 不可の場合はその記録を含む)が artifact 化される。ctx_execute / ctx_batch_execute / ctx_execute_file の execution-like tool quarantine matrix が docs に記録され、quarantine_continue 判定が固定される。
In Scope
- current project policy で
mcp__context-mode__ctx_executeが明示 deny であることの構造化 parse 確認 - 通常 profile で
ctx_executeが permission-denied になることの確認 - 比較 probe が必要な場合は commit されない isolated local profile で固定 read-only command のみを実行
- worktree / main checkout / nested repo での Bash vs
ctx_executeの cwd 比較 pwd,printf '%s\n' "${CLAUDE_PROJECT_DIR:-<unset>}",git rev-parse --show-toplevel,git branch --show-current,git rev-parse HEAD,git rev-parse --is-inside-work-tree- upstream feat-storage-add-snapshot-schema-migration-issue-736 #756 の current state / installed context-mode version の確認
ctx_execute/ctx_batch_execute/ctx_execute_fileの execution-like tool quarantine matrix 作成- artifact と docs への結果記録
- artifact schema test の追加
Out of Scope
ctx_executeによる build / test / git write 操作ctx_executeの恒久許可- upstream context-mode の修正
ctx_batch_execute/ctx_execute_fileの routine-use 許可判断(今 Issue は deny/quarantine 方針の記録のみ)
Acceptance Criteria
- AC1: current project policy で
mcp__context-mode__ctx_executeが明示 deny であることを.claude/settings.json/registered-tools.json/permission-policy.jsonの構造化 parse で検証している - AC2: 通常 profile で
ctx_executeが実行されず permission-denied になることを artifact に記録している。実行できた場合は Stop Condition - AC3: 比較 probe を行う場合、commit されない isolated local profile で固定 read-only command のみを実行し、probe profile が commit されていないこと、deny が復元されたことを artifact に記録している
- AC4: main checkout / linked worktree / nested repo の各 case で Bash と
ctx_executeのpwd,git rev-parse --show-toplevel,git branch --show-current,git rev-parse HEAD,git rev-parse --is-inside-work-treeを比較している - AC5:
CLAUDE_PROJECT_DIRは informational field として記録し、session cwd の正否判定には使っていない - AC6: upstream feat-storage-add-snapshot-schema-migration-issue-736 #756 の current state / fetched_at / installed context-mode version / local probe result を artifact に保存している
- AC7:
ctx_execute,ctx_batch_execute,ctx_execute_fileの execution-like tool quarantine matrix が docs に記録されている - AC8: upstream feat-storage-add-snapshot-schema-migration-issue-736 #756 が open、local probe 不一致、probe 不可、または sibling execution-like tools 未評価のいずれかなら、verdict は
quarantine_continue - AC9:
docs/dev/agent-ops/context-mode-cwd-quarantine.mdに build / test / git / repo grep / log summary を context-mode execution-like tools へ移さない方針が明記されている - AC10: artifact schema test が null / stale / unredacted path / token-like value を fail する
Verification Commands
# AC1
rg -q "ctx_execute" .claude/settings.json
# AC2
uv run python3 -c "import json; d=json.load(open('.claude/artifacts/context-mode/cwd-comparison-result.json')); assert d['project_policy']['ctx_execute'] == 'deny'"
# AC3
uv run python3 -c "import json; d=json.load(open('.claude/artifacts/context-mode/cwd-comparison-result.json')); p=d.get('probe', {}); assert p.get('profile_committed') == False"
# AC4
uv run python3 -c "import json; d=json.load(open('.claude/artifacts/context-mode/cwd-comparison-result.json')); assert all(k in d['cases'] for k in ['main_checkout','linked_worktree','nested_repo'])"
# AC5
uv run python3 -c "import json; d=json.load(open('.claude/artifacts/context-mode/cwd-comparison-result.json')); assert 'informational_only' in d and 'claude_project_dir' in d['informational_only']"
# AC6
uv run python3 -c "import json; d=json.load(open('.claude/artifacts/context-mode/cwd-comparison-result.json')); assert d.get('upstream_issue_756_state') in ('open','closed') and bool(d.get('context_mode_version')) and bool(d.get('fetched_at'))"
# AC7
rg -q "ctx_batch_execute" docs/dev/agent-ops/context-mode-cwd-quarantine.md
# AC8
uv run python3 -c "import json; d=json.load(open('.claude/artifacts/context-mode/cwd-comparison-result.json')); assert d['verdict'] in ('quarantine_continue','probe_blocked_quarantine_continue')"
# AC9
rg -q "移さない" docs/dev/agent-ops/context-mode-cwd-quarantine.md
# AC10
uv run pytest tests/context_mode/test_cwd_quarantine_artifact.py -vAllowed Paths
.claude/artifacts/context-mode/**docs/dev/agent-ops/context-mode-cwd-quarantine.mdtests/context_mode/test_cwd_quarantine_artifact.py
Stop Conditions
.claude/settings.jsonを commit 上でctx_executeallow に変更する必要が出た場合- standalone MCP mode / SQLite surrogate だけで Claude Code worktree cwd 安全性を結論づけようとした場合
ctx_batch_execute/ctx_execute_fileの実行相当性を評価せずにctx_executequarantine を解除しようとした場合CLAUDE_PROJECT_DIRを session cwd と同一視する設計になった場合- artifact に
null,pending,unknownを含んだままstatus: passになる場合 - upstream feat-storage-add-snapshot-schema-migration-issue-736 #756 が open のまま build/test/git/read-only repo command を context-mode execution-like tools に解放しようとした場合
Delivery Rule
- research-only
- PR は docs / artifact のみ
- child 1 / child 2 完了後に着手する
Handoff Contract
Current ObjectiveBounded Current ContextOpen QuestionsNext ActionArtifact Refs
Metadata
Metadata
Assignees
Labels
state/queuedQueued for implementation
Activity
squne121 commentedon Jun 13, 2026
判定: REQUEST_CHANGES
#826 の方向性は妥当ですが、現契約のまま実装させると 「ctx_execute は危ないので隔離する」という結論を、危ない
ctx_executeをどう安全に検証したか不明なまま artifact 化する 形になります。現時点では merge-ready な Issue 契約ではありません。#826 は upstream #756 の cwd bug を検証し、Bash と
ctx_executeの cwd / repo root / branch / HEAD SHA を比較する research-only Issueです。初期判断は quarantine 継続です。 親 #813 でもctx_executeは child 3 完了まで明示 deny、rg/git log/ test log 要約も例外扱いしない方針になっています。重大ブロッカー
1.
ctx_executeを deny しているのに、#826 はctx_execute実行比較を要求している現在の
.claude/settings.jsonはmcp__context-mode__ctx_executeとmcp__context-mode__ctx_fetch_and_indexを明示 deny しています。 それ自体は正しいですが、#826 の AC1 は Bash とctx_executeの比較を要求しています。この矛盾を解消するには、Issue に次の二段階を明記してください。
ctx_executeが permission deny されることを artifact 化する。.claude/settings.jsonを PR 上で allow に変更して検証する実装は不可です。2.
ctx_batch_execute/ctx_execute_fileが抜けているcontext-mode は 11 MCP tools を登録し、その中に
ctx_batch_execute,ctx_execute,ctx_execute_file,ctx_index,ctx_search,ctx_fetch_and_indexがあります。([GitHub]1) current artifact でも 11 tool 登録が確認されています。問題は、明示 deny されているのが
ctx_executeとctx_fetch_and_indexだけで、ctx_batch_execute/ctx_execute_fileは settings 上の明示 deny に入っていないことです。 context-mode README 上、ctx_batch_executeは複数コマンド実行、ctx_execute_fileは sandbox 内でファイル処理を行う tool と説明されています。([GitHub]1)#826 は
ctx_execute単体ではなく、少なくとも次の quarantine matrix を要求すべきです。ctx_batch_execute/ctx_execute_fileを別 Issue に逃がすなら、#826 の Stop Conditions に「execution-like sibling tools の扱いが未定義なら quarantine 継続」と書くべきです。3. 既存 artifact に「実験用 profile / project scope / main 非影響」の矛盾がある
PR #856 は context-mode を project-scoped / team-shared / commit-tracked setting として導入した、と説明しています。 実際に
.claude/settings.jsonではenabledPlugins.context-mode@context-mode: trueが入っています。一方、
profile-isolation.jsonは「local scope のみ」「main branch の.claude/settings.jsonと hooks は変更なし」と記録しています。 これは current repo の状態と整合しません。#826 はこの artifact を前提にしてはいけません。修正: #826 の artifact schema に
effective_scopeを入れ、少なくとも次を明示してください。4. Claude Code runtime の証跡が弱い
#826 が扱う upstream #756 は Claude Code + worktree の
ctx_executecwd bug です。upstream #756 は open で、ctx_executeが worktree ではなく main repo / MCP server process cwd で動く観測が報告されています。([GitHub]2)ところが既存
ctx-doctor-result.jsonにはClaude Code: not installed — using standalone MCP modeとあります。 これは #824 の導入確認には一定の意味がありますが、#826 の Claude Code worktree cwd 検証の証跡にはなりません。#826 は
Claude Code session evidenceを必須化してください。例:5.
CLAUDE_PROJECT_DIRの意味を誤解しやすいClaude Code docs は、stdio MCP server に
CLAUDE_PROJECT_DIRを渡すが、これは「working directory に依存せず project-relative path を解決するための project root」だと説明しています。([Claude API Docs]3) したがって、CLAUDE_PROJECT_DIR == worktree cwdを無条件に期待値にすると誤判定になります。#826 の比較対象はこう分けるべきです。
env | rg '^CLAUDE_PROJECT_DIR='も避けた方がよいです。settings ではBash(env)/Bash(printenv)が deny されており、環境変数 dump は secret surface でもあります。 固定値だけを出すならprintf '%s\n' "${CLAUDE_PROJECT_DIR:-<unset>}"にしてください。6. artifact の検証が
test -fだけで弱い#826 の Verification Commands は artifact と doc の存在確認だけです。 これでは、cwd が一致したのか、不一致だったのか、
ctx_executeが deny されただけなのか、artifact が stale なのかを判定できません。Allowed Paths に以下を追加すべきです。
最低限の検証はこうです。
検証内容:
7. #825 完了を過信しない方がよい
#825 / PR #866 は closed ですが、current
deny-negative-test.jsonにはcontext_mode_version: null,head_sha: pending, direct_read coverage のnull, mutation detail のnull, FTS cleanup のnullが残っています。 さらにconftest.pyは artifact 生成失敗を握り潰します。これは #826 の直接ブロッカーではありませんが、親 #813 の「child 2 完了済みだから safety gate 済み」とは扱わない方がよいです。#826 の docs には「#825 artifact に未確定/null フィールドが残る限り、ctx_index/search routine-use 判断にも依存しない」と明記するのが安全です。
#826 に入れるべき修正案
Acceptance Criteria 差し替え案
Allowed Paths 修正案
Stop Conditions 追加案
実装時の推奨 probe command
envdump は使わず、固定 read-only だけにする。Git worktree は main worktree と linked worktree を分けて保持する仕組みなので、branch / HEAD / toplevel の比較は妥当です。([Git]4)
git rev-parse --show-toplevelは working tree の top-level directory を返すため、cwd drift 検出に適しています。(Git)最終方針
#826 は 「ctx_execute を許可できるか判断する Issue」ではなく、「許可しない理由を runtime evidence として固定する Issue」 に寄せるべきです。
現時点の推奨結論はこれです。
squne121 commentedon Jun 13, 2026
Refinement Loop: Human Escalation Required
The loop has terminated and requires human review. Cause: human judgment required
human_escalationhuman_judgment_requiredBlockers
squne121 commentedon Jun 13, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedfix(#826): replace placeholders with probe_blocked status; add stale …
fix(#826): add real Bash evidence for linked_worktree and nested_repo…
fix(#826): replace placeholders with probe_blocked status; add stale …
fix(#826): add real Bash evidence for linked_worktree and nested_repo…
docs: record context-mode cwd quarantine evidence for issue 826 (#880)