edit-file-usage

A tool for changing a specific part of an existing repository file by replacing an exact piece of text.

In plain words
What is it for?
It helps update one function, setting, or named piece of code while leaving the rest of the file unchanged.
Why use it?
It avoids rewriting the whole file when only a small, known change is needed, while checking that the edit stays within allowed paths and can be rolled back.

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/sharpninja/mcpserver/edit-file-usage
Any agent
npx skills add sharpninja/McpServer --skill edit-file-usage
Clone the repo
git clone --depth 1 https://github.com/sharpninja/McpServer

Made for: Claude Code, Codex.

Per session 44 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,236 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.00044 $0.01236
Opus 5 $0.00022 $0.00618
Sonnet 5 $0.00009 $0.00247
Haiku 4.5 $0.00004 $0.00124

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

Security

Grade A, and why

edit-file-usage 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.

skills/edit-file-usage/SKILL.md · 90 lines

How it starts

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

edit_file Usage

The QBAgent edit_file tool performs a surgical, in-place change to a single file by replacing an exact oldString with a newString. Edits are not raw filesystem writes: they route through the MCP Server RepoFileService (interface IRepoFileService, src/McpServer.Services/Services/RepoFileService.cs) and are wrapped by TransactionGatedRepoFileService (src/McpServer.Support.Mcp/Services/TransactionGatedRepoFileService.cs), which enforces the path allowlist (FR-SUPPORT-010, TR-PLANNED-CORE-013) and transactional rollback compensation via IRepoFileCompensation (TR-MCP-TXN-001).

When to Use

  • Changing a known region of an existing file: one function, one config key, a few lines.
  • Renaming or retargeting a symbol where you can pin a unique surrounding context.
  • Any edit where most of the file should stay byte-for-byte unchanged.

When Not to Use

  • Creating a brand new file, or replacing essentially all of a file's content: use write_file (backed by RepoFileService.WriteAsync) instead.
  • The target path is outside the workspace allowlist: the write will be rejected.
  • You cannot read the file first to obtain an exact oldString. Never guess at content.

Inputs

  • filePath (or relativePath): path to the existing file, relative to the repo root.
  • oldString: exact text to find, including original indentation and line breaks.
  • newString: replacement text. Must differ from oldString.
  • replaceAll (optional, default false): replace every occurrence instead of one.
  • expectedOccurrences (optional): assert the number of matches before applying; the edit fails if the actual count differs. Use this as a guard when replaceAll is true.

Critical Rules

  • Read the file first. oldString must match the on-disk bytes exactly, including leading whitespace. Strip any line-number or cat -n prefixes before matching.
  • oldString must be unique within the file unless replaceAll is set. A non-unique oldString without replaceAll is an error; widen the surrounding context to a unique span rather than forcing it.
  • oldString and newString must differ. A no-op edit is an error.
  • Prefer edit_file over write_file for partial changes. Rewriting a whole file discards unrelated content, defeats the diff, and risks clobbering concurrent edits.
  • Edits are transactional. On a failed turn transaction, IRepoFileCompensation restores the prior file state, so a rejected edit leaves the file unchanged. Do not add your own manual rollback logic.
  • Do not chase path-safety or rollback yourself: the server owns both. Treat a rejected edit as a signal to fix the path or the oldString, not to retry blindly.

Read the full file on GitHub · 90 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. yesterday First seen · 90 lines · 44 tokens per session scan A ce0aac1cdfa5

Subscribe to this mod's changes

edit-file-usage is a skill published in the GitHub repository sharpninja/McpServer (2 stars, last pushed 11d ago), licensed Apache-2.0. It adds 44 tokens to every session and 1,236 once invoked, about $0.0002 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.