with one click
find-dead-code
// Find unused functions, types, constants, imports, and unreachable code paths. Use when the user asks to find dead code, unused code, cleanup candidates, or wants to reduce codebase size.
// Find unused functions, types, constants, imports, and unreachable code paths. Use when the user asks to find dead code, unused code, cleanup candidates, or wants to reduce codebase size.
| name | find-dead-code |
| description | Find unused functions, types, constants, imports, and unreachable code paths. Use when the user asks to find dead code, unused code, cleanup candidates, or wants to reduce codebase size. |
| disable-model-invocation | true |
Detect unused Go code that can be safely removed.
controller/, api/, cmd/, cli/). Skip tests unless explicitly asked.Ask the user:
For branch mode:
git diff --name-only upstream/main -- 'controller/' 'api/' 'cmd/' 'cli/' | grep '\.go$' | grep -v '_test\.go$'
Check for unused code with the compiler:
go build ./... 2>&1 | grep "declared and not used"
go vet ./... 2>&1 | grep -E "(not used|never used)"
staticcheck detects unused code, including unexported functions, constants, and variables:
staticcheck -checks=U1000 ./...
U1000 reports unused code that is not exported and not referenced.
If Go 1.23+ is available:
go run golang.org/x/tools/cmd/deadcode@latest -filter <package-pattern>
This finds functions, types, and variables that are never called or referenced.
goimports -l <target>
Any file listed has unused imports. Review with:
goimports -d <file>
Common false positives in this codebase:
| Pattern | Why it's not dead |
|---|---|
Reconcile(ctx, req) implementations | Called by controller-runtime via interface |
SetupWithManager() functions | Called by manager setup code |
init() functions | Called automatically by Go runtime |
| Interface method implementations | Called through interface, not directly |
kubebuilder: marker functions | Used by code generation |
Constants/vars in constants.go | May be used in tests or future code |
Error constants matching Err* pattern | May be used in error wrapping |
For each finding, classify:
| Category | Criteria | Action |
|---|---|---|
| Remove | Clearly unused, no interface/reflection use | Safe to delete |
| Verify | Possibly used dynamically or via interface | Search for references before removing |
| False positive | Interface impl, reflection, kubebuilder marker | Skip |
For "Verify" findings, search for references:
rg "<function_or_type_name>" controller/ api/ cmd/ cli/
For each finding:
Summary: total findings, how many safe to remove, estimated cleanup size.
Find functions with high cyclomatic complexity, excessive length, or too many parameters. Use when the user asks to find complex code, complexity hotspots, refactoring candidates, or wants to improve code maintainability.
Find code duplication in the codebase. Supports two modes - scoped to current branch changes or a full codebase sweep. Use when the user asks to find duplicated code, copy-paste, repeated patterns, or wants to deduplicate before a PR.
Reviews Go code for idiomatic patterns, error handling, concurrency safety, and common mistakes. Use when reviewing .go files, checking error handling, goroutine usage, or interface design.
Reviews Go test code for proper table-driven tests, assertions, and coverage patterns. Use when reviewing *_test.go files.
Investigate CI/Prow job failures on a GitHub pull request. Use when the user pastes a PR URL and asks about CI failures, red checks, test failures, or wants to understand why a job failed.
Performs a strict clean rebase of a feature branch onto main with minimal conflict resolution and full validation. Use when the user asks to rebase carefully, avoid extra branches, avoid exploratory edits, and run go test and go vet until green.