The Go retract Directive: Withdrawing a Bad Version

Once a Go module version has been fetched through the public module proxy, it is cached and the checksum database records its hash. You cannot take it back or replace it. What you can do, since Go 1.16, is publish a newer version whose go.mod says "do not use that one". That is the retract directive.

Why deletion is not an option

The Go ecosystem deliberately treats versions as immutable. The checksum database lets every go command verify that a version's contents match what everyone else saw. If you deleted a tag and re-tagged different code under the same number, users with the old hash would get a verification error, not your fix. So the rule is simple: never move or reuse a tag. Retract and release a new version instead.

Retracting, step by step

  1. Fix the problem on your main branch.
  2. Add a retract directive to go.mod naming the bad version and a comment explaining why. The comment is shown to users, so write it for them.
  3. Tag and push the next version. That version's go.mod carries the retraction.
module example.com/you/ratelimit

go 1.22

retract (
    // Token bucket refills at 10x the configured rate.
    v1.4.0
    // Panics on zero burst; use v1.4.2 or later.
    [v1.4.1, v1.4.1]
)

Single versions and closed ranges are both allowed. The go command reads retractions from the latest version of the module, so the directive must stay in go.mod in later releases; removing it would effectively un-retract the version.

Retracting the latest version itself

A common case: you just tagged v1.5.0 and it is broken, and you have no fix yet. Tag v1.5.1 containing only a retraction of both itself and v1.5.0:

retract (
    v1.5.0 // Broken release: config loader ignores env vars.
    v1.5.1 // Contains only this retraction.
)

Users resolving @latest will then fall back to the highest non-retracted version, v1.4.2 in this illustration.

What users see

When to retract, and when not to

Retract for versions that are actively harmful: a wrong release tagged by mistake, a security problem with a fixed successor, a change that silently corrupts data. Do not retract merely because a newer version exists or because you regret an API; those are jobs for deprecation, which Go supports with a // Deprecated: comment above the module line. The difference matters because retraction is noisy by design, and users learn to ignore noise.

Other registries have the same idea under another name: PyPI and crates.io call it yanking. For the broader process around a bad release, see semver edge cases; for the Go module basics this builds on, the Go module publishing outline; and for the authoritative rules, the "retract directive" section of the Go Modules Reference.

Related pages