並列でエージェントを走らせると、実装は速い。そのあとが重い。同じエラーレスポンスがコピペ、ヘルパーがファイルごとに増える。機能は動くのに、PR に出せる形にする作業が残る。
前回の棚卸し では、ループをターン型・ゴール型に分け、品質の鍵はメイカーとチェッカーを分けることだと書いた。今回はその内側に、実際に挟んでいるコマンドを置く。実装が終わったら /simplify で一周を閉じ、横断する移行だけ /batch に渡す。
3記事と公式の差分
読んだのは次の3本だ。PR 前の仕上げ、大規模マイグレーション、lodash をネイティブ JS に置き換えた検証。
記事は v2.1.63 時点の話が多い。公式の Commands をあとから見ると、いまはこうなっている。
/simplifyは変更差分を並列レビューして直す。観点は再利用、単純化、効率、抽象度の4つ。記事側は3エージェントと書いてあることが多い- v2.1.154 以降、
/simplifyはバグを探さない。正しさは/code-review /batchは調査、5〜30の独立ユニットへの分解、承認、git worktree ごとの並列実行、ユニットごとの PR/debugは Claude Code 自身のセッション診断。Cursor の Debug モードとは別物
検証記事では、/simplify が配列マージの実バグを拾っていた。今の公式では、その役は /code-review に移っている。運用では役割を分けた方が事故が少ない。
役割の切り方
/simplify はコードレビュワー、/batch はマイグレーションチーム、という対比が一番わかりやすい。
| 項目 | /simplify |
/batch |
|---|---|---|
| 対象 | 直近の変更 | コードベース全体の該当箇所 |
| 用途 | PR 前の冗長削減 | 大規模な一括変更 |
| 出力 | 今のブランチへの修正 | ユニットごとの孤立作業(PR は任意) |
| 頻度 | 実装のたびに | マイグレーションのとき |
| 関係 | 単体で使う | 各ワーカーの末尾で simplify する |
得意なのは、独立して実行できる変更がたくさんあるときだ。ライブラリ置換、型の一括追加、命名の統一、非推奨 API の置き換え。苦手なのは、ファイル A の結果に B が依存する密結合、まだ形が決まっていない探索、1ファイルの小さな修正。
共通ヘルパーが先に必要なときは、バッチの前に通常セッションで入れる。ここを飛ばすと、全ユニットが同じユーティリティを別々に作り始める。
Cursor には同梱が無い
自分のグローバルコマンドは、もともと /ui-skills と /fixing-accessibility だけだった。Claude Code 側は bundled skill なのでインストール不要。Cursor 側は自前で足す。
置いた場所は ~/.cursor/commands/ で、全プロジェクトから /simplify と /batch で呼ぶ。スキル(自動起動)にはしていない。品質ゲートは明示したときだけ走らせたい。
対応はこう切った。
| 役割 | Claude Code | Cursor |
|---|---|---|
| PR 前の冗長削減 | /simplify |
/simplify(今回追加) |
| 大規模を独立ユニットで並列 | /batch |
/batch(今回追加) |
| バグ・正しさ | /code-review |
Bugbot / Security Review |
| セッション不調 | /debug |
Debug モード |
| CI が落ちたら直し続ける | /autofix-pr |
/loop と Cloud Agent |
Cursor の /simplify は、4つのサブエージェントを並列でレビューに使い、適用は親が直列で行う。同じ checkout に4人が同時に書き込むと、きれいにするはずが衝突する。
Cursor の /batch は、計画を出して承認を待つ。ワーカーはデフォルトで best-of-n-runner(git worktree を分ける)。Cloud Agent は、クラウド実行を頼まれたときだけ。今の worktree で generalPurpose を並列起動するのは禁止にした。Grok の並列マルチタスクで MT プラグインを一気に進めた記録 で、同じ木に複数エージェントを入れるとファイルがぶつかる、と書いた話そのものだ。
PR 作成は自動にしない。Claude Code の /batch はユニットごとに PR まで開く。Cursor 側は既存ルールどおり、push も PR も確認後にする。
中身はスキル(自動起動)ではなく、スラッシュで明示するコマンドにした。置き場は ~/.cursor/commands/simplify.md と ~/.cursor/commands/batch.md。以後ここを正本にする。
simplify.md
---
name: simplify
description: Review recently changed code for reuse, simplification, efficiency, and abstraction, then apply behavior-preserving cleanups. Use after implementing a feature and before opening a PR. Do not hunt bugs.
---
# /simplify
PR に出す前の仕上げ。直近の変更だけを対象に、機能は変えず「どう書くか」を直す。
Claude Code の `/simplify`(v2.1.63 以降。v2.1.154 以降はバグ探しをしない)に相当する。
## How to use
- `/simplify`
直近の git diff を 4 観点で並列レビューし、妥当な修正を適用する。
- `/simplify <path>`
指定パス配下の変更だけを対象にする。
- `/simplify <extra focus>`
4 観点に加えて、引数の観点も見る(例: `/simplify セキュリティ観点も見て`)。バグ探しには使わない。
## Hard rules
- NEVER change behavior: return values, edge cases, side effects, public APIs, serialized field names, and observable output stay the same.
- NEVER hunt correctness bugs. If a likely bug appears, record it and tell the user to run `/review-bugbot` (or Claude Code `/code-review`). Do not silently "fix" it as cleanup.
- NEVER commit, push, or open a PR unless the user explicitly asked.
- NEVER rewrite unrelated files. Stay inside the scoped diff.
- If tests exist, a cleanup that fails them is invalid. Revert that hunk.
- Skip false positives. Prefer doing nothing over a clever rewrite.
## Scope
1. Run `git status` and `git diff` (staged + unstaged). Include untracked files only if they are part of the current work.
2. Choose the target in this order:
- Dirty working tree → that diff.
- Clean tree and a path argument → that path vs the default branch (or `HEAD~1` if the path is only in the last commit).
- Clean tree, no path → `HEAD` vs `HEAD~1` when the last commit looks like the implementation being polished; otherwise diff vs the default branch.
3. If there is no meaningful diff, say so and stop.
4. If the repo is not git, review files changed in this conversation only.
## Procedure
1. Summarize the scoped files in one short list.
2. Launch **four** `Task` subagents in **one** message, in parallel. They are reviewers, not editors.
- `subagent_type`: `explore` or `generalPurpose`. Prefer `explore` when the diff is small and read-only review is enough; use `generalPurpose` only if they must read many files.
- `run_in_background`: false (the parent needs the findings before applying).
- Each agent gets the same file list plus **one** lens below.
- Extra focus from the user argument is appended to every agent, or given to the closest lens.
3. Wait for all four. Deduplicate findings. Drop anything that would change behavior, touch files outside scope, or looks like a bugfix.
4. Apply remaining fixes **in the parent**, sequentially, to avoid overlapping edits.
5. Re-run the project's cheap checks when they exist (`test`, `typecheck`, `lint`/`format` as the repo already uses them). Do not introduce new toolchains.
6. Show `git diff` of the cleanup. List what changed, what was skipped and why, and any bug suspects for Bugbot.
7. Ask before committing. Preferred message shape: `refactor: /simplify で品質改善`.
## Four review agents
| Agent | Looks for | Typical fix |
| -------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| Reuse | Duplicated logic, copy-pasted helpers, repeated lookups | Extract or call an existing helper. Do not invent a new abstraction unless the duplication is real and local. |
| Simplification | Nested ternaries, dead branches, noisy names, over-wrapping | Flatten control flow. Delete unused code. Keep names that the codebase already uses. |
| Efficiency | Redundant loops, repeated I/O or queries, work done then thrown away | Hoist invariant work. Filter before mapping. Use a stdlib equivalent when it is already the project style. |
| Abstraction | Wrong layer (too many wrappers, or a god function) | Match the surrounding module's level. Do not introduce a framework. |
Each agent must return:
- file path and a short finding
- why it is cleanup, not a behavior change
- a concrete patch suggestion (or "skip")
## When not to run
- The user asked for a bug hunt, security review, or large migration → `/review-bugbot`, `/review-security`, or `/batch`.
- No diff yet (still designing) → stay in Plan mode.
- One-line typo or comment-only change → just edit it; do not fan out four agents.
batch.md
---
name: batch
description: Orchestrate large-scale independent code changes in parallel isolated worktrees. Research, split into 5-30 units, wait for approval, then implement, test, and simplify per unit. Use for migrations and bulk refactors, not one-file edits.
---
# /batch
コードベース全体に同じ方針の変更を大量適用する。調査して独立ユニットに分け、承認後に孤立した worktree で並列実行する。
Claude Code の `/batch`(v2.1.63 以降)に相当する。各ユニットの末尾で `/simplify` 相当を必ず走らせる。
## How to use
- `/batch <change>`
変更方針は必須。例:
- `/batch lodash を全部ネイティブ JS に置き換えて`
- `/batch 非推奨 API を現行相当に更新して`
- `/batch 未型付けの関数パラメータに型を足して`
引数が無いときは、何を一括変更したいかを聞いて止める。推測で走らせない。
## Hard rules
- NEVER start workers before the user approves the unit plan.
- NEVER put two units on files that would conflict. Same file → same unit.
- NEVER run multiple editors in the **current** worktree in parallel. Isolation is mandatory.
- NEVER use `environment: cloud` unless the user explicitly asked for a cloud agent.
- NEVER commit, push, force-push, or open a PR unless the user explicitly asked. Propose PR titles and a split; wait.
- NEVER use `/batch` for exploratory design, a single-file change, or a tightly coupled architecture rewrite.
- If a shared helper must exist first, do that in **this** session before fanning out, or refuse and say so.
## When to refuse
Stop after a short explanation and suggest a normal session (or `/simplify`) when:
- only one file (or a handful of lines) is involved
- the target shape is not decided yet
- unit B needs unit A's result (real dependency, not a fake edge)
- the user actually wants a bug hunt (`/review-bugbot`) or a cleanup of the current diff (`/simplify`)
## Phase 1: Research
1. Confirm this is a git repository. If not, stop. `/batch` needs branches and worktrees.
2. Launch an `explore` Task (`subagent_type: explore`, thoroughness `very thorough` when the tree is large) to find:
- matching files and call sites
- shared modules that all units would touch
- existing tests / how to verify
3. Identify shared work that must land **before** the fan-out (new helper, type, compatibility shim). Do that first, or fold it into unit 0 as a sequential prerequisite.
## Phase 2: Plan (approval gate)
Decompose into **5〜30** independent units. Fewer than 5 is fine if the blast radius is small; do not invent dummy units. More than 30 → merge related folders.
Each unit lists:
- id and one-line goal
- files it owns (exclusive)
- replacements or pattern (a small mapping table when it is a mechanical migrate)
- how to test that unit
- dependencies (must be none, or only "after unit 0 / shared helper")
Show a mermaid or bullet graph of units. Call out collision risks (lockfiles, generated code, protocol registries, README catalogs).
Then **stop and wait**. Do not spawn workers. Ask the user to approve, edit the split, or abort.
## Phase 3: Parallel execution (after approval)
Spawn **one isolated worker per unit** in a single message.
Isolation, in order:
1. Local default: `subagent_type: best-of-n-runner` (own git worktree and branch).
2. Cloud: `environment: cloud` only if the user asked for cloud.
3. Never: multiple `generalPurpose` agents writing the same checkout.
Each worker prompt must include:
- the unit's files and the global mapping / policy
- implement only that unit
- run the unit's tests (or the repo's cheapest equivalent)
- run `/simplify` rules on **that unit's diff** (four lenses: reuse, simplification, efficiency, abstraction; behavior-preserving; no bug hunting)
- do not commit unless the parent said the user asked for commits
- report: files changed, test result, simplify summary, leftover risks
Parent tracks workers. Do not redo a finished worker's research. If one fails, retry that unit once with the error; do not take over its files in the current tree while siblings still run.
## Phase 4: Report
Aggregate:
- landed units vs failed units
- worktree / branch names
- test outcomes
- simplify cleanups applied
- suggested PR split (one PR per independent unit; stack only when the dependency is real)
Ask what to do next: commit, push, open PRs, or leave the worktrees.
If the user asks to open PRs, follow the project's PR rules (`gh pr create`, no force-push, no hooks skipped). Prefer the split-to-prs skill when leftover work is still one pile on the current branch.
## Relationship to /simplify
`/simplify` is the inner quality gate (recent diff, four reviewers).
`/batch` is the outer migration orchestrator. Every worker ends with simplify.
Bugs stay outside both: `/review-bugbot` / `/review-security`.
ループのどこに置くか
前回の棚卸しでは、ループをターン型・ゴール型・時間型・プロアクティブ型に分けた。普段 Cursor に「あれやって」と打つのはターン型。/simplify と /batch は、そのターンの内側に検証ゲートを足す部品だ。
着手前の4条件もそのまま使える。週1回以上の繰り返し、自動検証、トークン予算、実行環境。/batch は並列エージェントが走るので、予算と検証が弱いと静かな失敗になりやすい。
メイカーとチェッカーを分ける、という話にも乗る。実装したエージェントに /simplify をやらせるのではなく、4観点のレビューは別コンテキストのサブエージェントに渡す。親は集約と適用に徹する。自己採点にしない。
「ある」のときは A / B / C が別 worktree で同じループを回す。図ではテスト以降を1本に畳んでいる。内側のゲートは /simplify、正しさは Bugbot、外側は CI。実装した側に自己採点させない。
実際の一周
前回の分類でいうと、普段の「あれやって」はターン型のままである。変えるのは、実装のあとにチェッカーを必ず挟むことだ。/simplify がその部品になる。ゴール型にするのは CI が落ちたら直す外側だけ、という切り方にしている。
実装コミットを先に切る。/simplify の差分を refactor: で分けないと、機能と掃除が同じコミットに混ざる。レビューも、あとから戻すのもやりにくい。
Cursor で機能を1本出す
Scraps の管理画面に画像リサイズを足す、くらいのサイズを想定する。打つものはこれだけだ。
画像アップロード後に長辺 1600px へリサイズしてから R2 に置け
動いたらテストを回し、実装だけ先にコミットする。
git add workers/scrap-api/src/index.ts src/components/ScrapImageUpload.tsx
git commit -m "feat: scraps の画像をアップロード時にリサイズする"
そのあと /simplify とだけ打つ。Cursor 側のコマンドは、直近の git diff を4つのサブエージェントに渡す。再利用、単純化、効率、抽象度。エージェントはレビューだけで、適用は親が直列でやる。同じファイルに4人が同時に書き込まない。
返ってくるのはだいたい、こういう指摘だ。
- リサイズの数値と MIME 判定がコンポーネントと Worker で重複している。Worker 側のヘルパーに寄せる
new Date().toISOString()の切り出しが他ファイルにもある。既存のtodayDateがあればそれを使う- ループ内で毎回バケットを引いている。ループの外へ出す
機能は変えない。テストが落ちる変更は捨てる。バグっぽいものが出ても、ここでは直さない。Bugbot に回す。
git diff
git commit -m "refactor: /simplify で品質改善"
正しさは別ゲートにする。
/review-bugbot
通ったら PR。CI を見ておきたいときだけ /loop で監視する。落ちたら「失敗から直す」に戻って、またテストから一周する。/simplify は実装の直後だけではない。CI 修正で diff が汚れたら、もう一度挟んでよい。
観点を足すときは引数を付ける。バグ探しには使わない。
/simplify エラーメッセージの重複も見て
Claude Code でも中身は同じ
打つコマンドの名前が違うだけだ。実装コミットのあと /simplify、目視、refactor: コミット、/code-review --fix、PR。外側をゴール型にするなら /autofix-pr で CI とレビューコメントを監視させる。
横断するときだけ /batch
/simplify は今のブランチの直近差分だけを見る。lodash を全部外す、非推奨 API を置き換える、型を50ファイルに足す、は対象外だ。そっちは /batch に1行渡す。
/batch lodash を全部ネイティブ JS に置き換えて
返ってくるのは対照表と、5〜30の独立ユニットだ。ここで計画を読む。同じファイルを2ユニットが持っていたら分割を直す。承認するまでワーカーは起動しない。
承認後、各 worktree が実装、テスト、末尾の /simplify までやる。リモートが無い小さなリポジトリでは並列にならず、順番に進む。検証記事の lodash 置換がそれだった。
Cursor では Plan モードで影響範囲を切ってから /batch する。Cloud Agent は、クラウド実行を頼んだときだけ。今の worktree で複数エージェントを走らせない。1山の差分が残ったら split-to-prs に渡す。PR は確認後に出す。
並列開発では /batch 相当が必須に近い。調査、分割、worktree 分離を人手でやると、衝突と冗長実装が戻る。/simplify は毎日の品質ゲートで、バッチの出力をマージ可能なサイズに保つ。1ファイルや探索的リファクタでは、どちらも使わない。
使うときの実務
トークンは並列で増える。大きなコードベースにいきなり投げず、フォルダ1つで試す。
Claude Code を使うリポジトリでは .claude/worktrees/ を gitignore する。Cursor の worktree は ~/.cursor/worktrees/ 側なので、リポジトリには入らない。
CLAUDE.md に日本語で返す、と書いておかないと計画書が英語になる。Cursor 側はユーザールールで日本語にしている。地図ファイルに言語を書いておくのは、フォルダ管理の話ともつながる。
まとめ
/simplifyは直近差分の仕上げ。実装コミットのあとに挟み、refactor:で一周を閉じる/batchは独立ユニットへの分解と worktree 並列。承認前に走らせない。各ワーカーの末尾でも simplify する- Cursor には同梱が無いので、グローバルコマンドとして同じ切り方を置いた。本文に
simplify.mdとbatch.mdの全文を残してある - 正しさは Bugbot、外側のゴール型は CI。メイカーとチェッカーは分ける
- 1ファイルや探索では使わない。共有ヘルパーはバッチの前に入れる
前回「次は自分の作業のどれかをゴール型のループに落とす」と書いた。今回足したのは、そのループの品質ゲートと、グラフでいう fan-out の打ち方だ。偽エッジのテストも同じで、本当に独立していないユニットを並列にしない。トポロジーだけで誠実にはならないので、テストと git diff の目視は残す。
参考