skills/audit-and-migrate/SKILL.md
Slice-based, evidence-driven framework for explicit codebase migrations and convergence programs. Use when the user is moving from a named source to a named target, running a multi-session standardization effort across a codebase, consolidating parallel implementations into one target architecture, or asking for a migration playbook with slices, ratchets, handoffs, and release closeout. Do not trigger for normal refactors, routine cleanup, or one-off architecture improvements that are not framed as a migration or convergence effort.
npx skillsauth add petekp/claude-code-setup audit-and-migrateInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A structured methodology for tackling codebases with accumulated technical debt. Works in three phases — audit (understand and freeze the problem), migrate (pay it down slice by slice with proof), then closeout (remove residue and prove the repo is actually ready to ship).
Agents without structure fail at four things during large refactors:
Every rule in this methodology prevents one of these four failures. When a rule feels heavy, that's the justification.
Do this at the start of every session. This is what makes the methodology survive context compaction and session switches.
.claude/migration/ or wherever the project stores them):
CHARTER.md, DECISIONS.md, SLICES.yaml, MAP.csv, RATCHETS.yaml, SHIP_CHECKLIST.mdHANDOFF.md if prior sessions have touched the migrationCHARTER.md — re-absorb the mission and invariants
b. SHIP_CHECKLIST.md — re-load the project-specific definition of "ready to ship"
c. DECISIONS.md — understand what's been decided and why
d. Latest HANDOFF.md — recover current status and blockers quickly
e. All in_progress slices in SLICES.yaml — this is your current work
f. Run the guard script to see current statusWrite or update HANDOFF.md (or append to the most recent commit message if the handoff is small). Five parts, no exceptions:
NoneExample:
## Handoff — 2026-03-01
### Changed
- Completed slice-003 (user routes auth migration)
- Ratchet budget for jwt.verify decreased from 8 → 5
### Now True
- All user route auth goes through withAuth() middleware
- Behavioral tests cover user routes at 100%
### Remains
- slice-004 (data routes) ready to start
- slice-005 (admin routes) blocked on Decision 4 re: webhook auth
### Shipping Blockers
- None
### Next Steps
1. Run `./guard.sh --status` to confirm baseline
2. Start slice-004: mark in_progress in SLICES.yaml
3. Write behavioral tests for src/api/posts.ts and src/api/comments.ts
This format survives context compaction. The next session (or a different agent) can pick up without information loss or having to guess whether the repo is actually releasable.
The audit phase is about understanding the problem space before changing production code. Measuring first creates the foundation that makes migration safe, and defining the ship gate early prevents the common failure mode where the implementation lands but cleanup keeps spilling into follow-up runs.
Create CHARTER.md using the template in references/templates/CHARTER.md. This defines:
The charter is the constitution. When in doubt about scope, check the charter.
Catalog everything in the target domain — code, tests, scripts, docs, configuration, tooling, and dependencies. For each item, classify by leverage:
Be exhaustive. Anything missed here risks becoming vestigial code later. If an item is low leverage, record what will replace it or which slice will delete it.
Before designing slices, sweep for the parts of the system most likely to burn you later:
These become your slice smoke tests, manual checks, and ship-gate inputs.
Use grep/ripgrep to count specific weak patterns. The goal is concrete numbers, not vibes.
For each pattern, record:
Examples (adapt to your codebase):
Pattern: source\.contains\( Scope: test/ Count: 43 Problem: Tests code shape, not behavior
Pattern: Task\.sleep\( Scope: test/ Count: 17 Problem: Non-deterministic timing
Pattern: struct Scenario Scope: test/ Count: 22 Problem: Duplicated test scaffolding
Pattern: require\(.*/utils/old- Scope: src/ docs/ Count: 8 Problem: Imports from deprecated module
For each measured anti-pattern, create a ratchet that enforces a maximum budget equal to the current count. See The CI Ratchet Pattern for the technique.
This is the most important step. Once ratchets are in place, debt can only decrease. No one — human or agent — can accidentally reintroduce eliminated patterns. Ratchets are only trustworthy if the query and search scope are explicit and the count measures matches, not just matching files.
Write these ratchets into RATCHETS.yaml using the template in references/templates/RATCHETS.yaml. Do not let the guard script become the only place the budgets live.
Create a comprehensive audit doc. Include:
Alongside the control plane artifacts, produce domain-specific reference material that will accelerate the actual migration work:
This material pays for itself many times over — without it, every slice (and every agent session) independently rediscovers the same conversion patterns. With it, the knowledge is captured once and reused throughout.
Using templates in references/templates/:
DECISIONS.md — seed with any architecture decisions from the auditSLICES.yaml — populate with proposed slices from the audit docMAP.csv — populate with all files from the inventoryRATCHETS.yaml — machine-readable anti-pattern budgets and scopesSHIP_CHECKLIST.md — define the exact release gate once, then execute it during closeoutMigration is slice-by-slice debt paydown. Each slice is a vertical, outcome-based unit of work that can be independently verified.
If the audit was done without full codebase access (e.g., based on a description or partial exploration), the first action in Phase 2 is calibrating the ratchet budgets against reality. Run every grep pattern from the audit document and update the guard script budgets with actual counts. This is a quick, high-value step — incorrect budgets produce either false failures (budget too low) or silent regression (budget too high).
Also run the guard script with a --status flag (if you added one) to confirm a clean green baseline before starting any slice work.
Also confirm SHIP_CHECKLIST.md contains exact commands and scenarios rather than placeholders. A closeout phase is only as good as the checklist it runs.
Before starting implementation, reserve a final convergence slice in SLICES.yaml. It should depend on every implementation slice and own whole-codebase cleanup: residue sweep, dependency pruning, docs/config reconciliation, and execution of SHIP_CHECKLIST.md.
If you don't reserve this slice up front, cleanup becomes "later work," and later work quietly becomes another migration.
Review SLICES.yaml for the highest-leverage unblocked slice:
doneEvery implementation slice follows five stages.
in_progress in SLICES.yamlMAP.csvdeletion_targets, temp_artifacts, dependency_changes, residue_queries, verification_commands, docs_to_update, and any touched external_surfaces in SLICES.yaml before writing any codetemp_artifacts with an owning slice.Before calling the slice "verified," do a focused residue sweep across touched paths and their adjacent modules:
DECISIONS.md with an owner and exit conditionCleanup is not just "delete what you already planned to delete." It is "prove this slice didn't leave residue nearby."
Residue queries must be specific and scoped. Avoid broad patterns like legacy across the whole repo when legitimate retained names still exist. Prefer queries like import.*legacy-auth, LEGACY_COOKIE_NAME, or TODO\\(migration\\) with explicit search roots.
Run all applicable checks:
verification_commands pass — run the exact automated commands recorded in SLICES.yamlSLICES.yaml, run themresidue_queries return zero matches — old names, flags, TODO markers, and temp markers are actually gonedeletion_targets are physically removed (not commented out, not behind a flag — gone)temp_artifacts are removed or explicitly handed to a later owning slicedocs_to_update and dependency_changesMAP.csv — mark migrated files, remove deleted files, keep docs/config/tooling entries in syncSLICES.yaml — mark slice done, record what was accomplished and what evidence passedRATCHETS.yaml — decrement budgets, add notes for ratchets driven to zeroDECISIONS.mdIf the cleanup sweep uncovers extra dead code beyond the original deletion_targets, either delete it now or create an explicit follow-up slice before calling the current slice done. Do not leave newly discovered residue as ambient debt.
Migration is not complete when the last implementation slice lands. It is complete when the repo is globally clean and the project-specific ship gate passes.
Treat closeout as a real convergence slice, not an afterthought.
MAP.csv against reality. No unmapped files, orphaned replacements, or forgotten side artifacts.SHIP_CHECKLIST.md. Run the exact lint/typecheck/build/test/replay/smoke/manual checks defined during the audit. Automate everything possible; manual checks are only for visual, experiential, hardware, or third-party surfaces automation cannot prove.old/new/final artifacts.Ready to ship or list the exact blockers that remain. If debt is intentionally retained, record it in DECISIONS.md with an owner and exit condition.The methodology's signature technique. Instead of eliminating all instances of a bad pattern at once:
source.contains assertions)Why this works so well for agents: It provides a clear, mechanical pass/fail signal. No judgment about whether a few instances are "OK." The ratchet answers definitively. Progress is visible: 43 → 38 → 29 → 15 → 7 → 0 is a concrete trajectory.
Implementation: Typically a shell script that greps for the pattern, counts matches, compares against the budget, and exits non-zero if count exceeds budget. Count exact matches, not just matching files, and keep the search scope explicit. Budgets should live in RATCHETS.yaml, not only in the script. See references/guard-script-pattern.md for the pattern. Wire it into CI or pre-commit hooks.
Vestigial code — old code replaced but never deleted — is the biggest source of codebase bloat in agent-assisted development. Agents optimize for "does the new thing work?" without asking "did I remove the old thing?"
For every slice:
Define deletion_targets before implementation. Write them into SLICES.yaml before building. This creates accountability — you can't "forget" to delete something when it's pre-defined.
Add denylist patterns for removed names/paths. After deleting code, add a grep pattern to the guard script that fails if the name reappears. Stronger than test coverage because it catches reintroduction anywhere in the codebase.
Delete docs describing removed architecture. Stale docs about removed systems actively mislead future agents and developers.
Remove obsolete scripts, config, and env fallbacks. Configuration for removed features is invisible debt.
No "temporary" adapters without: an owning slice ID, an expiry condition, and an explicit deletion target. Adapters without a planned death live forever.
Kill migration markers. TODO(migration), temporary debug logging, scratch files, and old/new/final copies are residue, not harmless notes.
Each slice must be:
When verifying slice correctness, use layered evidence in priority order:
If evidence sources conflict, deterministic replay wins. "Tests pass but the replay diff differs" means something is wrong — investigate, don't dismiss.
If a check can be automated, it belongs in verification_commands, not in human memory or a future TODO.
Seven artifacts govern the migration. Templates are in references/templates/.
| Artifact | Purpose | Update Frequency |
|---|---|---|
| CHARTER.md | Mission, invariants, non-goals, guardrails | Rarely (scope changes only) |
| DECISIONS.md | Append-only architecture decisions | Each decision-making slice |
| SLICES.yaml | Machine-readable slice ledger | Start and close of each slice |
| MAP.csv | Source-of-truth path mapping | Start and close of each slice |
| RATCHETS.yaml | Machine-readable anti-pattern budgets, scopes, and rationale | Seed in audit, update when budgets fall |
| SHIP_CHECKLIST.md | Project-specific release gate and closeout checklist | Seed in audit, execute during closeout |
| Guard script | CI-enforced invariant checks | When adding/removing ratchets |
Each slice tracks: id, type (implementation or convergence), name, status (proposed → in_progress → done), dependencies, touched_paths, external_surfaces, contracts (added/changed/removed), denylist_patterns, deletion_targets, temp_artifacts, docs_to_update, dependency_changes, residue_queries, verification_commands, replay_scenarios, smoke_scenarios, manual_checks, risks, notes.
slice_id, kind, capability, current_path, target_path, status, delete_in_pr, verification, notes
Every file touched by the migration must appear. This prevents files from falling through the cracks. Use kind to keep docs/config/tooling first-class, not invisible side work, and verification to record the command or scenario that proves the artifact is still valid.
When using multiple agents or parallel sessions:
Keep parallel work on truly independent file sets. Two agents committing to the same branch can silently displace each other's work. Slice boundaries should map to non-overlapping files.
CI ratchets are the most agent-friendly guardrail. Mechanical pass/fail beats requiring judgment about whether a change is "safe."
Denylist patterns prevent regression more reliably than tests. A regex CI check saying "this function name must not appear in this directory" is stronger than hoping test coverage catches reintroduction.
The handoff contract is non-negotiable. Without it, context compaction causes agents to redo completed work or skip remaining work.
Keep closeout owned by one slice. Parallelize implementation slices when file sets are disjoint, but reserve one convergence slice that owns the final residue sweep and ship gate.
This methodology works for non-code domains too — scripts, docs, tooling, configuration. The cycle is the same: inventory → measure → freeze → pay down. The "delete in the same change" discipline and anti-vestigial sweeps are just as valuable when consolidating documentation or eliminating redundant scripts.
tools
Comprehensively manually test the Circuit plugin's user-facing surface in either Claude Code or Codex. Use this skill whenever the user asks to "manually test Circuit", "QA the Circuit plugin", "exercise the Circuit surface", "run the Circuit checklist", "smoke test Circuit", "find regressions in Circuit", "test the Claude Circuit plugin", "test the Codex Circuit plugin", or when preparing a Circuit release for marketplace publication. Argument is the host package to test — `claude` or `codex`. Produces a Markdown report with per-command pass/fail, exploratory findings ranked by severity, run-folder evidence links, and a concise terminal summary. Use even if the user does not say the word "test" — phrases like "go through every Circuit command" or "make sure Circuit still works end-to-end" should also trigger.
development
Turn the prompt supplied with this skill into a concise, auditable Codex Goal or explain why a Goal is not the right fit. Use when the user asks to draft, formulate, rewrite, tighten, or create a `/goal` from a plain-language task, especially for multi-step work that needs a durable objective, evidence-based completion, constraints, iteration policy, and a default adversarial review loop.
development
Give the human a fast, plain-English catch-up on what changed in the project: what the agents did, why, and what decisions need their input. Use this whenever the user asks to "catch me up", "what changed", "where are we", "recap", "brief me", "give me the rundown", "what did you do", "summarize the session", "fill me in", or otherwise signals they have been away and want to get back up to speed quickly. Built for someone steering several agent-driven projects at once who does not read the code closely but needs to grasp the core ideas, the choices made, and the open decisions well enough to steer. Trigger even if they do not use these exact words: any request to get oriented on recent progress should use this skill.
tools
Expert Unix and macOS systems engineer for shell scripting, system administration, command-line tools, launchd, Homebrew, networking, and low-level system tasks. Use when the user asks about Unix commands, shell scripts, macOS system configuration, process management, or troubleshooting system issues.