read-before-edit

A rule requiring files to be checked from the current workspace before they are edited. The workspace is treated as the latest source of truth.

In plain words
What is it for?
Safely editing files in projects where code may change between conversations or through other tools.
Why use it?
It prevents changes from overwriting edits made outside the conversation or relying on an outdated copy of a file.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/xc404/kiwi/read-before-edit
Clone the repo
git clone --depth 1 https://github.com/xc404/kiwi

Made for: Cursor.

Per session 457 This file is loaded in full into every session.
When invoked 457 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00457 $0.00457
Opus 5 $0.00229 $0.00229
Sonnet 5 $0.00091 $0.00091
Haiku 4.5 $0.00046 $0.00046

Measured yesterday against content hash 30f68316a4dc, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

read-before-edit scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/read-before-edit.mdc · 27 lines

What it actually says

修改前同步工作区(避免覆盖)

原则

  • 工作区磁盘上的文件是唯一真相;对话里缓存的代码片段、上一轮 tool 输出、或记忆中的版本都可能落后于用户在外部保存的改动
  • assistant 在修改任意文件之前,必须先拿到「当前将要写入的最终版本」,再基于该版本做最小差异编辑;不得仅凭会话上下文拼补丁。

必须执行的操作

  1. 在每次 apply_patch / 实质性编辑之前,对目标路径使用 Read 工具重新读取文件全文或足够大的局部(含待改片段的上下文),以当前内容作为 old_string / 补丁基准。
  2. 若用户说明「已在外部改过」「与磁盘不一致」或涉及多人/多轮并行修改:对受影响路径再读一遍;必要时在仓库根目录执行 git diff -- <path>(或 git diff)查看相对版本库的未提交差异,再合并意图。
  3. 若 Read 结果与对话中的假设不一致,以 Read 为准,并在回复中简要说明已按最新文件调整(无需长篇)。

禁止

  • 在未重新 Read 目标文件的情况下,用大段替换「还原」助手记忆中的旧版本。
  • 用过时行号或过时引用块作为补丁依据(行号会变;应以 Read 返回的当前文本为准)。

说明

「当前 session 的最终版本」在工程上等同于:用户已保存到工作区的文件;通过 Read(及可选 git diff)与之对齐,即完成与「外部改动」的 diff,避免覆盖。

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 27 lines · 457 tokens per session scan A 30f68316a4dc

Subscribe to this mod's changes

read-before-edit is a cursor rule published in the GitHub repository xc404/kiwi (7 stars, last pushed 7d ago), licensed MIT. It adds 457 tokens to every session, about $0.0023 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.