with one click
grepai-trace-graph
// Build complete call graphs with GrepAI trace. Use this skill for recursive dependency analysis.
// Build complete call graphs with GrepAI trace. Use this skill for recursive dependency analysis.
Reference for all GrepAI MCP tools. Use this skill to understand available MCP tools and their parameters.
Advanced search options in GrepAI. Use this skill for JSON output, compact mode, and AI agent integration.
Find function callees with GrepAI trace. Use this skill to discover what functions a specific function calls.
Find function callers with GrepAI trace. Use this skill to discover what code calls a specific function.
Supported programming languages in GrepAI. Use this skill to understand which languages can be indexed and traced.
Troubleshooting guide for GrepAI. Use this skill to diagnose and fix common issues.
| name | grepai-trace-graph |
| description | Build complete call graphs with GrepAI trace. Use this skill for recursive dependency analysis. |
This skill covers using grepai trace graph to build complete call graphs showing all dependencies recursively.
grepai trace graph builds a recursive dependency tree:
main
āāā initialize
ā āāā loadConfig
ā ā āāā parseYAML
ā āāā connectDB
ā āāā createPool
ā āāā ping
āāā startServer
ā āāā registerRoutes
ā ā āāā authMiddleware
ā ā āāā loggingMiddleware
ā āāā listen
āāā gracefulShutdown
āāā closeDB
grepai trace graph "FunctionName"
grepai trace graph "main"
Output:
š Call Graph for "main"
main
āāā initialize
ā āāā loadConfig
ā āāā connectDB
āāā startServer
ā āāā registerRoutes
ā āāā listen
āāā gracefulShutdown
āāā closeDB
Nodes: 9
Max depth: 3
Limit recursion depth with --depth:
# Default depth (2 levels)
grepai trace graph "main"
# Deeper analysis (3 levels)
grepai trace graph "main" --depth 3
# Shallow (1 level, same as callees)
grepai trace graph "main" --depth 1
# Very deep (5 levels)
grepai trace graph "main" --depth 5
--depth 1 (same as callees):
main
āāā initialize
āāā startServer
āāā gracefulShutdown
--depth 2 (default):
main
āāā initialize
ā āāā loadConfig
ā āāā connectDB
āāā startServer
ā āāā registerRoutes
ā āāā listen
āāā gracefulShutdown
āāā closeDB
--depth 3:
main
āāā initialize
ā āāā loadConfig
ā ā āāā parseYAML
ā āāā connectDB
ā āāā createPool
ā āāā ping
āāā startServer
ā āāā registerRoutes
ā ā āāā authMiddleware
ā ā āāā loggingMiddleware
ā āāā listen
āāā gracefulShutdown
āāā closeDB
grepai trace graph "main" --depth 2 --json
Output:
{
"query": "main",
"mode": "graph",
"depth": 2,
"root": {
"name": "main",
"file": "cmd/main.go",
"line": 10,
"children": [
{
"name": "initialize",
"file": "cmd/main.go",
"line": 15,
"children": [
{
"name": "loadConfig",
"file": "config/config.go",
"line": 20,
"children": []
},
{
"name": "connectDB",
"file": "db/db.go",
"line": 30,
"children": []
}
]
},
{
"name": "startServer",
"file": "server/server.go",
"line": 25,
"children": [
{
"name": "registerRoutes",
"file": "server/routes.go",
"line": 10,
"children": []
}
]
}
]
},
"stats": {
"nodes": 6,
"max_depth": 2
}
}
grepai trace graph "main" --depth 2 --json --compact
Output:
{
"q": "main",
"d": 2,
"r": {
"n": "main",
"c": [
{"n": "initialize", "c": [{"n": "loadConfig"}, {"n": "connectDB"}]},
{"n": "startServer", "c": [{"n": "registerRoutes"}]}
]
},
"s": {"nodes": 6, "depth": 2}
}
TOON format offers ~50% fewer tokens than JSON:
grepai trace graph "main" --depth 2 --toon
Note:
--jsonand--toonare mutually exclusive.
# Fast mode (regex-based)
grepai trace graph "main" --mode fast
# Precise mode (tree-sitter AST)
grepai trace graph "main" --mode precise
# Map entire application startup
grepai trace graph "main" --depth 4
# What depends on this utility function?
grepai trace graph "validateInput" --depth 3
# Full impact of changing database layer
grepai trace graph "executeQuery" --depth 2
# Is this function too complex?
grepai trace graph "processOrder" --depth 5
# Many nodes = high complexity
# Generate architecture diagram data
grepai trace graph "main" --depth 3 --json > architecture.json
# What would break if we change this?
grepai trace graph "legacyAuth" --depth 3
GrepAI detects and marks circular dependencies:
main
āāā processA
ā āāā processB
ā āāā processA [CYCLE]
In JSON:
{
"name": "processA",
"cycle": true
}
For very large codebases, graphs can be overwhelming:
# Start shallow
grepai trace graph "main" --depth 2
# Instead of main, trace specific subsystem
grepai trace graph "authMiddleware" --depth 3
# Get JSON and filter
grepai trace graph "main" --depth 3 --json | jq '...'
# Convert JSON to DOT
grepai trace graph "main" --depth 3 --json | python3 << 'EOF'
import json
import sys
data = json.load(sys.stdin)
print("digraph G {")
print(" rankdir=TB;")
def traverse(node, parent=None):
name = node.get('name') or node.get('n')
if parent:
print(f' "{parent}" -> "{name}";')
children = node.get('children') or node.get('c') or []
for child in children:
traverse(child, name)
traverse(data.get('root') or data.get('r'))
print("}")
EOF
Then render:
dot -Tpng graph.dot -o graph.png
grepai trace graph "main" --depth 2 --json | python3 << 'EOF'
import json
import sys
data = json.load(sys.stdin)
print("```mermaid")
print("graph TD")
def traverse(node, parent=None):
name = node.get('name') or node.get('n')
if parent:
print(f" {parent} --> {name}")
children = node.get('children') or node.get('c') or []
for child in children:
traverse(child, name)
traverse(data.get('root') or data.get('r'))
print("```")
EOF
Track complexity over time:
# Get node count
grepai trace graph "main" --depth 3 --json | jq '.stats.nodes'
# Compare before/after refactoring
echo "Before: $(grepai trace graph 'main' --depth 3 --json | jq '.stats.nodes') nodes"
# ... refactoring ...
echo "After: $(grepai trace graph 'main' --depth 3 --json | jq '.stats.nodes') nodes"
ā Problem: Graph too large / timeout ā Solutions:
--depth 2main--mode fastā Problem: Many cycles detected ā Solution: This indicates circular dependencies in code. Consider refactoring.
ā Problem: Missing branches ā Solutions:
--mode precise--depth 2, increase as neededmainTrace graph result:
š Call Graph for "main"
Depth: 3
Mode: fast
main
āāā initialize
ā āāā loadConfig
ā ā āāā parseYAML
ā āāā connectDB
ā āāā createPool
ā āāā ping
āāā startServer
ā āāā registerRoutes
ā ā āāā authMiddleware
ā ā āāā loggingMiddleware
ā āāā listen
āāā gracefulShutdown
āāā closeDB
Statistics:
- Total nodes: 12
- Maximum depth reached: 3
- Cycles detected: 0
Tip: Use --json for machine-readable output
Use --depth N to control recursion depth