Safe refactoring workflow for Go: behavior-preserving steps, compiler-checked renames, extracting packages, breaking circular dependencies, and strangler migrations — always behind green tests.
Ships in go-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A refactor changes structure, never behavior. The definition of done is mechanical: same tests pass before and after every step, and every step is small enough to revert alone.
Detailed reference material, loaded on demand:
references/bulk-rewrites.md — gofmt -r, //go:fix inline, eg,
gopatch and custom analyzers, with the verification to run after.Read a reference file only when the summary below is not enough.
| Risk | Transformations | Before you start |
|---|---|---|
| Low | gopls rename, extract/inline variable, organize imports | Green build and tests |
| Medium | Extract function or method, inline a call across packages, add/remove a parameter | Tests that cover every changed call site |
| High | Move types across packages, split or merge packages, break cycles, change exported API | Full safety net, and the developer's sign-off |
Stop for the developer's approval before any cross-package move, exported API change, deletion, or change to code with no tests. Question the refactor itself when the code is stable and nothing planned touches it, when it is critical and untested, or when no concrete next change gets easier.
go build ./... && go test ./... must be green before
touching anything. If tests are missing around the target code,
write characterization tests FIRST — they pin current behavior,
even if that behavior looks wrong.go vet ./....refactor: commit; they must scrutinize a
mixed one.If step 3 fails and the fix isn't obvious in a minute, revert the step rather than debugging a half-applied transformation.
# Preferred: gopls (understands types, interfaces, embedding)
gopls rename -w internal/service/user.go:#offset newName
# Module path or package import path changes:
# update go.mod, then rewrite imports mechanically
find . -name '*.go' -exec sed -i 's|github.com/acme/old|github.com/acme/new|g' {} +
go build ./... # the compiler is the reviewer
After a rename, grep for the old name in struct tags, templates, SQL and
anything reflection reads — gopls guards compilation, not those. Renaming
a field silently desyncs it from its json/db tag.
Never rename an exported identifier of a published library without a
deprecation cycle: add the new name, mark the old one
// Deprecated: use NewName., delete in the next major version.
Moving code out of a god package, in compiler-checked steps:
gopls
or cut/paste), leaving everything else.type User = user.User (aliases, =, not definitions).This keeps every commit green with an arbitrarily large caller base.
Packages a → b and b → a won't compile; near-cycles show up as
god packages. Three escapes, in order of preference:
a and b actually depend on a
type — move it to a third package c that imports nothing.store calls back into service,
define the callback interface IN store (consumer side) and let
service implement it. The arrow flips at compile time.For exported functions with many callers:
// Step 1 — add the new form alongside the old
func (s *Service) ProcessCtx(ctx context.Context, id string) error { ... }
// Step 2 — old form delegates; mark deprecated
// Deprecated: use ProcessCtx.
func (s *Service) Process(id string) error {
return s.ProcessCtx(context.Background(), id)
}
// Step 3 — migrate callers batch by batch, building each batch
// Step 4 — delete the old form (same module) or keep until next major (library)
On Go 1.26+, add //go:fix inline above the deprecated wrapper and step 3
becomes go fix ./... — for your module now, and for every downstream
module when it next runs go fix.
Inside a single module, prefer atomic signature changes when the compiler can find every caller for you: change it, then chase the build errors — that's the compiler enumerating your TODO list.
Replacing a subsystem (old store, legacy client) too big for one PR:
When the same change lands at many sites, encode it once and let a tool
apply it: gofmt -r for syntactic expressions, //go:fix inline + go fix
for callers of your own APIs, eg for type-aware expression rewrites,
gopatch for statements and imports, a go/analysis fixer for migrations
you will run again. A tool's rewrite is reviewable and re-runnable; forty
hand edits are neither. Examples: references/bulk-rewrites.md.
refactor: commits contain no behavior changego build ./... proves it)go vet ./... and the full test suite pass at every commit, not just the lastWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
35 skills in this plugin
/git-commitStructured git commit messages following Conventional Commits format for Go projects. Generates well-scoped, atomic commits with clear descriptions. Use when committing changes, writing commit messages, preparing PRs, or reviewing commit history quality. Trigger examples: "commit these changes", "create commit", "commit message", "prepare PR", "squash commits". Not for: code review (go-code-review), changelog generation.
/go-api-designHTTP/REST API design for Go services: handlers, ServeMux routing, middleware, request validation, pagination, idempotency, health checks, error responses, and graceful shutdown. Use when designing APIs, writing HTTP handlers, implementing middleware, or structuring REST endpoints. Trigger examples: "design API", "REST endpoints", "HTTP handler", "middleware pattern", "graceful shutdown", "API versioning". Not for: gRPC services (go-grpc), spec-first OpenAPI work (go-openapi), general architecture (go-architecture-review), concurrency in handlers (go-concurrency-review).
/go-architecture-reviewReview Go project architecture: package structure, dependency direction, layering, separation of concerns, domain modeling, and module boundaries. Use when reviewing architecture, designing package layout, evaluating dependency graphs, or refactoring monoliths into modules. Trigger examples: "review architecture", "package structure", "project layout", "dependency direction", "clean architecture Go", "module boundaries". Not for: code-level style (go-coding-standards), endpoint design (go-api-design).
/go-binary-sizeReduce the size of compiled Go binaries and container images: linker flags, inlining budget, CGO and build tags, embedded assets, dependency weight, and measuring what actually costs bytes. Use when a binary or image is too large, when shrinking a CLI for distribution, or when auditing what a dependency adds to the build. Trigger examples: "binary is too big", "shrink the binary", "reduce image size", "strip symbols", "what is making my binary large", "ldflags -s -w". Not for: runtime speed and allocations (go-performance-review), CI setup (go-ci), release pipelines and signing (go-build-release), dependency CVEs (go-dependency-audit).
/go-build-releaseBuild and release Go binaries that are reproducible and verifiable: version stamping, -trimpath builds, cross-compilation, GoReleaser, checksums, SBOMs, cosign signing, build provenance attestations, and container images with ko or a multi-stage Dockerfile. Use when: "release a Go binary", "set up GoReleaser", "cross-compile", "reproducible build", "sign the release", "generate an SBOM", "build provenance", "publish a container image", "version command shows (devel)". Not for: test and lint pipelines (go-ci), shrinking the binary or image (go-binary-size), auditing dependencies (go-dependency-audit).
/go-ciContinuous integration for Go projects: GitHub Actions pipelines, caching, golangci-lint setup, test/coverage gates, vulnerability scanning, SAST (CodeQL, gosec), Dependabot, action pinning, build matrices, Makefile targets. Use when: "set up CI", "GitHub Actions for Go", "add lint to the pipeline", "CI is slow", "coverage gate", "build matrix", "write a Makefile", "run govulncheck in CI". Not for: commit conventions (git-commit), choosing or auditing dependencies (go-dependency-audit), writing the tests themselves (go-test-quality), releases and signing (go-build-release).
/go-agent-skills:go-refactoringfrom go-agent-skills
npx claudepluginhub eduardo-sl/go-agent-skills --plugin go-agent-skillsOther plugins' skills for the same job