Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: parent
goal_ref: "context-mode MCP を Claude Code に段階的導入し、大出力を扱う read-only 調査補助として運用する"
change_kind: workflow
parent_mode: delivery-rollup
closure_mode: child-completeSummary
[調査完了 2026-06-12] context-mode(mksglu/context-mode v1.0.162)は Claude Code のコンテキスト汚染を減らす MCP ツールである。loop-protocol のような Issue/PR/作業ログ/テスト出力/repo-wide grep を大量に読む開発では ~98% のコンテキスト削減(vendor claim。loop-protocol の実ログでの before/after 計測を仮説 KPI とする)。ただしセキュリティ境界としては信頼できない。
採用判断:
- Claude Code: 「大出力を扱う read-only 調査補助」として条件付き採用候補
- Codex CLI: 現時点では本格導入しない
主なリスク:
- Path Traversal / XSS の既知脆弱性履歴(v1.0.0〜1.0.96 範囲、現 v1.0.162 では修正済み)
ctx_executeが worktree でなく MCP server の cwd で実行される bug(upstream feat-storage-add-snapshot-schema-migration-issue-736 #756)→pnpm testやgit statusが main checkout に対して走るリスクpermissions.denyが silent fail-open になる設計(deny-list 漏れで許可側に倒れる)- Elastic License 2.0(MIT ではない)
Goal
context-mode MCP を Claude Code に段階的に導入し、大出力(Issue/PR/コメント/作業ログ/rg 結果/test output)の read-only 圧縮・検索補助として安全に利用できる状態を確立する。build/test/git 操作は upstream #756 が未解消の間は通常 Bash に残す。
Outcome
Claude Code の実験用 profile で context-mode が動作確認済みとなり、read-only 用途(ctx_search / ctx_index)のみが許可され、deny rule が negative test で検証済みで、worktree cwd 安全性と fetch 隔離が artifact 化され、persistence / purge / license policy が docs 化されている。build/test/git 操作は upstream #756 解消まで通常 Bash に残す。
Desired Destination
- Claude Code の実験用 profile で context-mode が動作確認済み
- read-only 用途(ctx_search / ctx_index / ctx_fetch_and_index)のみ有効
- deny rule が
.claude/settings.jsonに反映済み(.env / ~/.ssh / ~/.config/gh / ~/.claude / gh auth token 等をブロック) - worktree cwd 安全性が検証済み(
pwd; git rev-parse --show-toplevelの Bash vs ctx_execute 比較) - 上記が確認されてから Codex CLI 別 profile への限定導入を検討する child issue を起票可能
Current Validated Scope
調査完了(2026-06-12)。実装変更対象:
.claude/settings.json(MCP server 設定追加).claude/hooks/**(routing hook 設定、該当時のみ)
Decisions Fixed
- 2026-06-12: context-mode v1.0.162 を Claude Code の実験用 profile に限定導入する(main profile は upstream worktree cwd bug 解消まで保留)
- 2026-06-12: Codex CLI は Claude Code 検証完了後に別 profile で限定導入する(本 parent close 条件外)
- 2026-06-12:
ctx_executeは child 3 の cwd 検証完了まで明示 deny。rg/git log/ test log 要約も例外扱いしない - 2026-06-12:
ctx_fetch_and_indexはCTX_FETCH_STRICT=1の negative test が通るまで明示 deny - 2026-06-12:
ctx_index/ctx_searchは許可候補だが、.env/~/.ssh/~/.config/gh/~/.claude/ repo secrets fixture が index されないことを negative test で検証する - 2026-06-12:
CTX_FETCH_STRICT=1は CI・共有環境を想定して必須前提とする - 2026-06-12: deny rule の最低限対象は
.env/~/.ssh/~/.config/gh/~/.claude/gh auth token/printenvとする
Quality Decision Record
Status: N/ADecision Date: 未記録Does this prove the parent goal complete?: N/AReason: delivery-rollup parent のため N/AEvidence: N/ANext Action: child 1(実験用 profile 導入・検証)を起票・実装する
Parent Closure Rule
delivery-rollup: child 1〜5 がすべて CLOSED かつCONTEXT_MODE_VERDICT: PASSコメントまたは evidence artifact パスが本 Issue に記録された時点でクローズする。child 6(Codex CLI)は optional 扱いとし、child 1〜5 完了で close 可とするquality-gate: N/Arouting-map: N/Adecision-log: N/A- 非
quality-gateparent のQuality Decision RecordはN/A扱いでよく、close 判定の必須材料にしない
Child Issues
- 実装: Claude Code 実験用 profile に context-mode を導入し version / provenance / doctor を検証する #824 — child 1: 実験用 profile で Claude Code に context-mode を導入し version / provenance / doctor を検証する
- 実装: context-mode deny rule を secret / token / config negative test 付きで fail-closed 化する #825 — child 2: context-mode deny rule を secret / token / config negative test 付きで fail-closed 化する
- 調査: context-mode ctx_execute の worktree cwd 安全性を検証し quarantine 方針を固定する #826 — child 3: context-mode
ctx_executeの worktree cwd 安全性を検証し quarantine 方針を固定する - 実装: context-mode ctx_fetch_and_index を CTX_FETCH_STRICT=1 と network negative test で隔離する #827 — child 4: context-mode
ctx_fetch_and_indexをCTX_FETCH_STRICT=1と network negative test で隔離する - 実装: context-mode の persistence / purge / ELv2 notice policy を docs 化する #828 — child 5: context-mode の persistence / purge / ELv2 notice policy を docs 化する
- (未起票 / optional) — child 6: Codex CLI 別 profile への context-mode 限定導入可否を hooks / MCP trust 前提で判定する(child 1〜5 完了後)
Remaining Parent Gaps
- upstream context-mode feat-storage-add-snapshot-schema-migration-issue-736 #756(ctx_execute worktree cwd bug)の解消確認後に build/test/git 権限解放を再判断する
- Codex CLI 導入の採否は child 1〜3 完了後に判断する
Phase Handoff Contract
Desired DestinationCurrent Validated ScopeRemaining Parent GapsCurrent ObjectiveBounded Current ContextNormative ReferencesAllowed PathsRequired SkillsValidation CommandsStop ConditionsOpen QuestionsNext ActionArtifact RefsHandoff Prompt DraftLinked PR(implementation のみ)
Acceptance Criteria
- AC1: Claude Code 実験用 profile で context-mode が起動確認済みであり、
ctx-doctorの実行結果が.claude/artifacts/context-mode/ctx-doctor-result.jsonに保存されている - AC2:
.claude/settings.jsonにctx_index/ctx_execute/ctx_searchの deny rule が記録されており、negative test の結果が artifact に保存されている - AC3:
ctx_executequarantine 方針がdocs/dev/agent-ops/context-mode-cwd-quarantine.mdに docs 化されている - AC4:
.claude/settings.jsonにCTX_FETCH_STRICT設定が記録されており、fetch negative test の結果が artifact に保存されている - AC5: context-mode の persistence / purge / ELv2 policy が
docs/dev/agent-ops/以下に docs 化されている - AC6:
CONTEXT_MODE_VERDICT: PASSを記録した artifact が.claude/artifacts/context-mode/verdict.jsonに存在する
Verification Commands
# AC1
$ test -f .claude/artifacts/context-mode/ctx-doctor-result.json
# AC2
$ rg -n "ctx_index|ctx_execute|ctx_search" .claude/settings.json
# AC3
$ test -f docs/dev/agent-ops/context-mode-cwd-quarantine.md
# AC4
$ rg -n "CTX_FETCH_STRICT" .claude/settings.json
# AC5
$ test -f docs/dev/agent-ops/context-mode-ops.md
# AC6
$ test -f .claude/artifacts/context-mode/verdict.jsonAllowed Paths
本 parent は tracker のため直接の実装変更を持たない。child issue の Allowed Paths は各 child 本文を正本とする。対象領域は以下:
.claude/settings.json.claude/hooks/**
Notes
関連 Issue:
- 導入: agent ops の token/context 浪費を決定論的 preflight / compact contract / hook 規律で削減する #791(agent ops token/context 浪費削減 parent)—
.claude/settings.json/.claude/hooks/**を共有。child 実装順は 実装: Claude / Codex hook の stdout policy と compaction 時 loop state 保存・復元 hint を fixture 検証付きで整備する #797(hook stdout 規律)と直列化して conflict を避ける - upstream context-mode: feat-storage-add-snapshot-schema-migration-issue-736 #756(ctx_execute cwd bug)/ 実装: ADR 0002 frontmatter を TEMPLATE schema に移行する #442 closed(ctx_index arbitrary read)/ 設計: scope rollup から security escalation を分離した専用 security-risk gate skill を検討する #558 closed(permission fail-open)
- Elastic License 2.0(source-available)。内部利用・fork・modify・distribute は可。hosted/managed service 化と notice removal は不可。loop-protocol 内部利用は問題なし
- 実装: Claude / Codex hook の stdout policy と compaction 時 loop state 保存・復元 hint を fixture 検証付きで整備する #797 は
.claude/settings.json/.claude/hooks/**の hook stdout policy を整備する Issue。導入: context-mode MCP を Claude Code に段階的導入する(read-only 調査補助) #813 child で context-mode plugin hooks / MCP routing を入れる場合は 実装: Claude / Codex hook の stdout policy と compaction 時 loop state 保存・復元 hint を fixture 検証付きで整備する #797 merge 後に rebase する(merge-order prerequisite)
Activity
squne121 commentedon Jun 12, 2026
Verdict: REQUEST_CHANGES
#813 の方向性は妥当です。Claude Code の main profile ではなく実験用 profile に限定し、Codex CLI は後回し、build/test/git 操作は Bash に残すという判断は正しいです。#813 にはコメントはまだありません。
ただし、現状の Issue 契約のまま child 実装に入るのは危険です。理由は、
read-onlyという言葉が強すぎること、ctx_executeの隔離が不十分なこと、deny rule の検証が弱いこと、そして.claude/settings.json/ hooks 領域が #791 / #797 と衝突しやすいことです。#813 自体も upstream の cwd bug、permission fail-open、Elastic License 2.0 をリスクとして認識していますが、Acceptance Criteria と child 分割がそのリスクを十分に吸収していません。関連 Issue / PR から見た位置づけ
#813 は #791 の token/context 削減 parent と同じ
.claude/settings.json/.claude/hooks/**領域を触ります。#791 は token/context 浪費を preflight・compact contract・hook stdout 規律で削減する parent であり、hook stdout / compaction 周辺まで含めています。特に #797 は
.claude/settings.json/.claude/hooks/**と.codex/hooks.json/.codex/hooks/**を対象に、Claude / Codex hook の stdout policy、compaction 時の loop state 保存・復元 hint を整備する Issue です。#813 が context-mode plugin hooks や MCP routing を入れるなら、#797 を blocker か merge-order prerequisite にすべきです。PR 側では #801 が #792 の preflight wrapper、#802 が #793 の VC scope preflight checker を実装済みで、#791 系は「自己申告ではなく fixture / machine-readable evidence で検証する」方向に進んでいます。#813 も
ctx_doctor実行だけでなく、deny / cwd / network / persistence の negative test を evidence artifact 化すべきです。Codex 側はさらに慎重に分けるべきです。#806 / #807 は Codex skill surface を
.agents/skills/に寄せ、.claude/skills/との二重管理・drift を抑える方向です。#813 の optional Codex child は、この surface policy と hook trust policy を前提にしないと、context-mode 導入が別経路の drift を作ります。Web 調査ベースの技術評価
context-mode 自体は、MCP tool の raw output を直接 main context に流す代わりに SQLite/FTS5 index を使い、検索・要約・圧縮して返す設計です。README は 315KB → 5.4KB、約 98% 削減という例を掲げていますが、これは vendor claim として扱い、loop-protocol の実作業ログで再計測すべきです。(GitHub)
Claude Code plugin としては
/plugin marketplace add context-mode@context-mode系で導入し、/context-mode:ctx-doctorで検証する流れです。plugin は MCP tools と hooks を登録し、sandbox tools としてctx_execute/ctx_index/ctx_search/ctx_fetch_and_indexなどを提供します。(GitHub)Claude Code 公式 docs は、MCP server を「信頼できる場合のみ」使うよう警告し、外部 content を取る MCP server は prompt injection risk を持つと明記しています。また stdio MCP server には
CLAUDE_PROJECT_DIRが渡されるため、cwd 検証は単なるpwdだけでなくcwd/CLAUDE_PROJECT_DIR/git rev-parse --show-toplevelの三点比較にすべきです。(Claude API Docs)context-mode upstream #756 はまだ危険です。報告では
ctx_executeが worktree ではなく main checkout で実行され、git statusや build/test 系が静かに別 tree を見ていました。#813 の「read-only コマンドならctx_executeを許す」は甘く、git log/rg/ test log 要約であっても cwd 誤認はレビュー判断を壊します。(GitHub)さらに、過去の upstream #442 は
ctx_indexが deny pattern を迂回してファイルを index し、ctx_searchで漏えいし得る問題でした。closed とはいえ、#813 の child 2 は.envを直接読むテストだけでなく、.envをctx_indexした後にctx_searchで引けないことまで検証すべきです。(GitHub)upstream #558 では
permissions.denyが silent fail-open になる問題が報告されています。これも closed ですが、#813 の deny rule は「設定を書いた」では足りず、printenv/gh auth token/.env/~/.ssh/~/.config/gh/~/.claudeに対する negative test が必須です。(GitHub)ctx_fetch_and_indexも read-only ではありますが安全ではありません。context-mode docs はCTX_FETCH_STRICT=1によって loopback / RFC1918 / ULA などの private network をブロックできると説明しています。#813 の「CI・共有環境では必須」では弱く、実験 profile の default でも有効にするべきです。(GitHub)Codex CLI については、公式 docs 上、MCP 設定は
~/.codex/config.tomlまたは信頼済み project の.codex/config.tomlで管理されます。hooks は複数 source から merge され、non-managed hooks は review / trust が必要です。さらに PreToolUse は不完全な enforcement boundary で、すべての shell call や WebSearch 等を捕捉するわけではありません。したがって #813 の Codex child は「導入」ではなく、まず「導入可否の research/design gate」にすべきです。(OpenAI Developer) (OpenAI Developer) (OpenAI Developer)Elastic License 2.0 の扱いも修正が必要です。context-mode README は、利用・fork・modify・distribute は可能だが、hosted / managed service として提供したり notices を削除することはできない、と説明しています。#813 の「再配布・SaaS 提供用途は使用不可」は雑なので、「内部利用は可。hosted/managed service 化と notice removal は不可。配布時は ELv2 notice 維持」と書く方が正確です。(GitHub)
Blockers
Severity | 指摘 | 修正方針 -- | -- | -- High | ctx_execute を read-only 用途で許す設計が危険。upstream #756 により cwd が silent にずれる。 | child 1〜3 完了までは ctx_execute を allow しない。cwd 検証 child は「許可判断」ではなく「quarantine 根拠作成」にする。 High | ctx_index / ctx_search を「read-only だから安全」と扱っている。過去に arbitrary read / index leak 系の脆弱性がある。 | deny negative test に ctx_index -> ctx_search 経路を含める。 High | deny rule が設定レビュー中心で、fail-open 回帰を検出できない。 | .env / SSH / gh / Claude config / printenv / gh auth token の実行・index・search negative test を fixture 化する。 High | #797 と .claude/settings.json / hooks が衝突する。 | #797 を blocker にするか、#813 child に「#797 merge 後 rebase」を Stop Condition として明記する。 Medium | v1.0.162 前提の provenance 検証がない。GitHub Releases では v1.0.162 が Latest と表示されているが、導入時に実際の installed package を確認する AC がない。(GitHub) | ctx --version 相当、plugin path、package version、release tag、doctor output を evidence artifact に残す。 Medium | CTX_FETCH_STRICT=1 が CI/shared 限定で、local 実験 profile の SSRF/localhost fetch リスクが残る。 | local 実験 profile でも default strict。有効化できない場合は ctx_fetch_and_index を child 1 では無効化。 Medium | SQLite/FTS5 の保存場所・purge・secret 混入時の処理が未定義。 | retention / purge child を追加する。 Medium | 親の close rule が child closed だけで、machine-readable evidence を要求しない。 | TEST_VERDICT_MACHINE 相当の CONTEXT_MODE_VERDICT コメントか artifact を親 close 条件に入れる。#813 親 Issue に入れるべき修正
ctx_executeは child 3 の検証完了まで 明示 deny。rg/git log/ test log 要約も例外扱いしない。ctx_fetch_and_indexはCTX_FETCH_STRICT=1の negative test が通るまで 明示 deny。ctx_index/ctx_searchは許可候補だが、.env/~/.ssh/~/.config/gh/~/.claude/ repo secrets fixture が index されないことを検証する。実装: Claude / Codex hook の stdout policy と compaction 時 loop state 保存・復元 hint を fixture 検証付きで整備する #797 を blocker または merge-order prerequisite にする。
parent closure rule を「child 1〜4 closed」ではなく、「child closed +
CONTEXT_MODE_VERDICTPASS + evidence artifact path 記録」に変更する。98% 削減は採用根拠ではなく仮説 KPI に落とす。loop-protocol の実ログで before/after を計測する。License note を ELv2 の正確な表現に修正する。
Child issue 草案
以下は、そのまま GitHub Issue body に貼れる粒度です。実際の起票はしていません。
Child 1 draft
Title
実装: Claude Code 実験用 profile に context-mode を導入し version / provenance / doctor を検証する
squne121 commentedon Jun 12, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 12, 2026
ClaudeCode作業ログ
squne121 commentedon Jun 14, 2026
child 1〜5(#824 / #825 / #826 / #827 / #828)が全て CLOSED。delivery-rollup クローズ条件(child-complete)を満たしたためクローズします。