Safeguard
Developer Tools•

How do you remove a Go dependency completely?

Delete the imports, run go mod tidy, and use go get module@none when needed. How to confirm a Go dependency is gone from go.mod, go.sum and the binary.

Safeguard Security Team
3 min read

Remove every import of the module from your code, then run go mod tidy, which removes modules that provide no relevant packages. If the module stays because something else needs it, find that with go mod why and use go get module@none only when you accept the knock on effects.

The commands

From the Go managing dependencies guide:

  • go mod tidy edits go.mod to add necessary missing modules and remove unused modules that provide no relevant packages. With -v it prints information about removed modules.
  • go get example.com/theirmodule@none removes a specific dependency, and will also downgrade or remove other dependencies that depend on the removed module.

The go.sum file is cleaned up by tidy too, which adds missing hashes and removes unnecessary ones, per the Go reference.

Steps

  1. Delete imports and code that use the module. Build to confirm nothing references it.
  2. Run go mod tidy -v and read what it removed.
  3. Check go.mod: the line should be gone. If not, run go mod why -m example.com/theirmodule to see who still needs it.
  4. If another dependency needs it, decide whether to keep it, replace that dependency, or accept it as an indirect requirement.
  5. Use go get example.com/theirmodule@none only if you understand the downgrades it may cause. Review the diff carefully.
  6. Search for leftovers: vendor directory (rerun go mod vendor), tool directives, build tags, test files and generated code.
  7. Rebuild and rescan. Confirm the module no longer appears in your SBOM or in the binary build info.

Common reasons it will not go away

SymptomLikely cause
Still in go.mod after tidyAnother package imports it, or a test file does
Reappears after go getA dependency requires it
Still listed in vendorVendor directory not regenerated
Still in the graph but not binaryRequired for version selection only

The last case is normal. A module can remain in the graph without contributing code. See which modules reach the binary.

Security reasons to prune

Each module is code you trust and a future advisory you may need to handle. Pruning unused dependencies shrinks the review surface and the list of findings. Do it as routine hygiene, for example before each release.

Where Safeguard fits

Safeguard's SBOM and dependency scanning show direct and transitive packages, so you can confirm a removal landed. Start with a free scan.

Quick check

Does go mod tidy remove unused modules?

Yes. It removes unused modules that provide no relevant packages and adds missing ones.

What does go get with @none do?

It removes the dependency and may downgrade or remove other dependencies that depend on it.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.