| name | batch-rewrite-pattern |
| description | Cascade the same edit pattern across N files safely. Use when applying the same refactor to multiple files (e.g. swap import paths across 11 scripts, rename a symbol, migrate a call signature). Detects the common-shape-across-files situation and turns an N-file cascade into a planned audit → apply → verify workflow instead of N sequential manual edits. |
| format | "2025-10-02T00:00:00.000Z" |
| version | 1.0.0 |
| status | stable |
| updated | "2026-04-17T00:00:00.000Z" |
| type | skill |
| category | gsd-meta |
| origin | tibsfox |
| modified | false |
| first_seen | "2026-04-17T00:00:00.000Z" |
| first_path | examples/skills/gsd-meta/batch-rewrite-pattern/SKILL.md |
| superseded_by | null |
Batch Rewrite Pattern
When the same edit needs to land in N files, the worst shape is N sequential
manual passes. Each pass collects its own errors; the hook system retriggers;
context fills with repetitive diffs. This skill captures the better shape.
Triggers
Activate when any of these apply:
- Renaming a symbol across the tree
- Migrating a function signature (add/remove/reorder args)
- Swapping an import path across modules
- Converting between two patterns (callbacks ↔ promises, v1 ↔ v2 API)
- Any edit where you can describe the transformation as "in every file
matching pattern X, replace Y with Z"
Typical count trigger: ≥ 4 files warrant the batch shape.
Workflow
-
Characterize the transformation in one paragraph:
- What's the before pattern? (regex or literal)
- What's the after pattern?
- Are there variants? (single pattern vs family of patterns)
- Any files that should be exempt?
-
Enumerate candidates with Grep/Glob:
Grep pattern=BEFORE output=files_with_matches
-
Dry-run the rewrite against 1-2 candidates first. Verify:
- The transformation is correct
- Surrounding context isn't disturbed
- No collateral damage
-
Apply in a batch — prefer a single Bash sed/perl invocation or a
small rewrite script over N sequential Edit calls:
for f in $(grep -l 'BEFORE' src/**/*.ts); do
sed -i -e 's/BEFORE/AFTER/g' "$f"
done
Or write a one-shot node script that reads each file, applies the
transformation, writes back.
-
Verify with the test suite if one exists, or with a grep that the
after-pattern is uniformly present and the before-pattern is gone.
-
Single commit covering the whole cascade, scope line listing files.
Anti-patterns to avoid
- Sequential manual Edit calls when the transformation is deterministic.
Each Edit triggers hook re-reads and bloats context.