| name | tldr-code-analysis |
| model | opus |
| description | 5-layer code analysis (AST, Call Graph, CFG, DFG, PDG) that yields 95% token savings over raw file reads. Use when: 'systematically understand an unfamiliar codebase', 'analyze code structure with minimal tokens', 'map call graphs and data flow', 'find dead code and architectural layers', 'trace variable definitions across files'. |
| category | continuous-learning |
| triggers | ["systematically understand an unfamiliar codebase","analyze code structure with minimal tokens","map call graphs and data flow","find dead code and architectural layers","trace variable definitions across files"] |
| tier | 1 |
| agents | ["primary"] |
| tool_dependencies | ["file_system"] |
| inputs | [{"name":"repo_path","type":"string","description":"Path to the repository or directory to analyze","required":true},{"name":"analysis_depth","type":"string","description":"Depth of analysis: 'overview' (L1-L2 only), 'deep' (L1-L4), or 'full' (all 5 layers including PDG)","required":false}] |
| outputs | [{"name":"analysis_report","type":"ref","format":"cas-ref","description":"Structured analysis report covering requested layers with token-efficient code summaries"}] |
TLDR Code Analysis
Purpose: Systematically analyze unfamiliar codebases using a 5-layer analysis stack that reduces token consumption by 95% compared to raw file reads, while surfacing architecture, call graphs, control flow, data flow, and program dependencies.
I. When to Use
- Onboarding to an unfamiliar codebase and need structural understanding fast
- Preparing for a refactor by mapping cross-file call graphs and data flow
- Hunting a bug that spans multiple files and need to trace variable definitions
- Auditing code quality: dead code detection, cyclomatic complexity, architectural layers
- Any codebase exploration where reading raw files would blow the context budget
II. The 5-Layer Stack
Layer 1: AST ~500 tokens Function signatures, imports, class outlines
Layer 2: Call Graph +440 tokens What calls what (cross-file edges)
Layer 3: CFG +110 tokens Cyclomatic complexity, branches, loops
Layer 4: DFG +130 tokens Variable definitions, reads, modifications
Layer 5: PDG +150 tokens Program dependencies, slicing
---------------------------------------------------------------------------
Total: ~1,200 tokens vs 23,000 raw = 95% savings
Depth Modes
| Mode | Layers | Token Budget | Best For |
|---|
| overview | L1-L2 | ~940 tokens | Quick orientation, "what does this repo do?" |
| deep | L1-L4 | ~1,180 tokens | Refactor prep, bug tracing |
| full | L1-L5 | ~1,330 tokens | Full program slicing, dependency analysis |
III. Workflow
Step 1: Structural Scan (Layer 1 - AST)
Extract file tree, function signatures, imports, and class outlines.
tldr tree [repo_path]
tldr structure [repo_path] --lang [detected_language]
tldr imports [key_file]
Produces a codemap: the skeleton of every file without reading bodies.
Step 2: Call Graph Construction (Layer 2)
Build cross-file call graph to understand what calls what.
tldr calls [repo_path]
tldr impact [function_name] [repo_path]
tldr importers [module_name] [repo_path]
This layer reveals the actual dependency structure that import lists alone miss.