clean-unused-code
Clean Unused Code
Overview
This skill provides workflows for finding and removing unused code in projects. It uses static analysis tools to identify unreachable functions and dead code.
When to Use
Use this skill when:
- Cleaning up dead code in a project
- Removing unreachable functions
- Optimizing codebase size
- Preparing for code review or release
Supported Languages
| Language | Tool | Install Command |
|---|---|---|
golang |
deadcode |
go install golang.org/x/tools/cmd/deadcode@latest |
Golang Projects
Prerequisites
Install the deadcode tool:
go install golang.org/x/tools/cmd/deadcode@latest
Step 1: Find Unused Code
Run deadcode from the project root:
deadcode ./...
For projects with test dependencies, include tests:
deadcode -test ./...
Step 2: Parse Output
The output format is:
<file>:<line>:<column>: unreachable func: <function_name>
Example output:
internal/utils/helper.go:45:1: unreachable func: unusedHelper
pkg/service/old.go:12:1: unreachable func: deprecatedMethod
Step 3: Review and Remove
For each unreachable function:
- Verify it is safe to remove (not called via reflection, not an interface implementation)
- Remove the function definition
- Remove any related imports that become unused
- Run
go build ./...to verify no build errors
Step 4: Clean Up Imports
After removing functions, clean up unused imports:
goimports -w .
Or use gopls organize imports functionality.
Caveats
[!WARNING]
deadcodemay not detect functions called via:
- Reflection (
reflect.ValueOf().MethodByName())- Interface implementations used through dependency injection
- CGo bindings
- Plugin systems
When to Skip Removal
Do NOT remove functions if:
- They implement an interface (even if not directly called)
- They are exported and part of a public API/library
- They are called via reflection
- They are test helpers used in
_test.gofiles (use-testflag)
Verification
After cleaning, verify the project:
# Build check
go build ./...
# Test check
go test ./...
# Run deadcode again to confirm
deadcode ./...
More from bizshuk/llm_plugin
character-profile-generator
This skill generates detailed virtual character profiles based on a standardized template. Use this skill when a user wants to create or refine a character for stories, roleplay, or virtual assistants. It guides the user through a clarifying dialogue to establish core personality, behavior, and background before generating the final profile.
25project-metadata
Project metadata update
21security scanner
Scan workspace for potential security risks including exposed passwords, API keys, tokens, and other sensitive data
20go-function-analysis
Analyze Go function lengths within a workspace and generate statistics (p50, p90, p99). Use when you need to audit function complexity, identify long functions, or generate code metrics for Go projects. Only analyzes files matching **/*.go within the current workspace, excluding dependencies.
18social-buisiness-explore
Explore niche markets, generate viral content ideas, write scripts, plan 30-day calendars, monetization, and automation.
7private network security scan
Run a private network security scan, diagnose all discovered hosts against 11 risk categories, and generate a security report within 60 minutes
6