rewrite

A skill for replacing an entire file when a small edit or patch is repeatedly failing or the required change affects much of the file.

In plain words
What is it for?
Use it after repeated edit failures, for large refactors in smaller files, or when the user explicitly asks for a full rewrite.
Why use it?
It avoids accumulating failed edits and makes broad structural changes easier to apply cleanly.

Skill for Claude CodeCodex

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 skills/stoa-platform/stoa/rewrite
Any agent
npx skills add stoa-platform/stoa --skill rewrite
Clone the repo
git clone --depth 1 https://github.com/stoa-platform/stoa

Made for: Claude Code, Codex.

Per session 52 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 971 The whole file, excluding the scripts and references it only reads on demand.
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.00052 $0.00971
Opus 5 $0.00026 $0.00485
Sonnet 5 $0.00010 $0.00194
Haiku 4.5 $0.00005 $0.00097

Measured 2d ago against content hash 8679b3ac87e2, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

rewrite 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.

.claude/skills/rewrite/SKILL.md · 80 lines

How it starts

The opening of the file, as written. The whole thing — 80 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Rewrite — $ARGUMENTS

Invoked when Edit (patch) is the wrong tool. Research shows search/replace fails 20-30% on evolved code, and accumulated failed patches poison the context (Liu et al. "Lost in the Middle"; Databricks Mosaic). See feedback_rewrite_after_fail.md.

When to use this skill

Triggered automatically via the hook post-edit-failure-tracker.sh at 2 consecutive Edit failures. Also invoke manually when:

  • Diff estimated >30% of the file size
  • Refactoring where structure changes, not just content
  • File is small-to-medium (≤800 lines) and a clean rewrite is cheaper than hunting for correct search/replace anchors
  • User says "just rewrite it"

Do NOT use for:

  • Single-line changes (use Edit)
  • Files >1500 lines (split first, or delegate to subagent)
  • Files you haven't read yet in this session (read first, understand first)

Workflow

Step 1 — Parse arguments

Split $ARGUMENTS into:

  • FILE_PATH (first token, absolute path)
  • INTENT (remainder — what the rewrite should accomplish)

If INTENT is empty, ask the user: "What should the rewrite accomplish? (e.g. 'fix the auth middleware bug', 'add tenant filtering')". Do NOT guess the intent from context alone.

Step 2 — Read the current file

Always Read the full file before rewriting. If >1500 lines, stop and suggest splitting or subagent delegation instead.

Step 3 — Check pollution signal

jq --arg path "$FILE_PATH" '[.[] | select(.path == $path)] | .[0]' .claude/state/edit-attempts.json

If consecutive_fails ≥ 2, the rewrite is warranted. If total ≥ 5 but consecutive_fails < 2, consider whether a subagent with fresh context would be better than an inline rewrite (Main context already has noise).

Step 4 — Rewrite strategy

Preserve by default:

  • Public API surface (exported symbols, function signatures if referenced elsewhere)
  • Import structure and file-level conventions
  • Comments that explain non-obvious WHY (delete comments that explain WHAT)
  • Type annotations, docstrings where they exist

Read the full file on GitHub · 80 lines

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 · 80 lines · 52 tokens per session scan A 8679b3ac87e2

Subscribe to this mod's changes

rewrite is a skill published in the GitHub repository stoa-platform/stoa (5 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 52 tokens to every session and 971 once invoked, about $0.0003 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.