Safeguard
Developer Tools•

How do you pin Go developer tools with the tool directive?

Go 1.24 added a tool directive to go.mod so linters and generators are versioned and checksummed with your code. Learn the commands and the tradeoffs.

Safeguard Security Team
3 min read

Since Go 1.24 you can record developer tools such as code generators in go.mod with a tool directive, add one with go get -tool, and run it with go tool. The tool is then versioned and checksummed like any dependency, instead of being installed from @latest on each machine.

Why this matters for supply chain risk

Many projects document a line like go install example.com/tool@latest in a README or Makefile. That fetches whatever is newest on the day, on every laptop and CI job, outside your reviewed dependency list.

The tool directive moves that into go.mod and go.sum, so the version appears in code review and the hash is verified.

Commands

From the Go reference and the managing dependencies guide:

go get -tool golang.org/x/tools/cmd/stringer
go tool stringer
go get tool
go get -tool golang.org/x/tools/cmd/stringer@none
  • The first adds a tool line to go.mod.
  • The second runs it. If names conflict, use the full package path.
  • go get tool upgrades all tools.
  • The @none form removes one.

If the tool lives in another module, a require for that module is needed too, which go get -tool handles.

Before and after

ApproachVersion sourceReviewed in PRs
go install pkg@latest in a scriptWhatever is newest todayNo
go install pkg@v1.2.3 in a scriptScript textSometimes
tool directivego.mod and go.sumYes

Steps to migrate

  1. List tools your team runs: linters, generators, mock builders, migration helpers.
  2. Add each with go get -tool and commit go.mod and go.sum.
  3. Replace install steps in Makefiles and CI with go tool name.
  4. Run your vulnerability scan again. Tools are now part of the module graph, so their dependencies appear in results.
  5. Decide who upgrades them. A scheduled go get tool pull request works well.

Watch for side effects

Tool dependencies join the graph for version selection, which can raise versions of shared libraries. Review the go.mod diff when you add one. Also note that a tool runs with your developer privileges, so a generator is as trusted as any code you build. Pin it, and review upgrades with the same care as application dependencies.

Where Safeguard fits

Safeguard's SBOM and dependency scanning read go.mod, so pinned tools are inventoried with the rest. You can run a free scan on a repository to see the full list.

Quick check

Which Go version added the tool directive?

The Go reference marks the tool directive as Go 1.24 and later.

How do I remove a pinned tool?

Run go get -tool with the package and @none, which removes the line.

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.