Introduction
Keeping your Go code up to date with the latest language features and best practices can feel like a chore. But with the completely rewritten go fix subcommand introduced in Go 1.26, modernization becomes a breeze. This tool automatically detects and applies code improvements—whether it's replacing interface{} with any, converting old loop patterns, or switching to newer library functions. In this guide, you'll learn how to use go fix step by step, understand its capabilities, and integrate it into your routine. By the end, you'll be running go fix with confidence and keeping your codebase modern effortlessly.
What You Need
- Go 1.26 or later – The completely rewritten
go fixis only available from this version onward. Check withgo version. - A Go project – Any module with source files you want to update.
- Git (recommended) – To track changes and easily review what
go fixmodified. - A clean working tree – Start with no uncommitted changes so you can clearly see the effect of
go fix.
Step-by-Step Instructions
Step 1: Prepare Your Repository
Before running any fixing commands, ensure your project is in a clean state. Use git status to verify there are no modified or untracked files you care about. If you have pending changes, commit them or stash them temporarily. This way, the only changes in your next commit will be those made by go fix, making code review much simpler.
Step 2: Run go fix on Your Codebase
The most straightforward invocation is to fix all packages under the current directory. Open a terminal, navigate to your project root, and run:
go fix ./...
This command applies all relevant fixers (analyzers) to every .go file in the module. On success, go fix silently updates the source files. It automatically skips generated files (such as those with // Code generated comments) because changes should be made to the generator logic instead.
Step 3: Preview Changes Before Applying (Optional but Recommended)
If you want to see what go fix would change without actually modifying files, use the -diff flag:
go fix -diff ./...
This prints a unified diff of every proposed modification. For example, you might see:
--- dir/file.go (old)
+++ dir/file.go (new)
- eq := strings.IndexByte(pair, '=')
- result[pair[:eq]] = pair[1+eq:]
+ before, after, _ := strings.Cut(pair, "=")
+ result[before] = after
Reviewing the diff helps you understand which fixes will be applied and catch any surprises before committing.
Step 4: List All Available Fixers
Curious about what kinds of improvements go fix can make? Run this command to see the full list of analyzers:
go tool fix help
The output includes entries like:
any– replaceinterface{}withanybuildtag– check//go:buildand// +builddirectivesfmtappendf– replace[]byte(fmt.Sprintf)withfmt.Appendfforvar– remove redundant re‑declaration of loop variableshostport– check format of addresses passed tonet.Dialinline– apply fixes based on//go:fix inlinecomment directivesmapsloop– replace explicit loops over maps with calls tomapspackageminmax– replaceif/elsestatements with calls tominormax
Step 5: Get Detailed Help for a Specific Fixer
To understand what a particular analyzer does, add its name to the help command. For example:

go tool fix help forvar
This shows documentation explaining the problem it solves and when it was introduced.
Step 6: Run Only Specific Fixers (Advanced)
If you want to apply only certain improvements, you can pass the -fix flag followed by a comma‑separated list of analyzer names. For instance, to run only the any and mapsloop fixers:
go fix -fix=any,mapsloop ./...
This is helpful if you want to phase upgrades gradually or if a particular fixer might need additional review.
Step 7: Commit and Review the Changes
After running go fix (with or without -diff), examine the modified files. Use git diff for a detailed view or git add -p to stage changes interactively. Once satisfied, commit with a meaningful message, for example: “all: run go fix to modernize code for Go 1.26”. Your reviewers will appreciate that the diff contains only go fix edits.
Tips for Success
- Run after every Go toolchain update – Each new version may introduce additional fixers. Make it a habit to run
go fix ./...right after you upgrade. - Always start from a clean git state – This isolates the auto‑generated changes, making code review a breeze.
- Use
-difffirst – Preview the changes before committing, especially when trying a new fixer for the first time. - Understand the “self‑service” nature – Module maintainers can create custom analyzers using the same infrastructure. Check the
go/analysispackage to write your own. - Don’t ignore generated files –
go fixskips them intentionally. If you see a potential fix in a generated file, update the generator code instead. - Pair with
go vet– Whilego fixapplies changes,go vetreports potential issues without modifying code. Use both regularly.
By following these steps, you can keep your Go codebase lean, modern, and aligned with the latest best practices. The new go fix is more than just a migration tool—it’s a self‑service platform for continuous improvement.