Repository navigation
Closed
4 / 64 of 6 issues completedClosed
4 / 64 of 6 issues completed
Copy link
Labels
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: parent
goal_ref: "claude/AI 運用の usage コスト削減"
change_kind: workflow
parent_mode: delivery-rollup
closure_mode: child-completeSummary
/usage 統計(2026-05-23: Sonnet $14.62/91%、output 316.3k、issue-refinement-loop が skill 16% + SubAgent 12%)で判明した usage ホットスポットに対し、claude/AI 運用コスト削減施策 A〜D を child issue として bundle する。施策 E(PostToolBatch hooks guard)は判断保留としてスコープ外。
Goal
issue-refinement-loop 軽量化・deterministic reviewer Haiku 化・OUTPUT_BUDGET_V1 全 SubAgent 導入・巨大 SKILL.md 分割の 4 施策を実装し、claude/AI 運用コストを削減する。
Desired Destination
施策 A〜D(issue-refinement-loop max_iterations=1 デフォルト化、issue-reviewer Haiku 化 + pr-reviewer-lite 追加、全 SubAgent OUTPUT_BUDGET_V1 出力制約、SKILL.md thin entrypoint + references/ 分割)が .claude/ 配下に反映され、2026-05-23 時点の usage ホットスポット(skill 28% 相当)が削減されている。
Current Validated Scope
- A:
.claude/skills/issue-refinement-loop/SKILL.md—max_iterationsデフォルト 3→1、codebase-investigator/web-researcherを条件付き起動に変更 - B:
.claude/agents/issue-reviewer.md—model: sonnet→model: haiku、.claude/agents/pr-reviewer-lite.mdを新規追加(docs-only / small diff 向け) - C:
.claude/agents/*.mdおよび.claude/skills/*/SKILL.md—OUTPUT_BUDGET_V1制約を導入(human summary ≤ 30 行、全文再掲禁止、delta-only) - D:
.claude/skills/issue-refinement-loop/,issue-contract-review/,post-merge-cleanup/,impl-review-loop/— SKILL.md を thin entrypoint +references/構成に分割
Decisions Fixed
- 2026-05-23: 施策 A〜D を採用(人間 Decision コメント)
- 2026-05-23: 施策 E(
PostToolBatch/Subagenthooks usage guard)は意図が不明のため判断保留、スコープ外 - 2026-05-23: 4+ parallel sessions の削減は運用上やむなしとしてスコープ外
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 issue A〜D を順次起票・実装する(D は Issue 実装: gemini-cli-headless-delegation SKILL.md を thin routing entrypoint に再設計する #264 との重複確認後)
Parent Closure Rule
delivery-rollup: child issue A(軽量化)・B(Haiku 化)・C(output budget)・D(SKILL.md 分割、実装: gemini-cli-headless-delegation SKILL.md を thin routing entrypoint に再設計する #264 重複確認後)がすべて完了した時点でクローズするquality-gate: N/Arouting-map: N/Adecision-log: N/A
Child Issues
- perf(claude): issue-refinement-loop を軽量化する(max_iterations=1 デフォルト / SubAgent 条件付き) #295 — A:
issue-refinement-loop軽量化(max_iterations=1 デフォルト / SubAgent 条件付き起動) - perf(claude): deterministic reviewer SubAgent を Haiku / script-first 化する #294 — B: deterministic reviewer Haiku / script-first 化(
issue-reviewerhaiku 化 +pr-reviewer-lite追加) - perf(claude): 全 SubAgent に OUTPUT_BUDGET_V1 出力制約を導入する #296 — C: 全 SubAgent
OUTPUT_BUDGET_V1出力制約導入 - 実装: issue-refinement-loop SKILL.md を thin control-plane に縮小し loop state / routing 判断を schema・script に外出しする #795 — D(issue-refinement-loop 分): SKILL.md thin control-plane 化 + loop state / routing 判断の schema・script 外出し
- (未起票) — D(残り): issue-contract-review / post-merge-cleanup / impl-review-loop の SKILL.md thin 化(実装: issue-refinement-loop SKILL.md を thin control-plane に縮小し loop state / routing 判断を schema・script に外出しする #795 完了後に起票)
Remaining Parent Gaps
- Issue 実装: gemini-cli-headless-delegation SKILL.md を thin routing entrypoint に再設計する #264 と修正案 D の重複確認・統合判断 — 実装: gemini-cli-headless-delegation SKILL.md を thin routing entrypoint に再設計する #264 は CLOSED 済み(先行事例として参照)。D は 実装: issue-refinement-loop SKILL.md を thin control-plane に縮小し loop state / routing 判断を schema・script に外出しする #795 から段階起票する
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/skills/issue-refinement-loop/SKILL.mdのmax_iterationsデフォルトが 1 になっており、codebase-investigator/web-researcherの起動が条件付きになっている - AC2:
.claude/agents/issue-reviewer.mdのmodel:がhaikuになっており、C1〜C11 チェックが script-first で実行される - AC3:
.claude/agents/pr-reviewer-lite.mdが新規追加され、docs-only / small diff 向け Haiku reviewer として機能する - AC4:
.claude/agents/*.mdおよび.claude/skills/*/SKILL.mdにOUTPUT_BUDGET_V1制約が導入されている(human summary ≤ 30 行、全文再掲禁止) - AC5: 対象 4 スキル(
issue-refinement-loop/issue-contract-review/post-merge-cleanup/impl-review-loop)の SKILL.md が thin entrypoint +references/構成に再設計されている - AC6:
pnpm typecheck && pnpm lint && pnpm test && pnpm buildがすべて PASS する
Verification Commands
$ rg "max_iterations" .claude/skills/issue-refinement-loop/SKILL.md— AC1 確認$ grep "^model:" .claude/agents/issue-reviewer.md— AC2 確認(haiku が返ること)$ test -f .claude/agents/pr-reviewer-lite.md && echo PASS || echo FAIL— AC3$ rg -l "OUTPUT_BUDGET_V1" .claude/agents/ .claude/skills/ | wc -l— AC4(1件以上)$ for s in issue-refinement-loop issue-contract-review post-merge-cleanup impl-review-loop; do test -d ".claude/skills/$s/references" && echo "PASS: $s" || echo "FAIL: $s"; done— AC5$ pnpm typecheck && pnpm lint && pnpm test && pnpm build— AC6
Notes
- ChatGPT 分析: perf(claude): AI 運用コスト削減施策 — refinement-loop 軽量化 / Haiku 化 / output budget / SKILL.md 分割 #293 (comment)
- 人間 Decision: perf(claude): AI 運用コスト削減施策 — refinement-loop 軽量化 / Haiku 化 / output budget / SKILL.md 分割 #293 (comment)
- dedupe_key:
perf-claude-usage-optimization-ABCD-2026-05-23 - Issue D は既存 Issue 実装: gemini-cli-headless-delegation SKILL.md を thin routing entrypoint に再設計する #264(OPEN)との重複確認が必要
Sub-issues
Collapse Sub-issuesSub-issues
Loading 6 sub-issues
Activity
squne121 commentedon May 23, 2026
you asked
message time: 2026-05-23 16:51:56
https://github.com/squne121/loop-protocol/ のusage 問題点、改善点がないか検討して。
❯ /usage
────────────────────────────────────────────────────────────────────────────────────────────
Settings Status Config Usage Stats
Session
Total cost: $16.04
Total duration (API): 1h 51m 29s
Total duration (wall): 3h 7m 16s
Total code changes: 787 lines added, 15 lines removed
Usage by model:
claude-haiku-4-5: 306.9k input, 57.1k output, 3.5m cache read, 292.2k cache write,
11 web search ($1.42)
claude-sonnet-4-6: 2.9k input, 316.3k output, 18.0m cache read, 1.2m cache write
($14.62)
Current session
██████████████████████████████████████████████████ 100% used
Resets 6:50pm (Asia/Tokyo)
Current week (all models)
████████████████████████ 48% used
Resets May 28, 1:59am (Asia/Tokyo)
Current week (Sonnet only)
████████████████████████████████▌ 65% used
Resets May 28, 2am (Asia/Tokyo)
What's contributing to your limits usage?
Approximate, based on local sessions on this machine — does not include other devices or
claude.ai
Last 24h · these are independent characteristics of your usage, not a breakdown
100% of your usage came from subagent-heavy sessions
Each subagent runs its own requests. Be deliberate about spawning them — and
consider configuring a cheaper model for simpler subagents.
27% of your usage was while 4+ sessions ran in parallel
All sessions share one limit. If you don't need them all at once, queueing uses
it more evenly.
12% of your usage came from subagents under "issue-refinement-loop"
If this runs frequently, consider configuring its subagents with a cheaper
model or tightening their prompts.
16% of your usage came from /issue-refinement-loop
Heavy skills can be scoped down or run with a cheaper model via skill
frontmatter.
Skills % of usage
/issue-refinement-loop 16%
/issue-contract-review 8%
/create-issue 6%
/review-issue 5%
/post-merge-cleanup 4%
/impl-review-loop 2%
/gemini-cli-headless-delega… 1%
Subagents % of usage
issue-refinement-loop 12%
issue-contract-review 10%
post-merge-cleanup 6%
pr-reviewer 6%
implementation-worker 5%
issue-author 3%
impl-review-loop 3%
review-issue 2%
… 1 more
d to day · w to week
Usage credits
████████████▋ 25% used
$20.22 / $80.00 spent · Resets Jun 1 (Asia/Tokyo)
Esc to cancel
chatgpt response
提示された
/usageだけでも、主因はかなり明確です。リポジトリ側のスキル/サブエージェント設計と、実際の利用統計を突き合わせて、削るべき順番まで落とします。ルールがリポジトリ内にかなり厚く置かれています。ここからは、どの定義が
/usageの「subagent-heavy」「4+ sessions」「Sonnet output過多」に直結しているかを見ます。ol` の AI 運用が Issue/PR 管理・レビュー・refinement の control-plane に寄りすぎて、Sonnet SubAgent が大量の説明文/YAML/レビュー結果を吐いている状態です。
最優先で直すべきは次の3点です。
/issue-refinement-loopを既定運用から外し、軽量版・1 iteration 既定にする今回の $16.04 のうち Sonnet が $14.62、約91% を占めています。Web search は $1.42 なので主因ではありません。さらに Sonnet は input 2.9k に対して output 316.3k と極端に出力過多です。ここが削減対象です。
usage 上の主要な問題
1.
issue-refinement-loopがホットスポット化している/usage上、/issue-refinement-loopが skill で 16%、その配下 SubAgent が 12% を占めています。厳密には独立特性なので単純加算はできませんが、同じ症状として見ると最大のホットスポットです。リポジトリ上の
issue-refinement-loopは、各 iteration でcodebase-investigator、review-issue、必要ならissue-author、外部仕様があればweb-researcherを使う設計です。さらにmax_iterations既定が 3 です。つまり、Issue本文を少し直すだけでも「調査 → レビュー → 編集 → 再レビュー」の多段 SubAgent ループになりやすい構造です。Claude Code 公式ドキュメント上も、SubAgent は隔離された文脈を持つため便利ですが、詳細な結果を返す SubAgent を多数使うと大きな context / token 消費になります。短い確認や頻繁なやり取りはメイン conversation や skill の方が向く、と説明されています。(Claude API Docs)
改善方針:
issue-refinement-loopは「Issueが曖昧」「人間コメントで前提が覆った」「外部仕様 claim がある」「contract-review が blocked にした」場合だけ使う。通常の docs-only / small issue 修正では使わない。2. Sonnet を使うべきでない判定系が Sonnet 固定になっている
issue-reviewerは read-only の loop worker ですがmodel: sonnetです。やっていることは Issue 本文取得、C1〜C11 の決定論的チェック、REVIEW_ISSUE_RESULT_V1返却です。pr-reviewerもmodel: sonnetで、PR diff / checks / Issue を読んでAPPROVE/REQUEST_CHANGESを返します。コード・セキュリティ・設計境界レビューなら Sonnet は妥当ですが、docs-only / small config PR まで Sonnet 固定だと高くなります。Claude Code 公式では、SubAgent の model は frontmatter や環境変数、呼び出し時指定で切り替え可能です。低コスト SubAgent には Haiku を割り当てる運用が想定されています。(Claude API Docs)
改善方針:
issue-reviewer: 原則 Haiku 化。C1〜C11 は script-first に寄せる。pr-reviewer:pr-reviewer-liteを追加し、docs-only / small diff は Haiku。implementation-workerと重要なissue-authorは Sonnet 維持でよい。3. Skill / SubAgent 定義が厚く、起動ごとの読込コストが増えている
リポジトリには
.claude/agents、.claude/skills、.claude/rules、.claude/settings.jsonがあり、AI運用定義がかなり厚いです。(GitHub)CLAUDE.mdは最初に読む順序として、Issue、CLAUDE.md、project constitution、requirements、current-focus、関連ADR/feature/directory docs を要求しています。project-constitution.mdも、docs-only 変更でも可能ならpnpm typecheck/lint/test/buildと Python test を通す方針です。公式ドキュメントでは、通常の SubAgent は新しい隔離 context で起動し、
CLAUDE.md、memory、git status、preloaded skill content を読むとされています。Explore / Plan だけは例外的に一部をスキップします。(Claude API Docs)また、skill はロード後、その内容が context に残り、各行が以後の token cost になるため、本文は簡潔にするべきです。(Claude API Docs)
改善方針:
長大な
SKILL.mdは「短い実行手順」だけにし、巨大な schema / examples / runbook はreferences/に逃がす。必要 branch のときだけ読む構造にする。4. Sonnet output が過剰
今回の Sonnet は 2.9k input / 316.3k output です。これは「考えるために読んでいる」より、「報告・YAML・本文案・レビュー文を大量生成している」コストです。
issue-refinement-loop、issue-contract-review、post-merge-cleanup、impl-review-loopはどれも構造化 YAML や詳細 report を返す設計です。特にissue-refinement-loopは巨大なLOOP_STATEを持ちます。post-merge-cleanupもPOST_MERGE_CLEANUP_REPORT_V1、follow-up materialization result などの長い出力契約を持ちます。改善方針:
全 SubAgent に次の出力制限を入れる。
これだけで Sonnet output は大きく下がるはずです。
5. follow-up Issue 自動起票が “Issue factory” になっている
post-merge-cleanupは SubAgent が follow-up 候補を返し、main thread が即時issue-authorに委譲してcreate-issueする設計です。agent-skill-boundaries.mdでも、観察・提案を Issue として materialize する方針が定義されています。これは追跡性の面では良いですが、運用が強すぎると「PRレビュー → follow-up Issue → refinement → contract-review → また follow-up」という増殖ループになります。改善方針:
mandatory_follow_upだけ即時 Issue 化optional_follow_upは既定でnote_onlypost-merge-cleanupからissue-authorへの自動委譲は人間承認後に限定6. 4+ parallel sessions が limit を食っている
/usageでは、直近24hの 27% が 4+ sessions 並列です。Claude Code の limit は共有なので、複数の heavy SubAgent session を並列に走らせると、リセット前に詰まりやすいです。改善方針:
/issue-refinement-loopと/impl-review-loopは同時に複数走らせない具体的な修正案
Issue A:
perf(claude): issue-refinement-loop-lite を追加する目的: 通常の Issue 改善を軽くする。
変更案:
max_iterations既定を 1 にするcodebase-investigatorはrequires_fact_checkまたはtarget_paths明示時だけweb-researcherは外部仕様 claim が Outcome / AC / VC に影響する場合だけverdict / blockers / minimal_patch / next_actionのみ対象:
.claude/skills/issue-refinement-loop/SKILL.md.claude/agents/issue-reviewer.mddocs/dev/agent-skill-boundaries.mdIssue B:
perf(claude): deterministic reviewers を Haiku / script-first にする目的: Sonnet 固定を減らす。
変更案:
issue-reviewer.md:model: haikupr-reviewer-lite.mdを追加pr-reviewerSonnet対象:
.claude/agents/issue-reviewer.md.claude/agents/pr-reviewer.md.claude/agents/pr-reviewer-lite.md新規.claude/skills/pr-review-judge/SKILL.mdIssue C:
perf(claude): SubAgent output budget を全 agent に導入する目的: Sonnet output 316k 問題を直接削る。
共通ルール:
対象:
.claude/agents/*.md.claude/skills/*/SKILL.mddocs/dev/agent-skill-boundaries.mdIssue D:
perf(claude): bulky SKILL.md を references へ分割する目的: skill ロード後の recurring token cost を下げる。
候補:
issue-refinement-loop/SKILL.mdissue-contract-review/SKILL.mdpost-merge-cleanup/SKILL.mdimpl-review-loop/SKILL.md方針:
SKILL.md: 入口、入力、最小手順、停止条件だけreferences/*.md: schema、長い例、runbook、taxonomyIssue E:
ops(claude): PostToolBatch / Subagent hooks で usage guard を入れるClaude Code には
PostToolBatchhook があり、tool batch 後に context を追加したり、decision: block/continue: falseで agentic loop を止められます。(Claude API Docs)また、
SubagentStart/SubagentStophook もあります。(Claude API Docs)入れるべき guard:
運用上の即効策
次回からは、以下のルールにすると消費はかなり下がります。
評価
現状の設計は、安全性・追跡性・再現性にかなり寄っています。これは悪くありません。ただし、個人趣味開発のゲーム制作として見ると、AI運用基盤がゲーム本体より重くなり始めているのが問題です。GitHub上でも、このリポジトリは TypeScript/Vite/Canvas のゲームである一方、言語比率は Python 89.8%、Shell 6.6%、TypeScript 2.9% になっています。(GitHub)
したがって、今やるべき改善は「もっと厳密な運用」ではなく、厳密さを維持したまま、重い経路を人間承認付きの例外パスへ落とすことです。特に
issue-refinement-loopと Sonnet reviewer の軽量化が最優先です。squne121 commentedon May 23, 2026
人間からの指摘です。
最近は Issueの疑問点や要望があったらIssueコメント→Issueコメントと本文のレビューをChatGPTに依頼→回答を元にClaudeCodeへ issue-refinement-loop を行っているので、重たいレビューはいらないかも。でも形は整えてほしい。
GithubをAIとのインターフェースにしている以上、標準出力は最小限で良い。Issue、PR、コメントなどのURLを教えてくれるだけでよさそう。
「follow-up Issue 自動起票」についてはIssue解決より増加数が多い、人間の認知負荷増で迷う、Issue探索コンテクストの増加などの問題がありそうだから減らしたいし、取り扱いは改善したい。
でも、クローズされたIssueやPRを人間が確認することはないので、改善点が起票されないのは困るかも。AIが必ずやった方がいいこととやらなくてもいいことを区別できるか?mandatory_follow_up、 optional_follow_upってどういう意味?たとえば、もし必ずやらなくてもいいIssueを判断できるなら、改善点リストissueみたいなものを起票して、そのissue本文にひたすら改善点を追記するのはどうだろうか。人間はその中から改善点を見てAIに起票を頼むし、AIはリストを探索して既存改善点との重複などを確認する?今とあまり変わらないかも。
「4+ parallel sessions が limit を食っている」これはしょうがない。そもそも4セッション並列で作業していて、それぞれが issue-refinement-loop 、impl-review-loop でサブエージェントを起動している。作業形態はしょうがないと思う。
「Issue E: ops(claude): PostToolBatch / Subagent hooks で usage guard を入れる」は何を意図するのかよくわからないから判断保留。
具体的な修正案は判断保留以外採用。
以下を参照して。
#293 (comment)
[-]Usage改善提案[/-][+]perf(claude): AI 運用コスト削減施策 — refinement-loop 軽量化 / Haiku 化 / output budget / SKILL.md 分割[/+]squne121 commentedon May 23, 2026
Issue 本文全面書き換え
変更種別: edit-issue(全面書き換え)
実施日: 2026-05-23
変更理由
review-issue が以下の blocking_issues を指摘したため、修正案 A/B/C/D と人間 Decision を元に整形:
参照した Decision
追加内容の概要
not_applicable(.claude/ 配下のみ)を明記issue_type: delivery_rollup/closure_mode: child-complete/ child_issues A〜D を追加タイトル変更
Usage改善提案perf(claude): AI 運用コスト削減施策 — refinement-loop 軽量化 / Haiku 化 / output budget / SKILL.md 分割squne121 commentedon May 23, 2026
Issue 本文書き換え経緯
issue-reviewer からの blocking_issues(C1/C4/C7/C8)に基づき、本文を parent.yml テンプレート形式に全面書き換えしました。
対応した blocking_issues
$プレフィックス付き形式に統一し、機械判定基準を満たす形に修正したrequired_skillsをワークフロー skill 記載なしのフォーマットに変更(contract_schema_version/issue_kind/goal_ref/change_kind/parent_mode/closure_mode のみ)追加ラベル
trackingstate/in-progresssqune121 commentedon May 23, 2026
issue-refinement-loop: 完了 (2026-05-23T10:15:53Z)
squne121 commentedon May 23, 2026
child issue 起票完了 (2026-05-23T10:19:39Z)
squne121 commentedon May 24, 2026
人間からの指摘です。
「D: 巨大 SKILL.md thin entrypoint + references/ 分割」について検討してほしい。
squne121 commentedon Jun 11, 2026
施策 A〜D の全 child issue がクローズ済みのため、delivery-rollup 契約(closure_mode: child-complete)に従いクローズします。\n\n- #295 (施策 A: refinement-loop 軽量化): CLOSED\n- #294 (施策 B: Haiku 化): CLOSED \n- #296 (施策 C: OUTPUT_BUDGET_V1): CLOSED\n- #795 (施策 D: SKILL.md thin 化): CLOSED — PR #804 マージ済み