Scan codebase to identify opportunities to replace custom implementations with well-maintained open source libraries. Creates worktree, implements changes, and submits PR for review. Multi-phase workflow with parallel analysis agents.
Scans your codebase for custom implementations that could be replaced with well-maintained libraries. When you request a scan, it analyzes patterns, researches library options, and presents cost-benefit reports. If you approve an opportunity, it creates an isolated worktree, implements the refactoring with tests, and submits a PR for review.
/plugin marketplace add samjhecht/wrangler/plugin install wrangler@samjhecht-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
You are the dependency opportunity scanner workflow coordinator. Your job is to identify code that could be simplified by adopting existing libraries, implement the refactoring in an isolated worktree, and submit a PR for human review.
MANDATORY: When using this skill, announce it at the start with:
š§ Using Skill: dependency-opportunity-scanner | [brief purpose based on context]
Example:
š§ Using Skill: dependency-opportunity-scanner | [Provide context-specific example of what you're doing]
This creates an audit trail showing which skills were applied during the session.
This is a workflow skill coordinating multiple phases with parallel analysis.
Purpose: Identify patterns and custom implementations that might be library candidates.
Launch three parallel analysis agents:
Task: Identify common patterns that libraries typically solve
Approach:
Task: Analyze current dependencies to understand preferences and avoid conflicts
Approach:
package.json (or equivalent dependency manifest)Task: Identify areas with technical debt or maintenance burden
Approach:
Output from Phase 1: Three agent reports consolidated into opportunity list
Purpose: For each identified opportunity, research best library options.
Approach:
(LOC removed + maintenance savings) / integration effortDecision Point: If no opportunities with benefit ratio > 2.0, abort workflow and report findings.
Purpose: Present findings to user and get approval to proceed.
Approach:
# Dependency Opportunity Report
## Summary
Found [N] opportunities to reduce custom code with libraries.
## Top Opportunities
### 1. Replace date formatting with date-fns
- **Custom code:** 342 lines across 8 files
- **Library:** date-fns (2.1M weekly downloads, actively maintained)
- **Bundle size impact:** +12KB minified
- **Integration effort:** ~2 hours
- **Benefit ratio:** 8.5x (high)
- **Files affected:** src/utils/dates.ts, src/formatters/*, tests/date.test.ts
**What we'd gain:**
- Remove 342 lines of custom date formatting
- Standardized, well-tested date operations
- Better timezone handling
- Reduce maintenance burden
**Trade-offs:**
- Adds 12KB to bundle
- New dependency to maintain
- Need to update 23 call sites
### 2. Replace HTTP client with axios
[Similar structure]
### 3. Replace validation logic with zod
[Similar structure]
## Recommendation
Proceed with opportunity #1 (date-fns) as proof of concept.
Use AskUserQuestion to get approval:
If user approves, continue to Phase 4
If user declines, end workflow with report saved
Output: Selected opportunity and user approval
Purpose: Implement the library integration in isolated worktree.
Approach:
Create worktree (use using-git-worktrees skill):
Branch name: refactor/adopt-[library-name]
Purpose: Replace custom [functionality] with [library]
Install library:
npm install [library-name]
# or yarn add, pnpm add, etc.
Implement refactoring (use test-driven-development skill):
Remove obsolete code:
Verify integration:
Document changes:
Output: Working implementation in worktree with all tests passing
Purpose: Create comprehensive PR for human review.
Approach:
## Replace custom [functionality] with [library-name]
### Summary
Replaces [N] lines of custom [functionality] implementation with the well-maintained [library-name] library.
### Motivation
Our custom implementation had several issues:
- [Issue 1 - e.g., incomplete timezone handling]
- [Issue 2 - e.g., maintenance burden]
- [Issue 3 - e.g., missing edge case handling]
Using [library-name] provides:
- [Benefit 1]
- [Benefit 2]
- [Benefit 3]
### Changes
- **Removed:** [N] lines of custom code
- `src/utils/[file].ts` (deleted)
- [other deleted files]
- **Updated:** [N] files to use [library-name]
- `src/[file1].ts`
- `src/[file2].ts`
- **Added:** [library-name] dependency (bundle size: +[X]KB)
### Impact Analysis
- **Bundle size:** +[X]KB minified (+[Y]% increase)
- **API changes:** [None | List breaking changes]
- **Test coverage:** [Maintained | Improved] ([N]% ā [N]%)
- **Performance:** [Neutral | Faster | Slower] ([details])
### Testing
- [x] All existing tests pass
- [x] Added tests for edge cases now handled by library
- [x] Manual testing completed
- [x] Bundle builds successfully
### Migration Guide
For developers:
1. Replace `import { customFn } from 'utils/custom'` with `import { libFn } from 'library'`
2. Update function calls: `customFn(args)` ā `libFn(args)`
3. See [link to migration guide] for full mapping
### Rollback Plan
If issues discovered:
1. Revert this PR
2. Redeploy previous version
3. No data migration needed (code-only change)
### Questions for Reviewers
- Does bundle size increase seem acceptable?
- Any concerns about the library choice?
- Should we add more tests for specific edge cases?
---
Generated with [Claude Code](https://claude.com/claude-code) via `dependency-opportunity-scanner` workflow
Co-Authored-By: Claude <noreply@anthropic.com>
Commit changes:
git add .
git commit -m "$(cat <<'EOF'
refactor: replace custom [functionality] with [library-name]
- Remove [N] lines of custom implementation
- Integrate [library-name] ([version])
- Update all [N] call sites
- Maintain test coverage at [X]%
- Bundle size impact: +[X]KB
Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
EOF
)"
Push to remote:
git push -u origin refactor/adopt-[library-name]
Create PR:
gh pr create \
--title "Replace custom [functionality] with [library-name]" \
--body "$(cat <<'EOF'
[Full PR description from above]
EOF
)"
Report PR URL to user
Output: PR created and URL provided for review
# Dependency Opportunity Scanner - Execution Report
## Phase 1: Analysis
**Duration:** [X] minutes
**Agents:**
- Pattern Detection: Found [N] patterns, [M] candidates
- Dependencies Review: [N] existing deps, [philosophy summary]
- Code Quality: [N] technical debt areas identified
**Top Patterns Found:**
1. [Pattern 1] - [LOC] lines, [complexity]
2. [Pattern 2] - [LOC] lines, [complexity]
3. [Pattern 3] - [LOC] lines, [complexity]
## Phase 2: Library Research
**Duration:** [X] minutes
**Opportunities Identified:** [N]
**Top 3 by Benefit Ratio:**
1. [Library 1] - Ratio: [X]x
2. [Library 2] - Ratio: [X]x
3. [Library 3] - Ratio: [X]x
## Phase 3: Selection
**User choice:** [Library selected]
**Rationale:** [Why this one]
## Phase 4: Implementation
**Duration:** [X] minutes
**Changes:**
- Files modified: [N]
- Lines removed: [N]
- Lines added: [N]
- Net LOC change: -[N] ([X]% reduction)
- Tests: [pass/fail status]
- Build: [success/fail]
## Phase 5: PR Creation
**PR URL:** [GitHub URL]
**Metrics:**
- Total workflow time: [X] minutes
- Code reduction: [N] lines ([X]%)
- Bundle size impact: +[X]KB ([Y]%)
- Test coverage: [before]% ā [after]%
## Recommendations
- [Recommendation 1]
- [Recommendation 2]
---
*Generated by dependency-opportunity-scanner workflow v1.0*
Workflow succeeds when:
ā Codebase analyzed and opportunities identified ā Best library options researched with cost/benefit analysis ā User approves selected opportunity ā Implementation completed in isolated worktree ā All tests pass with new library ā PR created with comprehensive description ā PR URL provided to user for review
Scenario: Analysis finds no beneficial opportunities
Response:
Scenario: Tests fail during implementation
Response:
Scenario: User rejects all opportunities
Response:
Opportunity Thresholds:
Library Selection Criteria:
User: "Scan for dependency opportunities"
Workflow:
User: "Scan for dependency opportunities"
Workflow:
User: "Scan for dependency opportunities"
Workflow:
To run Phase 1 agents in true parallel, launch all three in a single message:
Launching Phase 1 analysis with three parallel agents:
[Task tool - Agent A: Pattern Detection]
[Task tool - Agent B: Dependencies Review]
[Task tool - Agent C: Code Quality Analysis]
All agents running in parallel...
using-git-worktrees skill for isolationrefactor/adopt-[library-name]bundlephobia.com for estimatesSupport processing multiple opportunities in sequence:
1. Implement opportunity #1 ā PR #1
2. Implement opportunity #2 ā PR #2
3. Implement opportunity #3 ā PR #3
Allow user-defined rules:
preferences:
max_bundle_increase: 30KB
min_downloads: 50K/week
avoid_libraries: [moment, request]
prefer_ecosystems: [lodash, ramda]
Add performance testing phase:
Track dependency health over time:
Track these for continuous improvement:
Efficiency:
Accuracy:
Impact:
Quality:
Dependency Opportunity Scanner Workflow v1.0
Master defensive Bash programming techniques for production-grade scripts. Use when writing robust shell scripts, CI/CD pipelines, or system utilities requiring fault tolerance and safety.