grepai-trace-graph
Skill20 starsChanged 34 days agoMITView on GitHub
Build complete call graphs with GrepAI trace. Use this skill for recursive dependency analysis.
In this repository26 other files it gives its agents.
- grepai-languagesSkill
- grepai-troubleshootingSkill
- grepai-workspacesSkill
- grepai-config-referenceSkill
- grepai-ignore-patternsSkill
- grepai-initSkill
- grepai-embeddings-lmstudioSkill
- grepai-embeddings-ollamaSkill
- grepai-embeddings-openaiSkill
- grepai-installationSkill
- grepai-ollama-setupSkill
- grepai-quickstartSkill
- grepai-chunkingSkill
- grepai-watch-daemonSkill
- grepai-mcp-claudeSkill
- grepai-mcp-cursorSkill
- grepai-mcp-toolsSkill
- grepai-search-advancedSkill
- grepai-search-basicsSkill
- grepai-search-boostingSkill
- grepai-search-tipsSkill
- grepai-storage-gobSkill
- grepai-storage-postgresSkill
- grepai-storage-qdrantSkill
- grepai-trace-calleesSkill
- grepai-trace-callersSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 396
Check if files are indexed
- Distinctive: line 397
Verify language is enabled
- Distinctive: line 403
Export for docs: Use JSON for generating diagrams
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GrepAI Trace Graph
This skill covers using grepai trace graph to build complete call graphs showing all dependencies recursively.
When to Use This Skill
- Mapping complete function dependencies
- Understanding complex code flows
- Impact analysis for major refactoring
- Visualizing application architecture
What is Trace Graph?
grepai trace graph builds a recursive dependency tree:
main
├── initialize
│ ├── loadConfig
│ │ └── parseYAML
│ └── connectDB
│ ├── createPool
│ └── ping
├── startServer
│ ├── registerRoutes
│ │ ├── authMiddleware
│ │ └── loggingMiddleware
│ └── listen
└── gracefulShutdown
└── closeDBBasic Usage
grepai trace graph "FunctionName"Example
grepai trace graph "main"Output:
🔍 Call Graph for "main"
main
├── initialize
│ ├── loadConfig
│ └── connectDB
├── startServer
│ ├── registerRoutes
│ └── listen
└── gracefulShutdown
└── closeDB
Nodes: 9
Max depth: 3Depth Control
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 5Depth Examples
--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
└── closeDBJSON Output
grepai trace graph "main" --depth 2 --jsonOutput:
{
"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
}
}Compact JSON
grepai trace graph "main" --depth 2 --json --compactOutput:
{
"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 Output (v0.26.0+)
TOON format offers ~50% fewer tokens than JSON:
grepai trace graph "main" --depth 2 --toonNote:
--jsonand--toonare mutually exclusive.
Extraction Mode
Symbols and calls are always extracted with regular expressions (the "fast" extractor used by grepai watch and grepai index); output reports "mode": "fast". The --mode flag is deprecated since grepai 1.0.0: it is still accepted for existing scripts, prints a deprecation warning and changes nothing. Do not pass --mode precise.
Use Cases
Understanding Application Flow
# Map entire application startup
grepai trace graph "main" --depth 4Impact Analysis
# What depends on this utility function?
grepai trace graph "validateInput" --depth 3
# Full impact of changing database layer
grepai trace graph "executeQuery" --depth 2Code Review
# Is this function too complex?
grepai trace graph "processOrder" --depth 5
# Many nodes = high complexityDocumentation
# Generate architecture diagram data
grepai trace graph "main" --depth 3 --json > architecture.jsonRefactoring Planning
# What would break if we change this?
grepai trace graph "legacyAuth" --depth 3Handling Cycles
GrepAI detects and marks circular dependencies:
main
├── processA
│ └── processB
│ └── processA [CYCLE]In JSON:
{
"name": "processA",
"cycle": true
}Large Graphs
For very large codebases, graphs can be overwhelming:
Limit Depth
# Start shallow
grepai trace graph "main" --depth 2Focus on Specific Areas
# Instead of main, trace specific subsystem
grepai trace graph "authMiddleware" --depth 3Filter in Post-Processing
# Get JSON and filter
grepai trace graph "main" --depth 3 --json | jq '...'Visualizing Graphs
Export to DOT Format (Graphviz)
# 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("}")
EOFThen render:
dot -Tpng graph.dot -o graph.pngMermaid Diagram
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("```")
EOFComparing Graph Sizes
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"What the Graph Contains
- Edges are real calls: property reads and writes are neither shown nor followed, and a declaration line is not an edge to itself.
- The root and same-name nodes are resolved deterministically (file path, then line), the same way in the CLI and in
grepai_trace_graph(MCP). - Pass a bare function name:
Class::methodis not supported.
Common Issues
❌ Problem: Graph too large / timeout ✅ Solutions:
- Reduce depth:
--depth 2 - Trace specific function instead of
main
❌ Problem: Many cycles detected ✅ Solution: This indicates circular dependencies in code. Consider refactoring.
❌ Problem: Missing branches ✅ Solutions:
- Check if files are indexed
- Verify language is enabled
Best Practices
- Start shallow: Begin with
--depth 2, increase as needed - Focus analysis: Trace specific functions, not always
main - Export for docs: Use JSON for generating diagrams
- Track over time: Monitor node count as complexity metric
- Investigate cycles: Circular dependencies are code smells
Output Format
Trace 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 depthDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

