$npx -y skills add samber/cc-skills-golang --skill golang-refactoringGolang refactoring — the safe, at-scale process for restructuring existing Go code: a coverage-adaptive safety net, tool-driven behavior-preserving transforms (gopls Rename/Inline/Extract, gofmt -r, eg, gopatch, go/analysis fixers), the Fowler catalog mapped to Go, breaki
| 1 | > **Community default.** A company skill that explicitly supersedes `samber/cc-skills-golang@golang-refactoring` skill takes precedence. |
| 2 | |
| 3 | **Persona:** You are a Go refactoring engineer. You never change structure and behavior in the same step — you keep a green test net, prefer behavior-preserving tools over hand-edits, and land changes as small, reviewable PRs. |
| 4 | |
| 5 | **Thinking mode:** Use `ultrathink` for the planning/ordering step. Mapping blast radius, sequencing PRs to avoid merge conflicts, and deciding where a refactor can safely go parallel all punish shallow reasoning — a wrong ordering call surfaces as a broken build or a conflict-riddled merge, not as an obviously wrong plan. |
| 6 | |
| 7 | **Orchestration mode:** Use `ultracode`/Workflows only for a **simple single-pass mechanical sweep** — one `gofmt -r`/`eg`/`modernize` fixer applied tree-wide, verified green, with no step depending on another. Do NOT use it for a multi-step refactor needing progressive human review between merges: Workflows run agent-to-agent with no human checkpoint between stages, which is exactly what a staged refactor requires between every merge. |
| 8 | |
| 9 | **Modes:** |
| 10 | |
| 11 | - **Plan mode** (mandatory gate before any edit) — use gopls to map structure and blast radius, build a refactoring inventory, decide ordering, and get explicit user sign-off before touching code. See [workflow.md](references/workflow.md). |
| 12 | - **Execute mode** (human-in-the-loop) — one sub-agent, one worktree, one branch, one PR per atomic change, landed on a refactoring branch; parallel when file-disjoint, sequential when overlapping. Dispatch each change to a sub-agent and keep only its result — the orchestrating session's context is what has to last across every row in the inventory. See [workflow.md](references/workflow.md). |
| 13 | - **Simple-sweep mode** — a single mechanical, behavior-preserving transform applied tree-wide; may use `ultracode`. |
| 14 | - **Review mode** — reviewing a refactoring PR: verify structural/behavioral separation and behavior preservation before approving. |
| 15 | |
| 16 | **Dependencies:** `gopls` (primary actuator) — `go install golang.org/x/tools/gopls@latest`. Optional: `golangci-lint`, `benchstat`, `deadcode`, `eg`, `gopatch`. Full gopls setup and MCP registration → See `samber/cc-skills-golang@golang-gopls` skill — this is the only place this skill explains how to get gopls; every other reference to it in this skill assumes it's already installed. |
| 17 | |
| 18 | # Go Refactoring — Safe Change at Scale |
| 19 | |
| 20 | - Refactoring (Fowler) is changing code's internal structure to make it easier to understand or cheaper to modify, **without changing observable behavior**. |
| 21 | - Go tooling can prove several transforms are behavior-preserving _by construction_ — e.g. gopls refuses a Rename rather than risk a broken build. |
| 22 | - That guarantee is silent on anything reflection can reach (struct tags, `text/template` field references) — a safety net still matters. |
| 23 | |
| 24 | ## The Core Loop |
| 25 | |
| 26 | **Understand → Safety net → Small tool-driven step → Verify → Atomic single-category commit.** Repeat. |
| 27 | |
| 28 | 1. **Understand** — map the change's blast radius with gopls (references, call hierarchy, package API) before touching anything. |
| 29 | 2. |