Skip to navigation

Go Module Compatibility: Keep API Changes Inside the Contract

In short: Find whether a proposed Go API change fits the module compatibility contract before choosing a version path.

Published 21 min read
On this page

Direct answer

A proposed Go API change fits the compatibility contract when it does not break any code that imports the current path. Go’s module reference states that packages sharing an import path must remain backward compatible, and that incompatible v2-and-later modules use major version suffixes on the module path. So the decision is not “is this a big change” but “does this change the meaning of an existing import”. A new function is compatible. A changed parameter type or a removed export is not, and it needs either a compatible formulation or a new major version with a suffixed module path. The concrete win is a release decision grounded in the import contract rather than in a version label. The concrete loss is that Go’s rules are Go’s rules: they do not generalize to other ecosystems, and the reference documents special handling for non-module repositories that this post keeps separate.

Ask Claude Code to inventory the exported API surface before and after the change and to classify each difference. The classification drives the version path. Choosing the path is the maintainer’s call once the classification is on the table.

Why a misclassified change costs downstream trust

An incompatible change released under a compatible version label breaks consumers on a routine go get -u. They did not opt into a major upgrade. The break lands as a compile error in their build, and the fix is on their side even though the cause was a mislabeled release. Few things lose module trust faster than a single bug.

The cost is not the compile error. The cost is the review burden it creates afterward. Consumers who were broken once start pinning exact versions and reading every diff, which slows adoption of the compatible changes you actually want them to take.

There is a reverse cost too. Treating +incompatible as a normal major-version path hides a real breaking change behind a pseudo-version that looks routine. The Go reference keeps that path separate for a reason, and this post does the same.

Evidence and its limits

Official, F009: The Go Modules Reference states that packages sharing an import path must remain backward compatible and that incompatible v2-and-later modules use major version suffixes. The reference also documents special handling for non-module repositories, which this post does not collapse into the normal module path rule. The Go 1 Compatibility Promise is the broader language-level promise behind that discipline.

Official: Semantic Versioning 2.0.0 defines what a major, minor, and patch version mean, and the Go Blog: v2 Go Modules post explains how a module moves to v2 in practice.

Official, agent loop: Claude Code best practices recommends a check that returns pass or fail. A compatibility review checks a build of a consumer that imports the module, before and after the change. Claude Code common workflows covers iterating an edit against a command.

Derived, F010: Comparing the exported API change, import path, module path, and intended version before selecting a release strategy is an editorial decision framework, not an official release approval process.

This post does not claim every tagged release is module-compatible, and it invents no deprecation timeline for any third-party module.

The Go compatibility promise

Go’s promise is about import paths, not about effort or intent. Two packages with the same import path must stay backward compatible. If a change would break a caller, the change needs a new import path, which in practice means a new major version and a suffixed module path.

The rule is stricter than “we will try not to break things”. It makes the import path the unit of compatibility. A consumer that imports example.com/m/pkg is owed a stable contract at that path for as long as the path exists.

Version Expected change Import path Consumer action
patch bug fix, no API change unchanged none
minor additive, backward compatible unchanged none
major incompatible suffixed (/v2) update imports

The promise covers exported API. Behavior is not promised to be identical, performance is not promised unchanged, and a bug you relied on is not promised to persist. Reading it as an API contract rather than a behavior contract is what keeps the classification honest.

Import paths and module paths

The module path is declared in go.mod and is the prefix for every package import inside the module. The v0 and v1 module path has no version suffix. Version 2 and later end the module path with the major version.

Module go.mod path Package import
v0/v1 example.com/m example.com/m/pkg
v2 example.com/m/v2 example.com/m/v2/pkg
v3 example.com/m/v3 example.com/m/v3/pkg

The suffix is not cosmetic. Coexistence of v1 and v2 in one build depends on it. A consumer can import both, and each major version is a separate module with its own compatibility contract. The suffix is the mechanism behind the promise in F009.

A repo that wants to keep a single import path across majors has to avoid incompatible changes or accept that it is breaking the contract. There is no configuration that makes one path stay compatible while its API breaks.

Classify the proposed API change

Classify each difference between the old and new exported surface. Four categories cover most cases.

Change Category Compatible Version path
Add a new exported function additive yes minor
Add a method to an interface you own additive yes, if consumers cannot implement it minor, with review
Add a required parameter breaking no major
Change a parameter or return type breaking no major
Remove or rename an export breaking no major
Add a field to a struct additive usually minor, with review

Two rows need a second look. Adding a method to an exported interface breaks any consumer that implements the interface, so it is breaking despite looking additive. Adding a field to a struct is usually compatible because composite literals with field names still compile, but a consumer using unkeyed struct literals would break. Both are the rows a reviewer should not wave through.

Claude Code can produce the before-and-after export inventory, and the classification needs review. The agent reads declarations; it does not know which types consumers implement or how they construct structs. The Claude Code verification guide covers asking what changed and what proves it.

The same declared-surface discipline appears across this batch. A declared contract that must not change meaning silently is the subject of Go module graph pruning, which covers the requirement graph carrying these versions. A declared wire contract with the same no-silent-change rule is covered by Protocol buffer reserved fields, where a removed field number must not be reused. Declaration output ownership across projects is the subject of TypeScript project references. Reading these alongside the import-path rule shows one pattern in several ecosystems: a declared identity is a promise, and the promise is the thing that cannot drift.

bash
  # exported surface before and after
go doc -all ./pkg > /tmp/after.txt
git show HEAD~1:pkg/api.go > /tmp/before.go
# compare
diff <(rg "^func |^type " /tmp/before.go) <(rg "^func |^type " ./pkg/api.go)

Map semantic version consequences

Semantic versioning gives each category a version. Additive changes are minor. Breaking changes are major. Fixes with no API change are patch. The Semantic Versioning 2.0.0 spec defines those meanings, and Go’s module system maps major versions to path suffixes.

Category SemVer Go consequence What the maintainer writes
Additive minor same path, tag minor release notes describing the addition
Breaking major new suffixed path migration note from vN to vN+1
Fix only patch same path, tag patch notes describing the fix

The major-version row is where the module path changes. Tagging v2.0.0 while keeping the unsuffixed path does not create a v2 module; the path must carry the suffix. The Go Blog: v2 Go Modules post walks through that move.

A change that looks minor but breaks a consumer’s implementation of an exported interface is the classic misclassification. The SemVer label does not rescue it. The import contract does.

Handle major version suffixes

Moving to a new major version means updating go.mod to the suffixed path and updating every internal import to match. The old major keeps its own path and its own contract, so consumers migrate when they choose to.

bash
  # move a module to v2
go mod edit -module example.com/m/v2
# update internal imports
find . -name "*.go" -exec sed -i 's|example.com/m/|example.com/m/v2/|g' {} +

Record the migration path for consumers. A new major with no note about what changed and how to move is a contract change nobody can act on. The suffix is the mechanism, and the migration note is the courtesy that makes it usable.

The +incompatible marker is a separate case. It appears when a module with a v2+ tag but no suffixed path is resolved as if it were v1. Treating that as a normal major-version path is the specific overreach this post warns against. It is a compatibility shim for older repositories, not the path a new major should take.

Review non-module legacy packages

The Go reference documents special handling for repositories that are not modules or that predate modules. Those cases do not follow the same import-path rule as a maintained module, and this post keeps them separate rather than folding them into the normal path.

A legacy package resolved through a pseudo-version can carry an API that changed without a version tag. The compatibility analysis there is about the resolved commit, not about a SemVer label. Do not generalize the module-path rule to those cases, and do not treat a pseudo-version as a stability promise.

Repository shape Path rule applies Compatibility unit
Maintained module, v0/v1 yes import path without suffix
Maintained module, v2+ yes suffixed import path
Pre-module repository special handling resolved commit

The third row is the boundary of this post. Analyzing a pre-module repository’s compatibility needs the resolved commit and the actual diff, which is a different review from the module-path decision.

Write the compatibility decision

The decision record is what turns the classification into a release. It has four fields: the change, the classification, the version path, and the consumer action.

Field Value for a breaking change Value for an additive change
Change Parse now takes bytes new ParseStream function
Classification breaking additive
Version path new major, suffixed path minor on the current path
Consumer action update import path and call sites none, or adopt the new function

The record is the artifact a reviewer approves. A change with no record is a change whose compatibility was never decided, and those are the ones that ship under the wrong label.

The concrete win is a release where consumers are never surprised by a version label. The concrete loss is the discipline cost: a genuinely breaking change needs a new major, a suffixed path, and a migration note, which is more work than tagging it minor and moving on. The practical implication is that the import path is a contract, and contracts are cheaper to keep than to repair after consumers are broken.

On the graph side of Go dependency work, the Go module graph pruning guide covers how indirect entries and minimal version selection work, which is the complement to the compatibility decision here. For local development composition, the Go workspace boundaries guide covers what belongs in go.work.

Evidence map showing packages sharing an import path staying backward compatible while incompatible majors use distinct suffixed module paths.
Editorial evidence map based on F009 and F010. Module-aware packages put incompatible major versions behind distinct module paths rather than silently changing one import contract. Special non-module handling is kept separate.

Checklist before you tag a release

Run this list against the change. Each row is a pass condition.

Check Pass condition If it fails
Export inventory Before and after surfaces recorded Finish the inventory
Classification Every difference has a category Complete the table
Interface adds Any added interface method flagged as breaking Reclassify as major
Struct fields Unkeyed literal risk reviewed Review before tagging minor
Version path Path matches the classification Fix the path or the classification
Major move Suffix present in go.mod and imports Complete the move
Migration note Consumers have an action for a major Write the note
Legacy cases Non-module repos kept separate Do not fold them into the path rule
Workflow from export inventory through change classification, SemVer consequence, major-version suffix handling, and a recorded compatibility decision.
Editorial workflow based on F009 and F010. The sequence is an editorial decision framework, not an official release approval process.

Worked example: a parser signature change

Suppose a module example.com/m at v1 exports Parse(raw string) Node. A proposed change makes it Parse(raw []byte) Node because the parser now handles binary input directly.

The export inventory shows one changed signature. The classification is breaking: every caller passing a string stops compiling. The version path is a new major. The maintainer moves the module to example.com/m/v2, updates internal imports, and writes a migration note describing the string-to-[]byte conversion callers must make.

An alternative that keeps v1 compatible: add ParseBytes(raw []byte) Node and keep Parse as a wrapper. This option is additive, stays on the v1 path, and lets consumers migrate gradually. Both paths are valid; only the classification decides which one the contract allows.

Option Compatible with v1 Version path Consumer action
Change Parse signature No major, /v2 update import and call
Add ParseBytes, keep Parse Yes minor on v1 adopt when ready

The concrete win in the second option is that consumers are never broken and can move at their own pace. The concrete loss is that Parse becomes a wrapper the maintainer carries until a future major removes it. Neither option is free; the contract only decides which cost is honest to impose on consumers.

Working with Claude Code on the review

Give the agent two inputs: the module and version, and the proposed change. Ask for the before-and-after export inventory and a classification table. The agent session works best when the check is a command that returns pass or fail, which is the shape the official best-practices guidance recommends. A build of a consumer that imports the module is that check.

Ask the agent to report three things. The classified differences. The version path each classification implies. Any added interface method or struct-field change that needs a second look. A report that tags a breaking change as minor, or that treats +incompatible as a normal path, should be returned.

Reviewing the classification is the maintainer’s job. The agent reads declarations, but whether consumers implement an exported interface is knowledge outside the diff. The Claude Code overengineering guide describes how a small review request can produce a large diff; keep the review read-only and keep the release edit in a separate step.

Tradeoff between an additive compatibility shim on the current path and a clean break behind a new major-version module path.
Editorial tradeoff diagram based on F009 and F010. An additive shim keeps consumers unbroken but adds maintenance; a new major is clean but imposes migration. The classification decides which is honest.

Common misclassification patterns

Four patterns account for most compatibility mistakes in review. Naming them makes the review faster because each one has a known check.

The first is the additive interface method. A maintainer adds a method to an exported interface and tags it minor, because the diff looks like an addition. Every consumer that implements the interface now fails to compile, which makes it breaking. The check is a search for types that implement the interface, inside and outside the repository.

The second is the unkeyed struct literal. Adding a field to an exported struct is usually compatible because composite literals with field names still compile. A consumer using pkg.Point{1, 2} instead of pkg.Point{X: 1, Y: 2} breaks. The check is whether the struct is likely constructed positionally by consumers, which is a judgment the maintainer makes from how the struct is documented.

The third is the changed underlying type. A parameter that changes from string to a named type with the same methods, or from a concrete type to an interface it already satisfied, can look compatible and still break a caller that assigned the result to a concrete variable. The check is a build of a real consumer.

The fourth is the behavior-preserving rename. Replacing an exported function with a wrapper of the same name and signature is compatible. Replacing it with a wrapper whose default behavior differs is not, even when the signature is identical. The promise in F009 is about the API contract, and a silent default change is a contract change.

Pattern Looks like Actually is Check
Added interface method additive breaking search implementers
Unkeyed struct field additive breaking for positional literals review struct usage
Changed underlying type compatible often breaking build a consumer
Behavior-preserving rename compatible depends on defaults compare behavior

Each row is a judgment the maintainer records. None is settled by the version label, and none is settled by the diff size. The classification is about what callers do, not what the change looks like.

Claude Code can run the search behind the first and third checks and report results. The second and fourth need the maintainer’s knowledge of consumers, which is outside the diff. Asking the agent to classify without that context produces a table that looks complete and is not, which is the specific failure the review exists to prevent.

The version label is not the decision

A common shortcut is to decide the version first and work backward to the change. The label feels like the decision because it is the visible artifact, but it is the output of the classification, not the input. A team that tags first and reviews later has already committed to a compatibility claim before examining it.

The order that holds up is classification, then version, then tag. The classification names each difference and its category. The version follows from the worst category present. The tag records the result. Skipping to the tag skips the only step where a mistake can still be caught cheaply.

This is why the decision record in the previous section has the change before the version. The record forces the classification to be written down, and a written classification is one a reviewer can challenge. An unwritten one is a tag with a story attached.

The same discipline applies to other contract work in this batch. A schema change that reuses a removed field number, a dependency requirement that moves between a local and a published file, and an API change that crosses an import path are all cases where the visible artifact looks like the decision and is not. The artifact records a decision made earlier, or it records nothing.

The general version of this reasoning is in the Claude Code legacy code guide covers choosing an increment from consumer impact rather than from diff size. The Go module graph pruning guide covers a different Go contract: which versions the resolved graph selects and how indirect entries appear.

Module compatibility is one of several contract disciplines in this batch. On the dependency graph, the Go module graph pruning guide covers minimal version selection and indirect entries. For local development composition, the Go workspace boundaries guide covers what belongs in go.work and how workspace replacements override member go.mod directives.

Python answers the same boundary question in the Python dependency groups vs extras guide, which separates published metadata from local workflow requirements, and in the Python protocols vs ABCs guide, which covers structural versus nominal interface contracts. The Python TypedDict boundaries guide covers dictionary-shaped contracts, and the Python stub drift guide covers auditing declared typing surfaces against runtime APIs.

Rust has its own version in the Cargo workspace inheritance guide, which centralizes workspace metadata without hiding crates, and in the Cargo build scripts guide, which covers generated-artifact contracts.

Generated-code contracts in the batch cover C# source generators, OpenAPI generator customization, and GraphQL code generator client presets. Schema-level compatibility is covered by Protocol buffer reserved fields and sqlc query annotations. On the wire-contract side, where a field must not be reused, the protobuf guide is the closest parallel to the import-path rule here.

Build-system and dependency boundaries in the batch cover Cargo feature unification, Gradle constraints vs dependencies, NuGet central package management, and CMake find_package vs FetchContent. Each covers a declared dependency surface where the intent and the observed resolution can diverge, which is the dependency-graph cousin of an import-path contract. Framework maintenance guides including Django deprecation runway and Rails upgrade sequence apply the same consumer-impact reasoning to framework versions.

More Claude Code verification guides

A compatibility review is only as good as the check behind it. Claude Code verification covers the questions to ask before calling a release decision finished. Claude Code false success covers the trap of reading a green build as a compatibility proof, which is the trap a breaking change tagged minor creates.

The review load a release creates is covered by Claude Code code review, which looks at what happens when generated diffs outpace the review that accepts them. A release decision split into a reviewable record is the discipline behind Claude Code overengineering. A change that spans a version boundary is covered by Claude Code migration guide, which treats the consumer-facing note as part of the change rather than an afterthought.

Data gap and future update

The rules behind F009 come from the Go Modules Reference, which was reachable at research time. This post does not claim that every tagged release in the wild follows those rules, and it does not invent a deprecation timeline for any third-party module. Tagging practice varies by maintainer, and a tag is evidence of intent, not proof of compatibility.

The non-module and pre-module cases are deliberately kept separate. Their handling is documented in the reference, but this post does not enumerate every legacy shape. A future update should verify the current reference wording for those cases and add any changes to how the tooling resolves them.

The post makes no benchmark, adoption, or ecosystem comparison. Go’s rules are not generalized to other ecosystems, and the post makes no claim about how other package managers handle incompatible versions.

One AI API Key option for OpenAI-format agents

Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.

OpenAI-format agents have a separate route: One AI API Key offers https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. The route is a different client and request format, not a workaround for Claude Code authentication. Check the free model list and eligibility notes before choosing an agent route, or read the quickstart for the request shape.

FAQ

Does every tagged release count as module-compatible?

No. A tag records intent, and a compatibility decision is separate from the tag. A breaking change tagged as a minor is still breaking for consumers, and the import-path contract in F009 is what determines compatibility, not the label.

When do I need the /v2 suffix?

When the change is incompatible with the current import path. Go’s module reference states that incompatible v2-and-later modules use major version suffixes. Tagging v2.0.0 without the suffix does not create a v2 module.

Is +incompatible a normal major-version path?

No. It is a compatibility shim for repositories with v2+ tags but no suffixed path. Treating it as the normal path for a new major hides a breaking change behind a pseudo-version. Take the suffixed path instead.

Do Go’s compatibility rules apply to other languages?

This post does not generalize them. Go’s rules are about import paths and module paths in the Go module system. Other ecosystems have their own compatibility models, and the Go module graph pruning guide and workspace guide stay within Go for the same reason.

What proves a change is compatible?

A build of a consumer that imports the module, run before and after the change, plus a complete export inventory. Neither alone is sufficient: the inventory catches interface and struct-literal cases the build may not reach, and the build confirms the change compiles for a real importer.

More from this batch

More Claude Code troubleshooting

Sources

Control checklist covering export inventory, change classification, interface and struct-field review, version path, and the recorded compatibility decision.
Editorial control checklist derived from F009 and F010. Passing the checklist shows the release decision was recorded honestly; a tag alone does not prove compatibility.
Verdict that additive changes stay on the current import path while breaking changes require a new major version with a suffixed module path.
Editorial verdict based on F009 and F010. The import path is the contract; additive changes keep it and breaking changes require a suffixed major. Non-module cases stay separate.
More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
Claim $10 credit →