First identify what is changing the file: the standalone goimports command or your editor’s gopls organize-imports action. Both remove imports they consider unreferenced. If the package is needed for initialization side effects, use a blank import; if its only use is temporarily commented out, disable automatic organization on save or run it manually until the code is restored.
Why an import disappears
The Go project’s goimports documentation says the command updates import lines by adding missing imports and removing unreferenced ones. It also formats code in the style of gofmt. An editor may instead—or also—run gopls’s source.organizeImports action when you save. The gopls transformation documentation says this action removes duplicate or unused imports, adds imports for undefined symbols, and sorts imports.
A common debugging case is that the import’s only use is commented out. The gopls documentation’s explanation gives this as a reason some developers prefer not to organize imports automatically.
Identify what is organizing imports
- Save a copy of the file, then note whether the import changes only when saving, when running a formatter, or after invoking an editor action.
- Check the editor’s Go formatter and save-time code actions. Look for standalone
goimports,goplsorganize imports, or both. - Run the configured tool directly against the file, if appropriate, to see whether it reproduces the change. For standalone
goimports, the documentation describes the-vflag for inspecting behavior. - Check which version the editor invokes. The package page reported
goimportsv0.51.0, published October 2, 2026; your editor may use a different installed version. The documentedgo install golang.org/x/tools/cmd/goimports@latestcommand installs the latest version, not a reproducible version pin.
Choose the fix that matches the import’s purpose
The file refers to a package symbol
Make sure the saved file contains a live reference to the package’s identifier. Check the spelling, any import alias, the package name, and the import path. A reference elsewhere in the package does not necessarily make this file’s import useful. If a tool inserts a different path, verify that the chosen package exports the name you need and inspect your module or workspace context.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
A 2017 Go issue report describes neighboring files influencing package selection in a particular GOPATH layout. It is a historical, environment-specific report—not evidence of a general current defect. Use it as a prompt to inspect context and tool versions, not as a diagnosis by itself.
The package is imported for initialization side effects
Use a blank import to make that purpose explicit:
import _ "example.com/driver"
This is appropriate when the package’s initialization side effect is the reason for importing it, rather than when you intend to refer to one of its names.
The only use is temporarily commented out
Either leave the reference active while debugging or stop automatic import organization until you restore the code. You can organize imports manually afterward.
You want to control organization manually in VS Code
The gopls documentation shows disabling the organize-imports save action for Go files with this setting:
{
"[go]": {
"editor.codeActionsOnSave": {
"source.organizeImports": false
}
}
}
Then invoke the editor’s Organize Imports action when you choose. Other editor clients have different settings: locate the configured save hook or code action instead of copying this VS Code setting blindly.
A standalone goimports hook is running
Change the formatter or save hook that invokes goimports; this is separate from disabling gopls’s organize-imports action. The goimports package documentation describes using the command in a gofmt-on-save hook. Its .goimportsignore setting controls directories scanned under GOPATH for import discovery; it is not a general option for retaining unused imports.
Rank #4
If you mean a tool dependency, manage it separately
An import in ordinary compiled source code is not a general mechanism for keeping a developer tool in a module’s dependency graph. For Go 1.24 and later, the Go documentation describes go get -tool ... for tool dependencies. For earlier Go versions, it documents an alternative using a blank import in a Go file excluded from the build with build constraints, then running the tool with go run and its full package path. See Managing dependencies: Tools. That approach is for tool dependency management, not for preserving an ordinary unused import in compiled source.
Quick Recap
Best Value
Use this quick decision check
- Named symbol: Confirm the current file has a live reference and the import path and alias are correct.
- Initialization side effect: Use a blank import.
- Temporary debugging: Keep the reference active or disable the save-time organize action until the code is restored.
- Manual control: Disable the relevant save hook and organize imports on demand; distinguish the editor’s gopls action from a standalone formatter.
- Tool dependency: Use Go’s tool-dependency mechanism appropriate to your Go version, rather than an ordinary source import.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problems

