home / skills / shotaiuchi / dotclaude / refactor-dependency

refactor-dependency skill

/dotclaude/skills/refactor-dependency

This skill analyzes dependency graphs to aid refactoring by mapping import chains, call graphs, and coupling across modules.

npx playbooks add skill shotaiuchi/dotclaude --skill refactor-dependency

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.0 KB
---
name: refactor-dependency
description: >-
  Dependency mapping and analysis for refactoring. Apply when mapping
  import chains, call graphs, coupling relationships, circular dependencies,
  and hidden connections in target code.
user-invocable: false
---

# Dependency Mapper Analysis

Map all dependencies, import chains, call graphs, and coupling relationships for the refactoring target.

## Analysis Checklist

### Import Chain Analysis
- Trace all direct and transitive imports from the target code
- Identify shared dependencies across multiple modules
- Check for re-exports that create indirect coupling
- Map import depth to detect deeply nested dependency chains

### Call Graph Mapping
- Build function/method call graphs for the target scope
- Identify entry points and terminal nodes
- Detect callback chains and event-driven connections
- Map data flow through function parameters and return values

### Coupling Assessment
- Measure afferent coupling (who depends on this code)
- Measure efferent coupling (what this code depends on)
- Identify connascence types (name, type, meaning, position, algorithm)
- Check for hidden coupling through shared mutable state or globals

### Circular Dependency Detection
- Detect direct circular imports between modules
- Find indirect cycles through transitive dependencies
- Identify bidirectional data flow between layers
- Check for initialization-order dependencies that mask cycles

### Dependency Health Metrics
- Calculate instability ratio for each module in scope
- Identify modules that violate the stable dependencies principle
- Check for unnecessary dependencies that could be removed
- Assess dependency freshness and maintenance status

## Output Format

Report findings with impact ratings:

| Impact | Description |
|--------|-------------|
| Breaking | Dependency that will break if changed without coordination |
| High | Tightly coupled dependency requiring careful migration |
| Medium | Moderate coupling that should be addressed during refactoring |
| Low | Loose coupling, safe to change independently |

Overview

This skill performs dependency mapping and analysis focused on refactoring targets. It locates import chains, call graphs, coupling relationships, circular dependencies, and hidden connections to guide safe, incremental changes. The output highlights risks and impact ratings to prioritize remediation.

How this skill works

The skill statically inspects source files to trace direct and transitive imports, re-exports, and import depth. It builds call graphs to reveal entry points, terminal nodes, callback chains, and data flow through parameters and returns. Coupling metrics (afferent/efferent), connascence detection, and circular dependency discovery are calculated. Finally, it computes dependency health metrics and assigns impact ratings for each finding.

When to use it

  • Before a large refactor that touches module boundaries
  • When untangling tangled import or call relationships
  • To validate module stability prior to extracting or merging components
  • When diagnosing runtime initialization or load-order failures
  • During dependency reduction or third-party upgrade planning

Best practices

  • Scope analysis to a clear target set to avoid noise from unrelated modules
  • Run both import-chain and call-graph analyses to expose indirect coupling
  • Prioritize fixes by impact rating and instability ratio rather than line count
  • Look for connascence types and prefer breaking name/type coupling before behavioral coupling
  • Document breaking and high-impact dependencies for coordinating cross-team changes

Example use cases

  • Map transitive imports to reveal a hidden third-party transitive dependency that blocks upgrades
  • Identify a circular import chain between layers that causes test-order or initialization failures
  • Surface high-afferent-coupling modules that should be stabilized before splitting responsibilities
  • Locate shared mutable globals causing hidden coupling and propose safer interfaces
  • Produce a prioritized list of modules by instability ratio to guide incremental extraction work

FAQ

What languages does the analysis support?

The approach is language-agnostic; actual support depends on available parsers. For new languages, provide a parser or AST extractor.

How are impact ratings determined?

Impact ratings combine coupling metrics, call-graph centrality, instability ratios, and whether a dependency is transitive or re-exported; higher scores map to Breaking or High ratings.