You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Find unused functions, classes, variables, imports, and unreachable code with confidence scoring across your repository.
4
+
5
+
## Overview
6
+
7
+
The Undertaker is a reliable dead code detection agent that identifies unused code elements using static analysis. It provides deterministic confidence-based scoring to help you safely remove dead code while minimizing false positives.
The agent uses ripgrep for efficient cross-repository searching with language-specific patterns. It filters out comments and strings to minimize false positives and deduplicates results for accuracy.
139
+
140
+
## Limitations
141
+
142
+
- Static analysis only - cannot detect runtime dead code
143
+
- May have false negatives if code is referenced dynamically
144
+
- External library references may be missed if not directly imported in source files
145
+
- Consider running multiple times with different `min_confidence` values for comprehensive analysis
146
+
147
+
## Examples
148
+
149
+
### Example 1: Basic Analysis
150
+
151
+
```bash
152
+
qodo undertaker
153
+
```
154
+
155
+
Scans the repository and returns all dead code with confidence >= 70%.
156
+
157
+
### Example 2: High Confidence Only
158
+
159
+
```bash
160
+
qodo undertaker --min_confidence=90
161
+
```
162
+
163
+
Returns only the most reliable dead code detections (90-100% confidence).
164
+
165
+
### Example 3: Including Tests
166
+
167
+
```bash
168
+
qodo undertaker --include_tests=true
169
+
```
170
+
171
+
Includes test files in the analysis, which is useful for identifying unused test helpers or fixtures.
172
+
173
+
## Integration
174
+
175
+
The JSON output can be easily integrated into:
176
+
- CI/CD pipelines for automated reporting
177
+
- Code review tools
178
+
- Custom analysis scripts
179
+
180
+
## Best Practices
181
+
182
+
1. Start with the default `min_confidence=70` threshold
183
+
2. Review "Very High" confidence items first as candidates for removal
184
+
3. Use version control to safely remove dead code in isolated commits
185
+
4. Run the agent periodically to maintain code quality
186
+
187
+
## Support
188
+
189
+
For issues or questions about the Undertaker agent, please refer to the project documentation or create an issue in the repository.
description = "Reliable dead code detection agent that identifies unused functions, classes, variables, imports, and unreachable code with confidence scoring"
6
+
7
+
instructions = """
8
+
You are a dead code detection agent. Find unused code elements in the repository using static analysis.
Provide confidence scoring based on reference counts and export status.
13
+
Be reliable and dependable within reasonable limits.
14
+
Output clean JSON results for integration.
15
+
16
+
ANALYSIS PROCESS:
17
+
1. Project Discovery: Scan source files matching file_extensions, excluding generated/vendor folders. Use the filesystem tool for comprehensive directory traversal and file identification. Consider analyzing multiple source directories and files when available for more thorough coverage.
18
+
2. Definition Detection: Find function/class/variable/import definitions using language-specific patterns. Use ripgrep for efficient pattern matching across multiple files. Look for definitions across various file types (utils, services, models, routes, etc.).
19
+
3. Reference Counting: For each identifier, count actual usage across the codebase (excluding its definition). Use ripgrep with precise patterns to count references and exclude false positives.
20
+
4. Export Analysis: Detect if code is exported/public, which affects confidence scoring.
21
+
5. Unreachable Code: Find code after return/throw/break statements in the same block.
22
+
6. Confidence Scoring: Apply deterministic confidence rules based on usage patterns.
23
+
24
+
CONFIDENCE RULES:
25
+
No references + not exported = 100% confidence (very_high: 90-100).
26
+
No references + exported = 90% confidence (very_high: 90-100).
27
+
1 reference + not exported = 75% confidence (high: 70-89).
0 commit comments