بنقرة واحدة
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.
internal/, api/, cmd/). Skip tests unless explicitly asked.Ask the user:
For branch mode:
git diff --name-only upstream/main -- 'internal/' 'api/' 'cmd/' | 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>" internal/ api/ cmd/ test/
For each finding:
Summary: total findings, how many safe to remove, estimated cleanup size.
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.
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.
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 make test and make lint until green.
Review PR with structured approach covering architecture, naming, patterns, and critical questions
After a code change, find affected tests, update them to match new behavior, then guide the user to run validation. Use when the user has made or asked for a code change and wants to make sure nothing is broken.
Run the full validation pipeline (make test, make lint, optionally make test-e2e) and auto-fix trivial failures like formatting and import issues. Use when the user asks to validate, run tests, check the pipeline, or verify changes are clean.