callgraph

Go call graph for AI agents

callgraph parses .go files with tree-sitter-go and shows your agent structs, interfaces, functions and methods with line ranges, signatures, and every call by category.

What callgraph extracts from Go

  • Every file gets a <file>.go module container with its package-level functions and constants; the comment above package is its doc, and the package name is shown as the namespace.
  • struct as a class: fields as properties, embedded types (Base, *Logger) as extends. interface with abstract methods and embedded interfaces or type sets.
  • Defined types (type Level int, type Handler func()) and aliases (type A = B). Generic types show their type parameters ([T any]).
  • Methods with receivers belong to the receiver type, pointer or not. If the type is declared in another file of the package, the methods of this file are grouped under an extension container.
  • Signatures with several return values: Find(id int): (*User, error) (--signatures, --format api). A capitalised name is public (exported), a lower-case one private.
  • Package-level const and var, imports (alias, blank _ and dot . included), the doc comment right above a declaration, string literals, and syntax errors with a warning.
  • Several init functions show as init@L<line>; a function literal is not a separate item, its calls belong to the outer function.

A file that imports Gin, Echo, Fiber, Chi, gorilla/mux, gRPC, GORM or cobra is marked with that framework. vendor and testdata are skipped by default; _test.go files count as tests in locate.

Call categories

CategoryWhen
internal_helpera function defined in the same file, or r.f() on the receiver for a method of the same file
instantiationa struct literal such as Repo{…} or &pkg.T{…}, or a conversion to a type of the same file
static_callType.Method() (method expression) on a type of the same file
native_gobuiltins, standard-library packages and common methods: make, fmt.Println, errors.New, Close, Lock…
external_callan imported non-stdlib package, an unknown receiver, an unknown method on the receiver
global_helperan unknown bare name, probably defined in another file of the same package

The calls behind go and defer are included like any other call.

Commands

CG=~/.claude/skills/callgraph/callgraph.sh
bash $CG --project myapp <path/to>/cart.go                  # outline: structs, interfaces, functions, calls
bash $CG --project myapp <path/to>/cart.go --signatures     # with the signature on each method line
bash $CG --project myapp <path/to>/cart.go::Add --body      # just that method, line-numbered
bash $CG --project myapp <path/to>/cart.go --format api     # the exported surface only

Output of the outline for a small file

FILE  shop/cart.go  NS:shop

module cart.go  L1-31
  constants (1):
    TaxRate = 0.27
  __module__()  L8-8
  helper(n int): int  L31-31

class Cart  L11-14
  properties (2):
    []string $Items
    int $total
  Add(item string, p Pricer): error  L21-29
    external_call     p.Price
    internal_helper   helper
    native_go         errors.New, fmt.Println

interface Pricer  L16-18
  Price(item string): (int, error)  L17-17 [abstract]

Who calls this Go function?

bash $CG --project myapp <folder> --grep '(^|::|\.|->)helper$'      # every call of the name
bash $CG --project myapp <folder> --grep '(^|::|\.|->)helper$' --depth 2

Go has no type resolution in callgraph, so search by name: the pattern finds every call of helper, whatever the receiver. Each match shows the call's own source line.

Limits

This is the first phase of Go support.

  • No type resolution: the receiver of r.repo.Find() stays r, an internal import is not resolved to a file, and the type parameters of a generic function are not shown in its signature.
  • Methods promoted from an embedded struct and interface implementations are not followed.
  • No framework views (Gin / Echo / Chi routes, gRPC services, cobra commands) and no --format flow branches yet; //go:build tags are not evaluated.
  • Declarations inside a function are not listed.