Audit a codebase for handcrafted code that duplicates functionality already available in the project's dependencies. Reads package.json, launches parallel exploration agents, verifies replacement feasibility, and produces a structured refactor plan. Audit only -- does not execute changes.
Audit a codebase for handcrafted code that could be replaced by existing dependencies.
Projects accumulate utility code over time. Some predates a dependency that now covers the same ground; some was written before the team discovered a library API. Removing these duplications shrinks maintenance surface and leverages battle-tested implementations with better edge-case handling and security patches.
bun -e "const p=JSON.parse(await Bun.file('package.json').text()); console.log(JSON.stringify({...p.dependencies,...p.devDependencies}))" 2>/dev/nullbun --version 2>/dev/null || node --version 2>/dev/nullbun -e "const p=JSON.parse(await Bun.file('package.json').text()); console.log(p.dependencies?.effect || p.devDependencies?.effect ? 'yes' : 'no')" 2>/dev/nullbun -e "const p=JSON.parse(await Bun.file('package.json').text()); console.log(p.devDependencies?.['@types/bun'] ? 'yes' : 'no')" 2>/dev/nullls src/ 2>/dev/null | head -20The project context above was resolved at skill load time. Use it to decide which pattern catalogs each agent should read:
references/patterns/effect-infra.md in the infra
agent's pattern listreferences/patterns/runtime-infra.md for infra agent,
references/patterns/general-utility.md and references/patterns/runtime-utility.md
for utility agentThe subagents have effect-usage and bun skills preloaded — no need to load companion
skills in the orchestrator.
Spawn two custom subagents in parallel. Each receives a short task prompt with:
deps above)src_dirs above)~/.claude/skills/refactorlib-cc/references/guardrails.md~/.claude/skills/refactorlib-cc/references/report-format.mdAgent({ subagent_type: "refactorlib-infra", prompt: <task prompt> })
Agent({ subagent_type: "refactorlib-utility", prompt: <task prompt> })
The agents' system prompts (from their markdown definitions) provide the methodology. Their preloaded skills (effect-usage, bun) provide deep API knowledge with progressive disclosure.
Synthesize agent findings. For each candidate, classify:
| Verdict | Meaning |
|---|---|
| REPLACE | Clear duplication. Library equivalent exists, is proven compatible, and is installed. |
| INVESTIGATE | Likely replaceable but needs API verification or output comparison. |
| KEEP | Intentionally custom. See references/guardrails.md. |
For REPLACE and INVESTIGATE candidates, perform these verification steps:
grep -r for imports to gauge blast radiusnode_modules/*/dist/dts/ for the
replacement API. An API that looks right in docs might not exist in the installed version.bun -e and compare output. This catches subtle differences in encoding,
formatting, or edge-case behavior.Only promote INVESTIGATE to REPLACE after step 4 confirms identical behavior.
Produce the final report using this template:
## Library Replacement Audit
### Dependencies scanned
- <dep>: <what it provides>
### Candidates
#### [REPLACE] <title>
- files: <paths with line ranges>
- callers: <N files import this>
- current: <what the code does, 1 line>
- replacement: <library API, 1 line>
- effort: low | medium | high
- gain: <lines removed, better edge-case handling, etc.>
- verified: yes | no
- code_before: |
<snippet>
- code_after: |
<snippet>
#### [INVESTIGATE] <title>
- files: <paths>
- current: <what the code does>
- candidate: <library API>
- blocker: <what needs verification>
#### [KEEP] <title>
- files: <paths>
- reason: <why this is intentionally custom>
### Summary
| Candidate | Verdict | Effort | Gain | Verified |
|-----------|---------|--------|------|----------|
See references/guardrails.md. Agents are directed to read this file during exploration.
| Question | Load |
|---|---|
| Effect infrastructure patterns? | references/patterns/effect-infra.md |
| Bun/Node infrastructure APIs? | references/patterns/runtime-infra.md |
| Bun/Node utility APIs? | references/patterns/runtime-utility.md |
| General utility patterns? | references/patterns/general-utility.md |
| False-positive guardrails? | references/guardrails.md |
| Infra subagent? | dot_claude/agents/refactorlib-infra.md |
| Utility subagent? | dot_claude/agents/refactorlib-utility.md |
| Agent report format? | references/report-format.md |