Claude Code Plan Mode:用 plan-check skill 对照代码核查计划
Dmitriy Solodukha,Caprock 开发者 · 发布于
测试于 (Claude Code 和 Codex)
Claude Code 的 Plan Mode 会阻止编辑,直到你批准计划。plan-check skill 补充计划应包含的内容,并先对照代码逐行核查。
Claude Code 的 Plan Mode 会阻止智能体编辑,直到你批准计划;plan-check skill 则规定计划应包含什么,并在首次编辑前对照代码核查。智能体会写明文件、步骤、验证方法、风险及不做的事项,然后通过工具调用逐行确认,纠正错误后才修改代码。对于没有 Plan Mode 的智能体,是否继续取决于该 skill 中停止或继续的步骤。
安装 plan-check skill
每个智能体只需一条命令。skill 只有一个 SKILL.md;安装时不会运行任何内容。
将全部九个 skill 作为插件安装。在 Claude Code 中输入以下内容:
也可以只安装这个 skill,在终端中进入项目文件夹后运行:
添加 -g 即可为所有项目安装。
在终端中进入项目文件夹后运行:
添加 -g 即可为所有项目安装。
在终端中进入项目文件夹后运行:
添加 -g 即可为所有项目安装。 尚未在 OpenCode 上测试:这个 skill 是采用开放格式的纯文本指令,但还没有在 OpenCode 上实际运行验证。
在终端中进入项目文件夹后运行:
添加 -g 即可为所有项目安装。 尚未在 Cursor 上测试:这个 skill 是采用开放格式的纯文本指令,但还没有在 Cursor 上实际运行验证。
使用 plan-check skill 的提示词
你的措辞与 skill 描述匹配时,智能体会选择它;直接指定 skill 名称更有把握。点击提示词即可复制。
plan-check 为 Claude Code 的 Plan Mode 增加了什么
Claude Code 的 Plan Mode 强制要求“暂不修改”:智能体读取和探索代码、编写计划,然后等待你批准。它不规定好计划应包含什么,也不检查计划。这个 skill 会:
- 先读取,再规划:要修改的文件、它们的调用方、测试及项目运行测试的方式、项目的智能体指令,以及既有决策。
- 包含五个部分的计划:Files(真实路径)、Steps(每步都足够小,便于验证)、Verify(项目中已有的命令)、Risks,以及永不为空的 Not doing。
- 逐行核查:每个文件都存在,名称拼写与代码一致,涵盖所有调用方,验证命令能运行,遵守项目规则和既定决策。每行最终标记为 OK、FIXED 或 OPEN。
- 停止或继续:遇到 OPEN 问题、推翻已有决策或删除数据的情况,就会停下来询问你。否则会执行计划并报告结果。
在 Plan Mode 中,两者结合使用:要求按 plan-check 的格式制定计划,并在你批准前完成核查。
我们运行了什么,智能体做了什么
每个 skill 都于 2026年11月29日在为其专门创建的临时仓库中运行,并作为项目 skill 安装。测试使用一个小型 Python 仓库:src/prices.py 中的 format_price,由 cart_total 和 receipt_line 调用,使用 make test 运行测试。
Claude Code (claude -p --model sonnet)
Plan first, then do it: format_price should take a currency code (USD default, EUR uses the euro sign after the number). Do not touch anything until the plan is checked.
运行了两次。两次都调用了 plan-check,读取了文件及其调用方,并调用了 Caprock 的 current_decisions(其中一次未获权限,并说明了这一点),随后添加了 currency="USD",用 ValueError 处理未知代码,并新增了 tests/test_prices.py。make test 通过,7 项中有 7 项。最终报告列出了未改动的部分:cart_total 和 receipt_line 仍输出美元金额,负数金额原本就有格式错误(-5 得到 $-1.95),此次未修改。
Codex (0.163.0,codex exec)
The same prompt.
读取了 .agents/skills/plan-check/SKILL.md,按 skill 的五个部分写出计划(其 current_decisions 调用失败),对照代码检查(两个调用方都依赖默认的 USD;make -n test 确认了验证命令),然后编辑。以下是它的报告(省略空行和最后一句):
Implemented after checking the plan. - `format_price(150)` → `$1.50` - `format_price(150, "EUR")` → `1.50€` - Unsupported codes raise `ValueError`. All 6 tests pass; `git diff --check` passes. No deviations from the plan.
已测试的智能体
- Claude Code:测试于 2026年11月29日,使用
claude -p --model sonnet,skill 作为项目 skill 安装在.claude/skills/中。 - Codex:于 2026年11月29日使用 Codex 0.163.0(
codex exec)测试,skill 位于.agents/skills/。 - OpenCode 和 Cursor:未测试。此 skill 是以开放的 Agent Skills 格式编写的纯文本指令,但尚未在这两者上实际运行验证。
限制
- 在没有 Plan Mode 的智能体中,没有机制强制执行“no edits yet”:skill 中停止或继续的步骤是一条指令,而不是开关。
- 检查效果取决于智能体的搜索:通过反射或字符串调用的调用方可能会被漏掉。
- 如果只需修改一行,它会说明无需计划,并跳过自身流程。
使用和不使用 Caprock 的情况
连接 Caprock MCP 服务器后,skill 会调用 current_decisions,查找本次修改必须遵循的既有决策。未连接时,它会查找决策记录,以及涉及相同文件的近期提交消息。Caprock 是一款免费开源应用,记录你电脑上的每个编程智能体会话;skill 的其他功能都不依赖它。
完整的 SKILL.md
这是 dspv/skills 中修订版本 dfce799 的文件原样。手动安装时,将它保存在项目中:Claude Code 使用 .claude/skills/plan-check/SKILL.md,Codex 使用 .agents/skills/plan-check/SKILL.md。
---
name: plan-check
description: >
Write a short plan before changing code (files to touch, steps, how the change will be verified,
risks, what will not be done), then check every line of that plan against the actual code before
the first edit. Use when the user says "plan first", "make a plan before you code", "plan mode",
"claude code plan mode", "think before editing", "don't touch anything yet", or asks for a change
that spans several files, a refactor, a migration, or anything hard to undo. Works in any coding
agent; in Claude Code, plan mode is the built-in equivalent.
license: Apache-2.0
---
# Plan, check, then change
A plan written from memory of the code is a guess. This skill makes the agent write the plan down,
check it against the files as they are, fix what the check finds, and only then edit.
## When to use it, and when not
Use it before any change that touches more than one file, changes a public interface, moves data,
or is hard to undo, and whenever the user asks for a plan first.
Skip it for a one-line fix the user has already located, a typo, or a question that needs no edit.
Say in one line that no plan is needed and why.
## Step 1: Read before you plan
Read the code the change will touch before writing a word of the plan:
- the files you expect to edit, and their callers (search for each function, type, route or
config key you will change);
- the tests that cover them, and how the project runs its tests (README, Makefile,
package.json scripts, CI config);
- the project's agent instructions (CLAUDE.md, AGENTS.md or similar) for rules the change must keep.
**Earlier decisions.** If the Caprock MCP tool `current_decisions` is available, call it (it takes an
optional `project`, the repository folder's name, and `limit`) and keep the decisions that touch this
change. Without it, look for decision records in the repository (ADRs, a `docs/` decisions file,
recent commit messages on the same files with `git log --oneline -- <path>`). A plan that reverses an
earlier decision says so in Risks and asks the user. Caprock (https://caprock.dev, free, open source,
runs locally) provides that tool; nothing else here needs it.
## Step 2: Write the plan
Keep it short: a reviewer should read it in under a minute. Use exactly these sections.
```markdown
## Plan: <one-line goal>
**Files**
- `path/to/file.ext`: what changes (new function, edited block, deleted)
- `path/to/new_file.ext` (new): what it holds
**Steps**
1. <smallest step that leaves the code working>
2. ...
**Verify**
- `<exact command>`: what passing looks like
- <manual check, if a command cannot show it>
**Risks**
- <what could break, who calls it, what data it touches>
**Not doing**
- <tempting work left out of scope: refactors, renames, upgrades, unrelated fixes>
```
Rules for the plan:
- Every file is a real path. Every function, flag or command is named exactly as it appears in code.
- Each step is small enough to verify on its own; order steps so the code builds after each.
- Verify names commands that exist in this project, not generic ones.
- Not doing is never empty: name at least one thing you will deliberately leave alone.
## Step 3: Check the plan against the code
Go through the plan line by line and confirm each claim with a tool call (read, search, run), not
from memory:
| Check | How |
| --------------- | ------------------------------------------------------------------ |
| Files exist | List or read each path; a "(new)" path must not exist yet |
| Names are right | Search each function, type, key; note its exact signature |
| Callers covered | Search every use of what changes; each caller is in Files or Risks |
| Verify runs | The test or build command exists (script, target, binary) |
| Rules kept | Compare steps with the project's agent instructions |
| Decisions kept | Compare with the decisions found in Step 1 |
Then add a short block under the plan:
```markdown
**Check**
- OK: <claim confirmed, with the file or command that showed it>
- FIXED: <claim that was wrong, and what the plan says now>
- OPEN: <question only the user can answer>
```
If a check fails, fix the plan and re-check that line. Do not start editing with a FIXED line you
have not re-checked.
## Step 4: Stop or go
- **Stop and ask** when there is an OPEN line, when the plan reverses an earlier decision, when it
deletes data or files the user did not mention, or when the check found the task is much larger
than the user described. Show the plan and the Check block, ask the open questions, and wait.
- **Go** when every line is OK or a re-checked FIXED, and the user asked you to do the work (not
only to plan). If the user asked only for a plan, stop after the Check block.
## Step 5: Carry out the plan
- Follow the steps in order. Run the Verify commands at the end, and after any step that names its own
check.
- If the code turns out different from the plan (a caller you missed, a test that does not exist),
stop editing, update the plan and the Check block, and decide stop or go again. Do not drift.
- Touch nothing listed under Not doing.
## Step 6: Report
Always end with this report, in this shape, even when the change is small: it is how the user
sees whether the plan held.
```markdown
**Done**: <goal>
- Changed: `path` (what), ...
- Verify: `<command>`: <result, pasted or summarized>
- Differed from plan: <what and why, or "nothing">
- Left out: <the Not doing list, and anything found along the way>
```
## Plan mode in Claude Code
Claude Code has a built-in plan mode: Claude reads files and runs commands to explore, writes a plan,
and makes no edits until you approve it (Claude Code docs, permission modes page, read 2026-11-29).
Ways in:
- press `Shift+Tab` until the status bar shows plan mode on, or prefix a single prompt with `/plan`;
- start the session with `claude --permission-mode plan`;
- make it the project default with `"permissions": { "defaultMode": "plan" }` in `.claude/settings.json`.
At the approval prompt you can approve, keep planning, or press `Ctrl+G` to edit the plan in your
editor. Plan mode enforces "no edits yet"; this skill adds what to put in the plan and the check
against the code. Use both: in plan mode, write the plan in Step 2's format and run Step 3 before
asking for approval. In an agent without a plan mode, the skill's Stop or go step is the gate.
关于 plan-check skill 的问题
- 如何开启 Claude Code 的 Plan Mode?
- 按 `Shift+Tab`,直到状态栏显示 Plan Mode;也可以在某条提示词前加上 `/plan`,或用 `claude --permission-mode plan` 启动。要将其设为默认模式,在 `.claude/settings.json` 中设置 `"permissions": { "defaultMode": "plan" }`。
- plan-check skill 为 Plan Mode 增加了什么?
- 计划内容与核查:计划分为五个固定部分,在你批准前,逐行通过工具调用与代码核对,修正错误内容,并提出尚待解答的问题。
- 计划检查 skill 能用于 Codex 吗?
- 可以。skill 中“停止或继续”这一步就是关卡。在 2026年11月29日的测试中,Codex 0.163.0 遵循了这个流程:先规划,再核查,最后修改。
- 修正拼写错误也会写计划吗?
- 不会。对于已定位的单行修复、拼写错误或问题,它会用一行说明无需计划及其原因。