read-before-write

A coding rule that says you should inspect the existing project before adding new code. It focuses on finding matching patterns, helpers, tests, and conventions first.

In plain words
What is it for?
Use it before creating types, functions, endpoints, tests, errors, or configuration fields so the change follows the codebase's established approach.
Why use it?
It reduces duplicated code and prevents new code from conflicting with the project's existing naming, structure, error handling, and logging.

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/arango-solutions/arango-sparql-py/read-before-write
Clone the repo
git clone --depth 1 https://github.com/arango-solutions/arango-sparql-py

Made for: Cursor.

Per session 384 This file is loaded in full into every session.
When invoked 384 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.00384 $0.00384
Opus 5 $0.00192 $0.00192
Sonnet 5 $0.00077 $0.00077
Haiku 4.5 $0.00038 $0.00038

Measured 2d ago against content hash 3cafa318b431, 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-write 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 2d ago.

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-write.mdc · 53 lines

What it actually says

Read Before Write

"Match the codebase, don't fight it."

Before writing ANY code, understand what already exists. The codebase has patterns, conventions, and utilities. Use them, don't reinvent them.

The Reading Protocol

Before implementing anything:

  1. Pattern Search — How does the codebase already do this?
  2. Utility Search — Is there a helper for this?
  3. Existing Implementation — Has someone already solved this?
  4. Test Pattern Search — How are similar things tested?

What You Must Find Before Writing

Before Writing Find First
New struct/type Existing similar types
New function Existing utilities with same behavior
New endpoint Existing endpoint patterns
New test Existing test helpers/patterns
New error type Existing error conventions
New config field Existing config structure

Pattern Matching Requirements

When you find existing patterns, you MUST:

  1. Use the same naming conventions
  2. Use the same file organization
  3. Use the same error handling style
  4. Use the same logging approach
  5. Use existing utilities — don't write formatTime() if utils.FormatTime() exists

The Duplication Detector

Question If Yes →
Does this function already exist? Use it
Does a similar type already exist? Extend or reuse it
Is there a util/helper for this? Call it
Is there an established pattern? Follow it

The codebase was here before you. Your job is to make it more consistent, not less.

Read first. Match the patterns. Then write.

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. 2d ago First seen · 53 lines · 384 tokens per session scan A 3cafa318b431

Subscribe to this mod's changes

read-before-write is a cursor rule published in the GitHub repository arango-solutions/arango-sparql-py (2 stars, last pushed 15d ago), licensed MIT. It adds 384 tokens to every session, about $0.0019 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.