Skip to navigation

Go Workspace Boundaries: Decide What Belongs in go.work

In short: Find which local modules should participate in a Go workspace and how workspace directives alter resolution.

Published 21 min read
On this page

Direct answer

A module belongs in go.work when you edit it and another workspace member together and need local changes in one to resolve in the other without a published version. The workspace file’s use directives select local modules to treat as main modules, and a workspace replace directive overrides a member go.mod replacement. Both effects are local resolution behavior. They change which code your build and tests resolve to on your machine, and they do not change any module’s published metadata. The concrete win is a multi-module repository where a change spans two modules and resolves locally in one step. The concrete loss is that a workspace-specific replacement can make local resolution differ from an isolated module build, so a change that passes in the workspace can fail in CI that builds one module alone.

Ask Claude Code to map each module to a workspace role and to record every workspace-level replacement. The map is the review artifact. Deciding membership is the maintainer’s call once the roles and overrides are visible.

Why an unreviewed workspace costs a CI surprise

A workspace is convenient, which is the risk. A replace added to go.work to unblock a local build silently changes what every build in that workspace resolves. The change passes locally. The isolated module build in CI, which does not read the workspace, resolves differently and fails, or worse, resolves to an older version and passes for the wrong reason.

The cost is the divergence between local and CI resolution. A team that adds workspace replacements without recording them accumulates a file nobody can reason about, and the “works on my machine” failure comes back as a CI flake with no obvious cause.

There is a second cost: a workspace is not a release artifact. Nothing a workspace does reaches consumers, so a team that treats it as module configuration has confused local convenience with a published contract. Keeping the two separate is the whole discipline of this post.

Evidence and its limits

Official, F011: The Go Modules Reference describes go.work use directives as selecting local modules to treat as main modules, and says workspace replace directives override member go.mod replacements. The workspace file anchor and go.mod anchor document the two files separately. The Go Tutorial: Workspaces walks through a minimal workspace.

Official, agent loop: Claude Code best practices recommends a check that returns pass or fail. For a workspace review the check is a build of each member both inside and outside the workspace. Claude Code common workflows covers iterating an edit against a command.

Derived, F012: Recording which relationships are local development conveniences and which remain module requirements is an editorial boundary method, not a Go requirement for a particular repository layout.

No claim is made that a workspace changes a module’s release metadata, and no universal workspace layout is recommended.

What a Go workspace changes

A workspace lets several modules resolve against each other locally. Without one, a module that depends on a sibling uses the version in its go.mod, which is the published version. With a workspace that uses both, the sibling resolves to your local checkout.

That is the entire value and the entire risk. The value is a single build and test command across modules you are editing together. The risk is that the resolution is local and can diverge from every other context.

Without workspace With workspace
Sibling resolves to published version Sibling resolves to local checkout
Each module builds in isolation All used modules resolve together
go.mod replace governs workspace replace overrides
CI and local agree CI may differ if CI ignores the workspace

The last row is the failure to design against. If CI builds modules individually, the workspace is local-only, and every workspace override is a divergence you must be able to explain.

Read use directives

A use directive names a directory containing a module. The workspace treats that module as a main module, which means it is built and resolved as part of the workspace rather than fetched from a registry.

bash
go 1.22

use (
  ./api
  ./internal/shared
  ./tools/migrator
)

Each entry is a membership decision. Adding a module to the workspace means you intend to edit it alongside the others. A module that is only a dependency, never edited, does not need a use entry; it resolves through the normal requirement graph.

The Go Tutorial: Workspaces shows the minimal two-module case. A repository with several modules usually has a smaller use list than its module count, because not every module is edited together.

Claude Code can draft the membership map from the repository layout and the dependency graph, and the draft needs review. The agent sees directories and requirements; it does not know which modules a team edits together. Review each row against that question.

Map workspace replacements

A workspace replace directive redirects a module to a local path or a different version for the whole workspace. Because a workspace replace overrides a member go.mod replace, the workspace-level directive wins, and that precedence is the thing to record.

Module Member go.mod says go.work replace Effective locally
example.com/shared version v1.4.0 none v1.4.0 from registry
example.com/shared version v1.4.0 => ./internal/shared local checkout
example.com/legacy replaced to fork none member replace stands
example.com/legacy replaced to fork => ./vendor/legacy workspace override wins

The third and fourth rows are the review. A member go.mod replace survives in the workspace unless the workspace overrides it. A workspace override hides the member’s replace for the whole workspace, which is exactly the divergence that surprises CI.

Every workspace-level replace is a divergence from isolated module resolution by definition. The rule this post suggests is not that they are forbidden. It is that each one is recorded with a reason and an owner, and that the reason names what breaks without it.

Separate local and published contracts

The boundary in F012 is between two kinds of relationships. A local development convenience is a workspace use or a workspace replace that exists so you can build. A module requirement is a require in a member go.mod that consumers of that module also get.

A workspace changes the first kind only. It does not add a requirement to any module, does not change a module’s published go.mod, and does not alter what a consumer resolves. A change that belongs in a module’s contract belongs in that module’s go.mod, not in go.work.

Relationship Where it lives Reaches consumers Changes release metadata
Local sibling edit go.work use no no
Local redirect go.work replace no no
Module requirement member go.mod require yes yes
Member replace member go.mod replace per module semantics per module

Read the table before moving a directive. A redirect added to go.work to unblock a local build does not fix the module for consumers. If the redirect reflects a real dependency need, it belongs in the member go.mod, where it becomes part of the published contract.

On the compatibility side of that published contract, the Go module compatibility guide covers keeping API changes inside an import path. On the dependency graph side, the Go module graph pruning guide covers minimal version selection and indirect entries.

Choose workspace membership

Membership is a per-module decision with a simple test: do you edit this module at the same time as another workspace member, and do you need the local change to resolve now? If yes, use it. If the module is only ever a dependency at a published version, leave it out.

Module Edited with others Needs local resolution Membership
api yes, with internal/shared yes use
internal/shared yes, with api yes use
tools/migrator occasionally yes during migration work use, review periodically
example.com/thirdparty no no not a member
docs-site no no not a member

A membership list that grows to every module in the repository recreates the monorepo problem the workspace was meant to avoid, with a resolution graph nobody can reason about. The Claude Code monorepo search guide covers a different cost of large workspaces, search context; the same “keep it scoped” instinct applies to membership.

Review membership periodically. A module that was added for one migration and never removed keeps resolving locally long after the reason is gone, and that stale entry is a silent divergence from published versions.

Review override precedence

Workspace precedence is the part that produces CI surprises, so review it explicitly. For each dependency that differs between workspace and isolated resolution, record which directive wins and why.

bash
  # what the workspace resolves for a member
go list -m all
# what the member resolves alone, from inside the module
cd ./api && go list -m all

Diffing the two outputs is the concrete check. Every line that differs is a workspace effect. A diff that is empty means the workspace is not changing resolution for that member, which is the safest possible state. A diff with several lines means each one needs a recorded reason.

Dependency Isolated resolution Workspace resolution Reason recorded
example.com/shared v1.4.0 local ./internal/shared editing shared with api
example.com/legacy fork commit ./vendor/legacy local fork build

Two rows is a manageable workspace. Twenty rows is a repository where the workspace has become the real build configuration, which is the failure mode this review exists to catch.

The concrete win is a workspace where every override has a reason and the divergence from CI is known and small. The concrete loss is that the workspace is local-only, so no amount of workspace hygiene makes an isolated module build agree; CI still has to build each module alone, and the team still has to keep that build honest.

Evidence map showing go.work use directives selecting local main modules and workspace replace overriding member go.mod replacements for local resolution only.
Editorial evidence map based on F011 and F012. Workspace replace directives override replacements in member go.mod files, so local resolution can differ from an isolated module build. The effects are local and do not change published metadata.

Document the boundary

A workspace needs a short record next to the file. Two sections are enough: why each member is in the workspace, and why each workspace-level replace exists.

The record is what a new engineer reads before adding a directive. Without it, the workspace grows by accretion and the divergence from CI becomes unexplainable. With it, adding a replace is a decision with a reason rather than a shortcut.

Section Contents Review cadence
Membership module, why it is edited with others, owner when modules move
Overrides dependency, redirect, reason, owner every change
CI agreement which modules CI builds isolated when CI changes

The practical implication is that a workspace is a local development contract, and like any contract it needs to be readable. Teams that write down membership and overrides spend less time explaining CI failures. Teams that leave it implicit treat every workspace build as ground truth, which it is not.

Checklist before you commit a go.work change

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

Check Pass condition If it fails
Membership Every use entry has a recorded reason Add the reason
Stale members No member kept after its reason ended Remove it
Overrides Every workspace replace has a reason and owner Add both
Precedence Divergence from isolated resolution recorded Run the go list diff
CI agreement Each member builds alone in CI Fix the isolated build
Contract boundary No requirement moved from go.mod to go.work Put it back in go.mod
Scope Workspace not a stand-in for module config Move module config to go.mod
Workflow from repository module inventory through membership decision, override mapping, isolated-versus-workspace resolution diff, and a recorded boundary.
Editorial workflow based on F011 and F012. The sequence is an editorial boundary method, not a Go requirement for a particular repository layout.

Worked example: two modules and one override

Suppose a repository has api and internal/shared. api requires example.com/shared at v1.4.0, and internal/shared is the local copy of that module. A change spans both: a new function in shared, consumed in api.

The membership decision is to use both. With both in the workspace, a change to internal/shared resolves in api immediately, and the span compiles in one step. Without the workspace, api would resolve the published v1.4.0 and the new function would be invisible.

One override is needed: a workspace replace pointing example.com/shared at ./internal/shared. Record the reason as “editing shared with api for the new lookup function” and the owner as the team doing the change.

Check Workspace Isolated api build
example.com/shared resolves to local ./internal/shared published v1.4.0
New function visible yes no
Divergence recorded yes n/a

The concrete win is that a change spanning two modules compiles and tests in one local command instead of requiring a published intermediate version. The concrete loss is that the isolated api build does not see the change, so CI must build api against the published shared and the workspace must never be the only place the span is verified. The practical implication is that the workspace is a local convenience layered on a published contract, and the published contract still has to stand on its own.

Working with Claude Code on the workspace

Give the agent two inputs: the repository’s module layout and the set of changes in flight. Ask for a membership map and an override map with reasons. 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. The isolated-versus-workspace go list diff is that check.

Ask the agent to report three things. The modules it recommends for membership and why. Every workspace-level replace with its reason. The resolution diff for each member. A report that adds a replace without a reason, or that claims the workspace fixes something for consumers, should be returned.

Reviewing membership and overrides is the maintainer’s job. The agent reads directories and requirements, but which modules a team edits together and what CI builds isolated is knowledge outside the repository. The Claude Code verification guide covers asking what changed, what proves it, and what was not checked.

Tradeoff between convenient local cross-module resolution in a workspace and the divergence from isolated module builds that CI still has to verify.
Editorial tradeoff diagram based on F011 and F012. Local cross-module resolution is convenient; the isolated module build does not see it, so every override is a recorded divergence rather than a fix.

Workspace boundaries sit next to other Go module work in this batch. The compatibility contract is covered by the Go module compatibility guide, which covers keeping API changes inside an import path. The dependency graph is covered by the Go module graph pruning guide, which explains minimal version selection and indirect entries.

Other ecosystems answer the same local-versus-published boundary question: the Cargo workspace inheritance guide covers centralizing workspace metadata without hiding crates, the Cargo feature unification guide covers which optional APIs a workspace build exposes, and the Python dependency groups vs extras guide covers separating local workflow requirements from published package metadata.

Interface and shape contracts in the batch cover the Python protocols vs ABCs guide, the Python TypedDict boundaries guide, and the Python stub drift guide. Build-system boundary work covers the Gradle variant attributes guide, the Gradle constraints vs dependencies guide, and NuGet central package management. Each covers a file where a local setting must not be confused with a published contract.

Schema-level and generated contracts in the batch cover Protocol buffer reserved fields, sqlc query annotations, C# source generators, and OpenAPI generator customization. Further dependency boundaries appear in Gradle capability conflicts, Maven optional dependencies, CMake find_package vs FetchContent, and TypeScript project references. Framework maintenance guides including Django deprecation runway, Rails upgrade sequence, and Angular update guide apply the same reasoning to framework versions.

Common workspace mistakes

Four mistakes account for most workspace trouble. Each has a known check, which is why naming them speeds up review.

The first is the permanent override. A workspace replace added for one migration stays after the migration ends. The override keeps redirecting a dependency to a local path that no longer changes, and the divergence from published versions persists with no reason attached. The check is a periodic pass over the override list asking whether the reason still holds.

The second is the workspace as build config. A team that keeps adding replaces until every dependency resolves locally has turned go.work into the real build configuration. At that point the isolated module build in CI is testing a different program than the one developers run, and the two drift apart. The check is the size of the override list relative to the dependency count.

The third is the missing isolated build. Nothing in CI building each member alone, the workspace is the only thing validating the code, and the workspace is local-only. The failure surfaces as a consumer report rather than a CI failure. The check is whether every member has an isolated build job.

The fourth is the requirement parked in the wrong file. A dependency the module actually needs belongs in that module’s go.mod. Parking it in the workspace as a replace makes it work locally and disappear for consumers. The check is whether any workspace entry duplicates what a member go.mod should declare.

Mistake Symptom Check
Permanent override Override with no current reason Review override reasons
Workspace as build config Most dependencies replaced locally Compare override count to deps
Missing isolated build Failures reported by consumers, not CI Verify each member builds alone
Requirement in wrong file Works locally, missing for consumers Match workspace entries to go.mod

Each row is a review finding, not a tool error. A workspace that passes all four checks is small, recorded, and honest about being local.

Claude Code can run the isolated-versus-workspace diff and report the override list, which covers the first, second, and fourth checks mechanically. The third check is a CI configuration question that sits outside the repository’s build files. Asking the agent to confirm CI coverage it cannot see produces a report that looks complete and is not.

When a workspace is the wrong tool

A workspace solves local cross-module resolution. Three situations look like workspace problems and are not.

The first is a dependency version conflict. Two modules needing incompatible versions of a shared dependency, a workspace replace picks one for the whole workspace, which hides the conflict rather than resolving it. The conflict belongs in the module graph, and the tool for it is the version selection and compatibility review, not a local redirect. The Go module graph pruning guide covers how the graph selects versions.

The second is a module that should not exist. Sometimes two modules are one module split for no reason, and the workspace exists to paper over that. Merging the modules is the fix, and the workspace is a workaround that outlives its justification.

The third is a build that needs to reproduce exactly what consumers get. A workspace changes resolution, so it is the wrong place to validate a release. Release validation belongs in an isolated module build with the published versions resolved.

Situation Workspace helps Better tool
Editing two modules together yes workspace
Version conflict between members no graph and compatibility review
Two modules that should be one no merge the modules
Validating a release build no isolated module build

The third row is the one that catches teams. A workspace build that passes is not a release build that passes, because the resolution differs. Treating the workspace as release validation is the specific mistake that produces a consumer report instead of a CI failure.

This is the same local-versus-published distinction that runs through the batch. The Go module compatibility guide covers the published contract side, and the workspace covers the local side. Neither substitutes for the other.

More Claude Code verification guides

A workspace review is only as good as the check behind it. Claude Code verification covers the questions to ask before calling a workspace change finished. Claude Code false success covers the trap of reading a green workspace build as a validation of the published modules, which is the trap in the isolated-build row above. A workspace audit produces evidence the same way any agent review does, and Claude Code usage tracking covers how measured spend and usage feed the scope decisions around how much verification a change warrants.

A workspace file that grows by accretion is the pattern behind Claude Code overengineering. Recording each override with a reason and an owner is the discipline that keeps the file reviewable. For the trust boundary around tooling that runs in your checkout, Claude Code repository hooks covers hooks that execute locally, and Claude Code Gitignored files covers local files that build and test commands can touch.

Data gap and future update

The rules behind F011 come from the Go Modules Reference, which was reachable at research time. This post does not claim a universal workspace layout and does not claim a workspace changes published metadata, because the reference describes workspace behavior as local resolution.

The go.work and go.mod anchor pages were not full-page fetched in the research pass, so the exact directive wording carries a recheck caveat. A future update should verify the canonical anchors and add any workspace features added in newer Go releases, since that evidence was not collected here.

No benchmark, build-time measurement, or monorepo-size claim is made. The membership and override method is derived from the documented resolution behavior. Its effect on build time or CI stability is not measured in this post.

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. It 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 use the cost calculator to compare hosted options.

FAQ

Does adding a module to go.work change what consumers resolve?

No. A use directive selects a local module to treat as a main module for your workspace builds. It does not change the module’s published go.mod or what any consumer resolves. The effects are local.

Can a go.work replace override a member go.mod replace?

Yes. The Go modules reference says workspace replace directives override member go.mod replacements. That precedence is why every workspace-level replace needs a recorded reason: it silently changes resolution for the whole workspace.

Should every module in the repository be in go.work?

No. Add a module when you edit it alongside another member and need local changes to resolve now. A module that is only a dependency at a published version does not need membership. A workspace covering every module recreates the resolution complexity it was meant to avoid.

Why does CI fail when the workspace build passes?

The isolated module build in CI does not read go.work, so it resolves published versions while your workspace resolves local checkouts and overrides. Run the isolated-versus-workspace go list diff for each member to see the divergence, and keep the isolated build honest.

Can I put a module requirement in go.work instead of go.mod?

No. A requirement that consumers of the module need belongs in that module’s go.mod, where it becomes part of the published contract. A workspace directive is a local convenience and does not reach consumers.

More from this batch

For the monorepo search cost of a large workspace, the Claude Code monorepo search guide covers reducing grep loops and context bloat. A workspace that grows past a handful of members starts to pay that cost in review attention as well.

More Claude Code troubleshooting

Sources

Control checklist covering membership reasons, stale member removal, override precedence, and isolated build agreement in CI.
Editorial control checklist derived from F011 and F012. Passing the checklist shows the workspace boundary is recorded honestly; it does not make an isolated module build agree with the workspace.
Verdict that a scoped go.work with recorded overrides makes cross-module local work convenient while published module contracts still stand alone.
Editorial verdict based on F011 and F012. A workspace is a local development contract layered on published module contracts; every override is a divergence from isolated resolution that must be recorded.
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 →