When you suspect two parts of your code are connected but cannot see how, vg path shows the link. It finds the shortest path between two nodes in the call graph, so you can trace exactly how A reaches B.
What vg path answers
"How does this controller end up calling that database helper?" or "Is this utility really reachable from the API entry point?" vg path answers these by returning the shortest chain of calls connecting two nodes.
Prerequisites
Build the graph first:
vg build
Find a path
vg path
The output is the shortest connecting path from one endpoint to the other — the sequence of nodes that links them.
Why shortest path is useful
- It cuts through indirection: even if the connection passes through several layers, you see the most direct route.
- It confirms or refutes assumptions: if no path exists, the two nodes are not connected the way you thought.
- It is a great explanation tool in reviews and onboarding — a concrete chain beats a vague "they're related."
Choosing the endpoints
vg path needs two endpoints, A and B. You can target them explicitly with the pick flags:
vg path --pick-a --pick-b
This lets you select exactly which node is the start and which is the end of the path. See the companion article on picking endpoints for details.
When to reach for path vs. tree
- Use
vg pathwhen you have two specific nodes and want the connection between them. - Use
vg treewhen you want to explore everything reachable from a single node.
Related
See the articles on picking endpoints with --pick-a and --pick-b and on exploring the call tree with vg tree.