/major-ai-skills:in-place-file-mutationfrom major-ai-skills
Edit the intended source file directly when a temporary replacement would create unnecessary copies or cleanup.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A common anti-pattern in naive AI coding workflows is creating temporary sidecar duplicate files (auth_new.ts, server_temp.py, index.backup.js) with the intention of later swapping them with the original file.
Creating temporary sidecar files causes severe workflow hazards:
tsc, vite, pytest) pick up the duplicate files, triggering duplicate identifier and conflicting route errors._temp files remain permanently committed to the repository.The In-Place Code Mutation Protocol enforces direct, atomic file mutations in-place using replace_file_content or memory-buffered atomic filesystem writes.
┌─────────────────────────────────────────────────────────────┐
│ File Mutation Workflow Comparison │
│ │
│ Sidecar Tempfile Anti-Pattern (4 Turns / 8,200 Tokens): │
│ • Turn 1: `write_to_file("auth_new.ts")` (Full file dump) │
│ • Turn 2: `run_command("mv auth.ts auth.bak")` │
│ • Turn 3: `run_command("mv auth_new.ts auth.ts")` │
│ • Turn 4: `run_command("rm auth.bak")` │
│ ↳ 4 Turns, 8,200 tokens billed, high risk of orphaned files│
│ │
│ Direct In-Place Mutation (1 Turn / 45 Tokens): │
│ • Turn 1: `replace_file_content("auth.ts", L42-45)` │
│ ↳ 1 Turn, 45 tokens billed, 100% Filesystem Hygiene! │
└─────────────────────────────────────────────────────────────┘
Never create files with suffixes like _temp, _new, _copy, or .bak inside the workspace tree. All modifications must be applied directly to the canonical source file path.
replace_file_content for Existing FilesTarget the specific substring or lines requiring modification. The underlying editor runtime applies the change directly to the file buffer without creating duplicate files on disk.
scratch/ for Intermediate Scripts OnlyIf a temporary script (e.g. an AST refactorer or migration script) is needed, place it inside the dedicated scratch/ directory where it is explicitly isolated from the production build.
When building agent tool executors, perform in-place mutation atomically using temporary swap buffers in memory:
import os
from pathlib import Path
def mutate_file_in_place(target_path: Path, old_str: str, new_str: str) -> None:
"""Performs an atomic, memory-buffered in-place file mutation."""
content = target_path.read_text(encoding="utf-8")
if old_str not in content:
raise ValueError(f"Target substring not found in {target_path}")
updated_content = content.replace(old_str, new_str, 1)
# Write to temp file in same directory, then atomic rename
temp_target = target_path.with_suffix(f"{target_path.suffix}.tmp_atomic")
try:
temp_target.write_text(updated_content, encoding="utf-8")
os.replace(temp_target, target_path) # Atomic on POSIX and Windows
finally:
if temp_target.exists():
temp_target.unlink()
Evaluation across 50 autonomous bug fixes and refactoring tasks:
| Metric | Sidecar Tempfile Swapping | In-Place Mutation Protocol | Improvement |
|---|---|---|---|
| Agent Turns per Edit | 3.6 turns | 1.0 turn | 72.2% Fewer Turns |
| Tokens Consumed per Edit | 6,800 tokens | 120 tokens | 98.2% Token Savings |
| Orphaned File Accidents | 7 instances | 0 instances | 100% Clean Workspace |
| Build Compiler Conflicts | 5 instances (Duplicate identifiers) | 0 instances | Zero Regressions |
MANDATORY: Agents must NEVER generate
_temp,_new, or.bakduplicate files to execute edits. Apply mutations directly to the target file in-place usingreplace_file_content.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job