callgraph: a static call-graph / code-map CLI for PHP codebases (who calls this, what does this method call), free and MIT
Disclosure: I'm the author. Free, MIT-licensed, open source, no account.
callgraph is a command-line tool that parses PHP (and also TS/Vue, Rust, Swift, Python, Go) and prints a compact map of a file or directory instead of the file itself: classes, methods with line ranges, and the calls each method makes, grouped by kind (same-class helper, framework/facade use, external call, instantiation, ...).
What I use it for on legacy PHP:
"Who calls this method?" A name pattern finds every call site with its source line, and
--depth Nfollows callers of callers for impact analysis before a change.Type-aware where it can be:
Type::methodmatches calls resolved to that type, including calls that go through an interface, parent class or trait (shown asvia <Type>). Calls whose receiver type is unknown are kept out of the default answer, counted, and available with--guess, marked?.Framework views for Laravel and Yii-style code: routes, middleware, validation, jobs, events/listeners, service providers and container bindings, magic methods.
A public-API view with DocBlock param/return shapes, and a layered profile of the project (controllers, services, repositories, models, ...) inferred from folder and file names and checked against the call graph.
One static binary (written in Rust, tree-sitter / a PHP parser underneath). It runs locally and uploads nothing. It was built so AI coding agents (Claude Code, MCP clients) can navigate a repo without reading whole files, but it's a plain CLI and works fine without any AI.
Limits, honestly: it's static analysis. Anything decided at runtime ($this->$method(), $class::$m(), app($name), config-built bindings, magic __call) cannot be resolved. That is the main limitation, and I'm working on marking those spots explicitly so the output doesn't look cleaner than the code really is.
I'd like feedback from people maintaining large PHP codebases: where does a static call graph mislead you most, and which framework-specific views would you want next (Symfony? WordPress hooks?)
2
u/joseph-edmondscomm 5d ago
surely this kind of system just becomes a stale source of truth and conflicts with the true picture that is shown in the code? Even LSPs can't generally keep up with code edits by agents, how can this kind of system keep up?
0
u/GeRiYx 4d ago
Fair concern. callgraph doesn't keep a long-lived model that drifts: every query checks each file's freshness (mtime, size and inode change time) and re-parses only what changed before answering, so the answer is built from the files as they are now. The MCP server also watches the project and refreshes edited files on its own, and for Claude Code there's an optional hook that refreshes a file right after Edit/Write. A file that doesn't parse mid-edit is still mapped up to and after the broken part, with a warning. It's not an LSP session, more like a fast, cached re-read.
2
u/TheRealSectimus 5d ago edited 5d ago
Ok for real, what is the difference between just using an interface? Can't an agent just run a fancy grep to find this info in well defined codebase?
0
u/GeRiYx 4d ago
In a small, well-structured codebase a good grep gets you far, agreed. The difference shows up on bigger ones: grep matches text, callgraph matches calls. `--grep 'Order::cancel'` lists only calls resolved to that type, including ones through an interface, parent or trait (marked "via <Type>"), with the caller's method, its line range and the call's line. `--depth 2` follows callers of callers. And the outline gives the agent "what's in this file and what each method calls" without reading the file, so it reads only the 20 lines it needs. Fewer round trips and less context, which is the whole point for agents.
1
u/DistanceAlert5706 4d ago
Was testing a lot callgraph and other methods sometime ago and got rid of all of them.
Current models don't use them, and don't need them.
Cool toy tho to check your app structure visually and maybe identify coupling.
For PHP building callgraph I extremely simple if you're using PHPStan, it's few classes extension.
1
u/GeRiYx 4d ago
Thanks, that's a fair take, and current models are good with grep. I see it as a cost/round-trip thing rather than "can't do without": an outline plus a targeted 20-line read instead of opening whole files. Good point on PHPStan: with a working autoload it gives a more precise, type-aware graph for PHP. callgraph trades some of that precision for zero setup (no composer/autoload needed), speed, and one tool across PHP, TS/Vue, Rust, Swift, Python and Go. Curious what you used to compare them, if you're willing to share.
2
u/avg_php_dev 5d ago
You can't touch source code by yourself to use it? It looks like consequence. Just asking.
5
u/Beagon 5d ago
What makes it different from Codegraph? https://github.com/codegraph-ai/CodeGraph