| name | codenav-navigation |
| description | Use codenav CLI tool for efficient code navigation to explore function dependencies, call graphs, and code relationships. CRITICAL for token efficiency - always use codenav BEFORE grep/read when navigating codebases. Use when tracing function calls, finding dependencies, understanding architecture, or locating code patterns. |
Efficient Code Navigation with Codenav
CRITICAL: Always use codenav for navigation BEFORE using grep or read to save thousands of tokens.
This skill teaches efficient codebase exploration using the codenav CLI tool. Codenav builds indexed call graphs that let you navigate code relationships without reading files.
Token Efficiency Rules
✅ ALWAYS Use Codenav First For:
- Finding functions/symbols in the codebase
- Tracing function dependencies (what does this call?)
- Finding callers (who calls this function?)
- Understanding call paths between functions
- Exploring code architecture and relationships
- Locating functions by package or file pattern
⚠️ Use Grep ONLY For:
- Finding files containing specific text/strings
- Locating hardcoded values or constants
- Finding configuration values
- Searching for comments or documentation
⚠️ Use Read ONLY For:
- Reading specific files identified by codenav or grep
- Understanding implementation details AFTER finding the right file
- Viewing actual source code content
Core Codenav Commands
1. Query Functions/Symbols
codenav query --graph /tmp/codebase.bin --name "*pattern*" --output table
codenav query --graph /tmp/codebase.bin --name "*auth*" --type function --output table --limit 20
codenav query --graph /tmp/codebase.bin --package "api" --output table --limit 30
codenav query --graph /tmp/codebase.bin --name "functionName" --output json
codenav query --graph /tmp/codebase.bin --count
2. Find Callers (Who Calls This?)
codenav callers --graph /tmp/codebase.bin functionName --show-lines --output tree
codenav callers --graph /tmp/codebase.bin functionName --count
3. Trace Dependencies (What Does This Call?)
codenav trace --graph /tmp/codebase.bin --from "functionName" --depth 2 --show-lines
codenav trace --graph /tmp/codebase.bin --from "functionName" --depth 3 --output tree
4. Find Call Paths
codenav path --graph /tmp/codebase.bin --from "startFunc" --to "endFunc"
codenav path --graph /tmp/codebase.bin --from "startFunc" --to "endFunc" --limit 5
5. Analyze Code
codenav analyze --graph /tmp/codebase.bin complexity --limit 20
codenav analyze --graph /tmp/codebase.bin circular
codenav analyze --graph /tmp/codebase.bin hotspots --limit 10
Efficient Workflow Pattern
When investigating code (e.g., finding where data comes from):
Phase 1: Navigate with Codenav (REQUIRED FIRST STEP)
codenav query --graph INDEX --name "*dataHandler*" --output table
codenav callers --graph INDEX dataHandler --show-lines
codenav callers --graph INDEX parentFunction --show-lines
codenav trace --graph INDEX --from "entryPoint" --depth 3
Phase 2: Identify Specific Content (When Needed)
Grep pattern: "specific.text.pattern"
output_mode: files_with_matches
Phase 3: Read Identified Files (Final Step)
Read file_path: /path/identified/by/codenav/file.ts
Real Example: Finding Data Source
Task: Find where a specific data field originates.
WRONG Approach (Wastes Tokens):
grep -r "dataField" . | head -100
read file1.ts
read file2.ts
read file3.ts
CORRECT Approach (Saves Tokens):
codenav query --graph /tmp/codebase.bin --name "*data*" --output table
codenav callers --graph /tmp/codebase.bin dataHandler --show-lines
codenav callers --graph /tmp/codebase.bin processData --show-lines
codenav query --graph /tmp/codebase.bin --name "dataHandler" --output json
Grep pattern: "dataField"
output_mode: files_with_matches
Read file_path: /path/to/constants.ts
Read file_path: /path/to/dataHandler.ts
Token Savings: ~80% reduction by using codenav to navigate before reading.
Common Patterns
Pattern 1: Understanding a Feature
codenav query --graph INDEX --name "*feature*" --output table
codenav trace --graph INDEX --from "mainFeatureFunction" --depth 2
codenav callers --graph INDEX mainFeatureFunction
Pattern 2: Finding API Data Source
codenav query --graph INDEX --name "*Component*" --type function
codenav callers --graph INDEX useDataHook
codenav trace --graph INDEX --from "useDataHook" --depth 3
Read file_path: /identified/api/endpoint.ts
Pattern 3: Understanding Error Flow
codenav query --graph INDEX --name "*error*" --type function
codenav callers --graph INDEX errorHandler --show-lines
codenav path --graph INDEX --from "errorSource" --to "errorHandler"
Codenav Limitations (When to Use Grep/Read)
Codenav CANNOT determine:
- GraphQL query documents (use grep to find
.gql or `gql``)
- API endpoint URLs (use grep for
fetch( or axios()
- CMS queries (use grep for
contentful, strapi, etc.)
- Hardcoded constants (use grep for specific values)
- Configuration values (use grep in config files)
- Comments and documentation (use grep)
For these cases: Use grep to find files, then read to inspect.
Advanced Tips
List Available Packages
codenav query --graph INDEX --output json --limit 50 | jq -r '.[].package' | sort -u
Find Functions in Specific File
codenav query --graph INDEX --file "*targetFile.ts" --output table
Extract Subgraph
codenav extract --graph INDEX --from "rootFunction" --depth 2 --output /tmp/subgraph.bin
Export for Visualization
codenav export --graph INDEX --output graph.dot --format dot
Quick Reference Table
| Task | Tool | Command |
|---|
| Find function | codenav | query --name "pattern" |
| Who calls this? | codenav | callers functionName |
| What does this call? | codenav | trace --from "func" |
| Call path A→B | codenav | path --from A --to B |
| Find text in files | grep | pattern: "text" |
| Read file content | read | file_path: /path |
| Function details | codenav | query --name "func" --output json |
| Package functions | codenav | query --package "pkg" |
Workflow Summary for $ARGUMENTS
If investigating "$ARGUMENTS":
- Start:
codenav query --graph INDEX --name "*$ARGUMENTS*" --output table
- Trace Back:
codenav callers --graph INDEX relevantFunction --show-lines
- Trace Forward:
codenav trace --graph INDEX --from "relevantFunction" --depth 2
- Find Text (if needed):
Grep pattern: "$ARGUMENTS"
- Read Files (last resort): Only read files identified by steps 1-4
Remember
🎯 Codenav = Navigation (call graphs, dependencies, architecture)
🔍 Grep = Finding (text, strings, constants)
📖 Read = Content (implementation details)
Always navigate with codenav first, search with grep second, read last.
This order saves thousands of tokens and provides better context faster.