Extract call graphs, function locations, specs, types, and struct definitions from compiled Elixir projects.
- Extracts function call relationships from BEAM files
- Indexes function locations with source file mappings
- Parses
@specand@typedefinitions - Extracts struct field information
- Detects macro-generated functions (e.g., from
use GenServer,defstruct) - Computes cyclomatic complexity for each function clause
- Supports regular and umbrella projects
- Filters by main app only or includes dependencies
- Outputs JSON or TOON (token-optimized) format for LLM consumption
- Elixir 1.18+ with OTP 27+
- Project must be compiled with debug info (default in dev)
Build the escript:
mix deps.get
mix escript.buildThis creates the ex_ast executable. Move it to a directory in your $PATH.
ex_ast [OPTIONS] [PATH]PATH- Path to Elixir project (default: current directory)
| Option | Alias | Description |
|---|---|---|
--output FILE |
-o |
Output file path (default: extracted_trace.<format>) |
--format FORMAT |
-F |
Output format: json or toon (default: json) |
--file BEAM_FILE |
-f |
Process specific BEAM file(s) instead of a project (repeatable) |
--git-diff REF |
-g |
Process only files changed in git diff (commit hash, branch, HEAD~1, --staged, etc.) |
--include-deps |
-d |
Include all dependencies in analysis |
--deps DEP1,DEP2 |
Include specific dependencies (comma-separated) | |
--env ENV |
-e |
Mix environment to use (default: dev) |
--help |
-h |
Show help message |
# Analyze current directory
ex_ast
# Analyze specific project
ex_ast /path/to/project
# Custom output file
ex_ast -o output.json
# Include all dependencies
ex_ast --include-deps
# Include specific dependencies
ex_ast --deps phoenix,ecto
# Use test environment
ex_ast -e test
# Analyze a single BEAM file
ex_ast -f path/to/Module.beam
# Analyze multiple BEAM files
ex_ast -f A.beam -f B.beam
# Analyze only files changed in last commit
ex_ast --git-diff HEAD~1
# Analyze files changed between branches
ex_ast --git-diff main..feature
# Analyze staged changes
ex_ast --git-diff --stagedThe tool produces a JSON file containing:
- calls - Function call relationships (caller → callee)
- function_locations - Function definitions with line numbers
- specs -
@specdefinitions with parsed clauses - types -
@typeand@opaquedefinitions - structs - Struct field definitions
See docs/OUTPUT_FORMAT.md for the complete output schema.
{
"generated_at": "2024-01-15T10:30:00Z",
"project_path": "/path/to/project",
"environment": "dev",
"extraction_metadata": {
"modules_processed": 50,
"total_calls": 1234,
"total_functions": 456
},
"calls": [...],
"function_locations": {...},
"specs": {...},
"types": {...},
"structs": {...}
}- Locates compiled BEAM files in
_build/<env>/lib/ - Reads debug info chunks from each BEAM file
- Extracts function definitions, calls, specs, types, and structs
- Filters calls to only include project modules (unless
--include-deps) - Outputs structured JSON or TOON
- Processes specified BEAM file(s) directly
- No project context required - useful for analyzing individual modules
- Extracts all available information without filtering
- Runs
git diffto identify changed source files - Maps changed
.exfiles to their corresponding BEAM files in_build/<env>/lib/ - Processes only the BEAM files for changed modules
- Requires BEAM files to already exist (run
mix compilefirst if needed) - Useful for incremental analysis of changes
The codebase follows established conventions for:
- Parameter naming and formatting
- Standard data structure definitions
- Type representation
See the conventions documentation for details:
- docs/conventions/PARAMETER_FORMATTING.md - Parameter naming and formatting standards
- docs/conventions/DATA_STRUCTURES.md - Standard data structure definitions
- CLAUDE.md - Development commands and code style guidelines
- docs/OUTPUT_FORMAT.md - Complete output format specification
# Run tests
mix test
# Format code
mix format
# Build escript
mix escript.build
# Run on self
./ex_ast .