golang-dead-code

Detect and remove dead code from Go projects with build verification.

Updated Aug 9, 2022
One-click install
npx skills add https://github.com/BizShuk/gosdk --skill golang-dead-code
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-dead-code
Source: https://github.com/BizShuk/gosdk/tree/main/skills/golang-dead-code
Command: npx skills add https://github.com/BizShuk/gosdk --skill golang-dead-code

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Go projects accumulate unused functions, variables, types, unreachable code branches, dead stores, and deprecated API calls over time, increasing maintenance burden, binary size, and technical debt. Manually identifying and removing this dead code is error-prone and risks breaking existing functionality.

Core Features & Use Cases

  • 4-Phase Safe Workflow: Follows a strict Detect → Classify → Apply → Verify process that requires user confirmation before any deletion, and runs build/test checks after each batch of changes to catch breakages early.
  • Comprehensive Dead Code Detection: Identifies 4 categories of dead code: unused symbols (via staticcheck), unreachable code/dead stores (via go vet and staticcheck), module-level unreachable code (via deadcode), and deprecated APIs (via grep for deprecation markers).
  • Risk Classification: Automatically categorizes candidates into Safe, Deprecated-in-use, and Risky buckets to avoid removing exported public APIs, code used via reflection/plugins, or code with hidden callers.
  • Use Case: For a Go microservice codebase, use this skill to safely remove unused internal helper functions and deprecated API calls without breaking existing functionality or public interfaces.

Quick Start

Use the golang-dead-code skill to scan the current Go project for all unused code and deprecated APIs, then guide me through safely removing the confirmed low-risk candidates.

Frequently Asked Questions about golang-dead-code

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I detect and remove dead code in a Go project without breaking existing functionality?

To detect and remove dead code safely in a Go project, use a 4-phase workflow: Detect, Classify, Apply, and Verify. This process requires user confirmation before deleting unused symbols and runs build and test checks after each modification to prevent breaking changes.

Can staticcheck and go vet find unreachable code and dead stores in Go?

Yes, staticcheck and go vet are used to find unreachable code and dead stores in Go. The detection process combines these tools with deadcode for module-level unreachable code and grep for deprecated API markers to comprehensively identify candidates for removal.

What is the best way to clean up deprecated API usage and unused functions in a Go microservice?

The best way to clean up deprecated APIs and unused functions in a Go microservice is to scan the codebase and categorize candidates into Safe, Deprecated-in-use, and Risky buckets. This prevents the accidental removal of exported public APIs and code invoked through plugins.

Does removing unused Go code affect public interfaces or code called via reflection?

Removing unused Go code does not affect public interfaces or reflection calls when applying a risk classification workflow. The system automatically categorizes deletion candidates into Safe, Deprecated-in-use, and Risky buckets to avoid removing exported APIs or code with hidden callers.