Ask Claude to Map Your Dependency Graph and Find Tightly Coupled Modules
You can't see dependency problems by reading one file at a time. Claude traces every import, require, and use statement across the project and maps the relationships — showing you the shape of your codebase's dependencies.
"Map the dependency graph for this project — which modules import which,
where are the circular dependencies, and which files are imported by everything?"
Claude reads every file's imports, builds a mental model of the dependency tree, and reports what it finds:
# Claude might report:
# Hub modules (imported by 10+ files):
# - src/utils/helpers.ts (imported by 23 files)
# - src/services/auth.ts (imported by 15 files)
#
# Circular dependencies:
# - OrderService → ProductService → OrderService
# - UserController → AuthMiddleware → UserController
#
# Layer violations:
# - Controller imports directly from Repository (skipping Service layer)
# - Model imports from Controller (wrong direction)
You can focus on specific concerns:
# Find circular dependencies
"Find all circular dependency chains in the codebase"
# Identify God modules
"Which files are imported by the most other files? These are our
most critical dependencies — if they break, everything breaks."
# Check layer boundaries
"Do any controllers import directly from repositories, bypassing
the service layer? Find every layer violation."
# Analyze a specific module's dependencies
"Show me everything the OrderService depends on — direct and transitive.
How deep is the dependency tree?"
# Find isolated modules
"Which files have zero imports from the rest of the project?
These might be dead code or standalone utilities."
Use this before refactoring to understand what you're dealing with:
"I want to extract the payment module into a separate package.
What does it depend on and what depends on it?
Show me every connection I'd need to break."
Claude can output the results as a Mermaid diagram for visualization or as a structured list for action items.
You can't untangle what you can't see — let Claude map the dependency graph so you know where the knots are before you start pulling.
via Claude Code
Log in to leave a comment.
When a page takes five seconds to load or an API endpoint times out under load, tell Claude which route is slow and it traces the entire code path — controller, services, queries, loops — identifying N+1 queries, redundant computations, missing indexes, and cacheable operations, then fixes each bottleneck.
Flaky tests are maddening — they pass locally, fail in CI, pass again when you retry. Tell Claude to read the test, identify the source of non-determinism — timing issues, shared state, date dependencies, or order-dependent setup — and fix the root cause so the test is reliably green or reliably red.
When your app throws an error, don't just Google the message — paste the full stack trace into Claude Code. It reads the trace, opens the referenced files in your codebase, follows the call chain, and pinpoints the actual root cause instead of just explaining the symptom.