-
Notifications
You must be signed in to change notification settings - Fork 0
detect command
Arham-Qureshi edited this page Jul 21, 2026
·
1 revision
Detects circular dependencies in your dependency graph using DFS-based cycle detection.
codebase-vis detect
- Loads
graph.jsonfromcodebase-out/ - Runs DFS (depth-first search) on file-only nodes (skips entities and external packages)
- When a back-edge is found (a node reachable from itself in the current DFS path), it records a cycle
- Deduplicates cycles using canonical key rotation
- Caps output at 200 cycles (real codebases can have combinatorial explosions)
- Writes cycle details to
cycles.json
The same cycle can be detected starting from different nodes. For example, A→B→C→A and B→C→A→B are the same cycle. The algorithm handles this by:
- Rotating the cycle path so the alphabetically-minimum node is first
- Joining with
|to form a canonical key - Only recording cycles with unique canonical keys
Prints each detected cycle as a chain:
Cycle 1 (3 files):
src/utils/a.js
→ src/utils/b.js
→ src/utils/c.js
→ src/utils/a.js
Written to codebase-out/cycles.json with detailed data:
[
{
"id": "cycle-0",
"size": 3,
"files": ["src/utils/a.js", "src/utils/b.js", "src/utils/c.js"],
"edges": [
{ "source": "src/utils/a.js", "target": "src/utils/b.js" },
{ "source": "src/utils/b.js", "target": "src/utils/c.js" },
{ "source": "src/utils/c.js", "target": "src/utils/a.js" }
],
"label": "Cycle: src/utils/a.js → src/utils/b.js → src/utils/c.js"
}
]After running detect, open graph.html (via codebase-vis serve or directly) and click the cycle toggle button. Cyclic edges are highlighted in red, and non-cyclic nodes dim. Click individual cycles to zoom in.

| Flag | Description |
|---|---|
| (none) | No flags — just run codebase-vis detect
|
- Run
codebase-vis generatefirst —detectreads from the existinggraph.json - The 200-cycle cap prevents the command from overwhelming the terminal on deeply entangled codebases. The first 200 distinct cycles are reported.
- Entity nodes and external packages are excluded from cycle detection (they can't form meaningful cycles)
- Detected cycles are automatically visualized in
graph.htmlvia the cycle overlay feature