codebase-refactoring

A guide for making structural changes across a software repository while checking which files and callers are connected.

In plain words
What is it for?
Use it for multi-file refactors such as extracting methods, splitting classes, consolidating repeated code, and checking affected callers and related files.
Why use it?
It helps reduce breakage when moving responsibilities between files, splitting classes, or removing duplication. A refactor changes the internal structure while aiming to preserve how the software behaves for its users.

Skill for Claude CodeCodex

Part of the forensic-deepdive-codebase plugin — 5 skills shipped together

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/dhevenddra/forensic-deepdive/codebase-refactoring
Any agent
npx skills add Dhevenddra/forensic-deepdive --skill codebase-refactoring
Clone the repo
git clone --depth 1 https://github.com/Dhevenddra/forensic-deepdive

Made for: Claude Code, Codex.

Or install forensic-deepdive-codebase, the plugin that ships this one along with the rest of its 5 skills.

Per session 122 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 596 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.00122 $0.00596
Opus 5 $0.00061 $0.00298
Sonnet 5 $0.00024 $0.00119
Haiku 4.5 $0.00012 $0.00060

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

Security

Grade A, and why

codebase-refactoring 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.

tests/fixtures/prior_release/v0_8_0/.claude/skills/codebase-refactoring/SKILL.md · 35 lines

How it starts

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

Codebase refactoring

Coordinate multi-file structural changes against the codebase's coupling rules and co-change history. A refactor is not 'rename + reformat' — it's 'move responsibility while preserving every caller's contract.'

When to use

  • User wants to extract / inline / split / consolidate code across files.
  • Question shape: 'refactor X to do Y', 'extract method', 'split this class into A and B', 'consolidate this duplicated logic'.

When NOT to use

  • Change is contained in one file → just do the edit.
  • User is investigating a bug → codebase-debugging.
  • User is reading to understand → codebase-exploring.

How to answer

  1. Read docs/codebase/AGENT_BRIEF.md first. The 'if you touch X also touch Y' rules pre-encode the co-change neighborhood — refactors that ignore them break things in adjacent files.
  2. Read docs/codebase/HOTPATHS.md 'Co-change clusters' section. Files that historically co-change with the target should be reviewed in the same PR.
  3. If MCP server is running:
    • context(target_symbol) — full neighborhood (callers, callees, parent class, siblings, members, recent commits).
    • impact(target_symbol, direction='upstream') — every caller that will need to compile after the change.
  4. Surface the dominant author from ARCHAEOLOGY.md if the target file has one — they own the historical context.

Pitfalls

  • Don't refactor a symbol with AMBIGUOUS callers without listing them first — the human should resolve the ambiguity.
  • Don't refactor a symbol whose co-change cluster includes files the user didn't mention — flag those files, ask if they should be in scope.
  • Don't auto-rename across a polyglot graph (DEC-012's language-scoped rule) without checking that the symbol's other-language references are intentional.

Citation rule

Cite every coupling rule (docs/codebase/AGENT_BRIEF.md:23) and every co-change pair (docs/codebase/HOTPATHS.md:78). Never propose a multi-file refactor without first showing the impact list.

Read the full file on GitHub · 35 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 · 35 lines · 122 tokens per session scan A e8531de83f21

Subscribe to this mod's changes

codebase-refactoring is a skill published in the GitHub repository Dhevenddra/forensic-deepdive (2 stars, last pushed 17d ago), licensed Apache-2.0. It adds 122 tokens to every session and 596 once invoked, about $0.0006 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.

Related

Other skills, from other repositories

mistakes

List past mistakes engram has learned in this project — failures, regressions, broken assumptions. Use before starting a non-trivial change to surface relevant prior failures, or when debugging to check if this issue has been seen before.

NickCirv/engram · 46 tokens

query

Query engram's local knowledge graph for structural context — function calls, imports, type relationships, mistake history, ADRs. Use when the user asks "how does X work in this project", "what calls Y", "where is Z used", or any structural question that doesn't need file content.

NickCirv/engram · 60 tokens

chatcrystal-task-writeback

Write reusable ChatCrystal task memories after substantive work completes. Use when implementation or debugging produced a durable fix, pitfall, pattern, or decision worth preserving, and when the environment can either persist it through writetaskmemory or emit a structured memory candidate for later save.

ZengLiangYi/ChatCrystal · 62 tokens

chatcrystal-debug-recall

Recall ChatCrystal memories for debugging tasks involving failing tests, compiler errors, runtime exceptions, dependency issues, environment breakage, or performance regressions. Use when historical root causes, fixes, or pitfalls may accelerate diagnosis before proposing a fix.

ZengLiangYi/ChatCrystal · 54 tokens

chatcrystal-task-recall

Recall project-first and global-supplement ChatCrystal memories before substantive implementation, refactoring, migration, configuration, investigation, or optimization work. Use when the task is non-trivial, has repository or project context, and prior fixes, decisions, pitfalls, or reusable patterns may change the…

ZengLiangYi/ChatCrystal · 66 tokens

slm-graph

Index and query a codebase as a structural graph — build the code graph, trace blast radius of a change, find callers/callees/inheritors, semantic code search by meaning, assemble PR review context, and detect what changed since last index. Use when the user asks how code connects, what breaks if X changes, what calls…

qualixar/superlocalmemory · 97 tokens