# Go refactoring

> Go refactoring is an open-source agent skill for developer tools. Guides an agent through behavior-preserving Go refactors, renames and package moves. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/eduardo-sl/go-agent-skills/tree/main/skills/(workflow)/go-refactoring
- **Repository:** https://github.com/eduardo-sl/go-agent-skills
- **GitHub stars:** 90
- **License:** MIT
- **Skill name:** go-refactoring
- **Collection:** https://github.com/eduardo-sl/go-agent-skills
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-02

## About

This skill gives a coding agent a disciplined procedure for restructuring Go code without changing what it does. Each change is treated as one small, compiler-checked step: the agent confirms the build and tests are green, applies a single transformation, re-runs build, tests and go vet, and then commits before moving on. It includes a risk table that sorts transformations from low to high risk and calls for developer sign-off before cross-package moves, exported API changes or deletions.

The workflow covers renames through gopls, extracting a type into a new package behind temporary aliases, breaking circular dependencies by moving shared types or inverting them through consumer-side interfaces, changing function signatures with a deprecation cycle, and replacing a subsystem with a strangler migration. It also lists what does not count as a refactor, such as bug fixes or changes to JSON tags, and includes a checklist to run before finishing.

The skill expects a Go project with the Go toolchain and git installed. gopls is optional and only needed for semantic renames. It uses shell commands and reads or edits files in the repository. A reference file on bulk rewrites with gofmt -r, go fix, eg and gopatch is loaded only when needed.

## When your agent uses it

> Safe refactoring workflow for Go: behavior-preserving steps, compiler-checked renames, extracting packages, breaking circular dependencies, and strangler migrations — always behind green tests. Use when: "refactor this", "rename across the codebase", "extract a package", "break this circular dependency", "split this god package", "migrate callers", "clean up without changing behavior". Not for: choosing the target architecture (go-architecture-review), adopting new language features (go-modernize), performance rewrites (go-performance-review).

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(workflow)/go-refactoring)
- [Asks for: Read, Edit, Write, Glob, Grep, Bash(go:*), Bash(gofmt:*), Bash(git:*)…](https://github.com/eduardo-sl/go-agent-skills/blob/HEAD/skills/(workflow)/go-refactoring/SKILL.md)
- [License: MIT](https://github.com/eduardo-sl/go-agent-skills/tree/HEAD/skills/(workflow)/go-refactoring)

## Features

- **Risk-graded transformation table:** Sorts refactoring steps into low, medium and high risk, with the checks each level requires before starting.
- **Compiler-checked package extraction:** Moves a type into a new package in small steps, using temporary aliases so every commit stays green.
- **Circular dependency escapes:** Offers three ordered ways to break an import cycle: extract a shared core, invert with an interface, or merge.
- **Safe signature changes:** Adds a new function form, deprecates the old one, and migrates callers batch by batch.
- **Strangler subsystem migration:** Stages the replacement of a large component behind a shared interface and a conformance test suite.
- **Commit and verification discipline:** Requires one transformation per commit, with build, tests and go vet run at every step.

## Good for

- Rename a widely used exported type across a Go codebase
- Extract a package out of a large god package
- Break a circular dependency between two Go packages
- Migrate callers from an old function signature to a new one
- Replace a legacy storage layer incrementally without a big-bang rewrite
- Clean up a Go module without changing its behavior

## Install

### Any agent

Download the skill folder from https://github.com/eduardo-sl/go-agent-skills and copy it into your agent's skills folder.

## FAQ

### What does the skill need to run?

It requires the Go toolchain and git. gopls is optional and is used for semantic renames.

### Does Go refactoring change code on its own?

It guides the agent through edits such as renames and package moves, and it asks for developer approval before high-risk steps like cross-package moves or exported API changes.

### When should Go refactoring not be used?

It is not for choosing a target architecture, adopting new language features, or performance rewrites. The skill points to other skills for those tasks.

### Does Go refactoring add tests?

When test coverage is missing around the target code, the workflow says to write characterization tests first, before any refactor.

### Does Go refactoring run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Go refactoring?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Go refactoring?

The closest alternatives to Go refactoring are Refactor, Go semantic tools, Refactor seams, Code simplification edho ferdian and Go modernize.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Refactor](https://ai-powered.com/skills/refactor): Refactor is an open-source agent skill for developer tools.
- [Go semantic tools](https://ai-powered.com/skills/go-semantic-tools): Go semantic tools is an open-source agent skill for developer tools.
- [Refactor seams](https://ai-powered.com/skills/refactor-seams): Refactor seams is an open-source agent skill for developer tools.
- [Code simplification edho ferdian](https://ai-powered.com/skills/code-simplification-edho-ferdian): Code simplification edho ferdian is an open-source agent skill for developer tools.
- [Go modernize](https://ai-powered.com/skills/go-modernize): Go modernize is an open-source agent skill for developer tools.
- [Rust refactor helper](https://ai-powered.com/skills/rust-refactor-helper): Rust refactor helper is an open-source agent skill for developer tools.
- [Go architecture review](https://ai-powered.com/skills/go-architecture-review): Go architecture review is an open-source agent skill for developer tools.
- [Go code review](https://ai-powered.com/skills/go-code-review): Go code review is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/go-refactoring
