DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk6 min

declscope: A Go Linter That Enforces File Boundaries in AI-Written Code

declscope is a Go static analyzer that adds private and package scopes to Go packages and flags cross-file uses that break them. Here is how it works, how to install it, and where it falls short.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

declscope is a Go static analyzer that flags when code in one file uses a helper or field that a team meant to keep inside another file or its own file. It is a narrow boundary checker. It does not measure or prove that it makes AI-generated Go code better overall, and no published study currently supports a “dramatic” quality gain.

Why Go’s visibility rules don’t stop an AI agent from crossing files

Go has two visibility levels. Capitalized names are exported and usable from other packages. Lowercase names are unexported, and they are visible to every file in the package that declares them. The compiler does not know about file ownership, so a convention such as “this helper belongs to parser.go” is invisible to it.

As an Amazon Associate I earn from qualifying purchases.

That gap matters more when an AI coding agent is editing the code. An agent that sees an unexported helper in scope may call it from another file, or reach into an unexported struct field. The result usually compiles and passes the tests, yet it violates the boundary the team intended. Nothing in the standard toolchain reports that violation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The project behind declscope frames the underlying tension the same way. Teams often split a package only to enforce a boundary, and that split brings costs of its own: import cycles, interfaces added only to break those cycles, and names that have to become exported. A per-file convention keeps the package flat, but only a checker can enforce it.

What declscope adds: private and package scopes

declscope adds two pseudo-scopes on top of Go’s existing rules. A declaration marked private stays within its file. A declaration marked package is deliberately shared across the files of its package, without splitting the package into subpackages. The scopes are expressed with directives, //declscope:private and //declscope:package, and they are checked during static analysis at each use site.

Visibility level How it is set Where a use is allowed Who enforces it
Exported (capitalized name) Capitalization Any package that imports this one Go compiler
Unexported (lowercase name) Lowercase name Any file in the declaring package Go compiler
declscope private //declscope:private directive Its own file declscope
declscope package //declscope:package directive Files in the same package, as a deliberate shared scope declscope

The directive is a record of intent. A reader of the code can see that a helper is meant to stay in one file, and the linter can report any call that crosses that line.

How the boundary rule reports a crossing

The boundary rule detects a use from a different file or namespace than the one a declaration’s scope allows. Each diagnostic names the namespace that was crossed. From there there are two outcomes, and the choice is yours:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Sharing is intended. Run the -fix option to add a widening scope directive, so the declaration becomes package-scoped and the cross-file call is legitimate.
  • The boundary should hold. Move the call into the owning namespace. The project’s guidance is to restructure the code rather than widen the scope.

The project also documents configuration for defaults, naming, boundary checks, and detection of unused directives. Those options are documented in the project’s package page, linked below.

How do I install declscope?

The README lists several routes: mise (recommended), Go tool dependencies, go install, go run, and prebuilt release archives. The current README states that the go tool and go install routes require Go 1.27 or later. Go’s own dependency guide describes a broader feature floor: since Go 1.24, developer tools can be tracked with go get -tool and run with go tool. Check the project’s release notes before you publish an installation snippet, because both the tool version and the toolchain requirement can change.

  1. Confirm your toolchain is at least the version the README names for your route. Run go version.
  2. Add declscope as a tool dependency in the module:
    go get -tool github.com/mpyw/declscope/cmd/declscope@latest

    This records the tool in go.mod. Because @latest is a moving reference, replace it with a specific release, such as v0.18.0 (the version current as of early October 2026), before using it for team builds.

  3. Run the linter across the module:
    go tool declscope ./...

For reproducible team use, the project also shows pinning the version in mise.toml. Use one pinning method across the team so every developer and CI job runs the same analyzer version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can an AI coding agent call unexported Go functions from another file?

Yes. Lowercase names are visible throughout their package, so an agent can call them from any file and the compiler will accept the call. declscope does not prevent the edit. It reports the crossing when it is a use that violates a declared scope, and it can suggest a fix. That makes it a guardrail that runs after the agent writes code, not a restriction on what the agent can type.

The project recommends running the linter both in continuous integration and inside the agent’s edit loop, so the crossing is reported before it reaches review. Treat the report as the first check, followed by human review and tests.

Adopting declscope in an existing codebase

A large existing package will usually have violations on day one. The project’s approach is to record them rather than fix them all at once.

  1. Record the baseline. Run declscope baseline ./.... Existing violations are recorded, and new ones remain visible. The README says to regenerate the baseline rather than edit it by hand.
  2. Survey the results. Run declscope survey to see what was checked and found in each package.
  3. Inspect the crossings. Run declscope inspect <package> to see the namespaces and the crossings between them.
  4. Use JSON for agent work. When an AI agent is helping you introduce the tool, use the JSON output the README describes, and rank crossings by the crossings[].clears field so the agent works on the highest-value items first.
  5. Run in CI and in the edit loop. Keep the check in continuous integration so that new violations fail in the same way for people and agents.

If you run it through go vet with -vettool, be aware of caching. The README notes that go vet may cache results without configuration and baseline files in its cache key. After changing either file, run with -a, or run declscope directly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where declscope does not look

The analyzer reads one package at a time and counts a use when a name is written in source. It does not see the following cases, so a clean report does not cover them:

  • Uses from outside the package.
  • Whole-value operations on a struct, such as copies, comparisons, or zeroing, that do not name a field.
  • Reflection.
  • //go:linkname references.
  • Generated files.
  • Declarations with no uses. An unused declaration produces no boundary diagnostic, so the README points to a separate unused-code linter for that job.

declscope is therefore not a general code-quality, correctness, security, or dead-code analyzer. It is useful only where a team has file-level ownership conventions worth enforcing and is willing to adopt and configure them deliberately.

Does declscope measurably improve AI-written Go code?

The available evidence does not show it. The project describes its purpose as a guardrail for agent edits, and it does not publish a study measuring defect rates, productivity, or review effort for AI-written code. The Google Developers Blog article “Why Go is an Ideal Language for AI-Assisted Software Engineering,” by Cameron Balahan (Group Product Manager, Go) and Richard Seroter (Chief Evangelist, Google Cloud), published August 11, 2026, makes a related point about human responsibility. It states: “What matters now is reviewing, verifying, and maintaining that code once it’s already written.” The article does not evaluate declscope.

The fair claim is narrower: declscope can detect a specific kind of cross-file use that the compiler accepts, and it can do so before that use reaches a reviewer. Whether that reduces defects in your codebase is a question for your own measurements.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

declscope compared with adjacent Go tools

The project names two neighbouring tools to clarify scope. They differ mainly in the boundary they examine.

Tool Boundary it examines What it checks
declscope Uses inside one package, across files Whether a use crosses a declaration’s private or package scope
depguard Imports between packages Which packages may import which
deadcode Whole program Whether code is reachable at all

When choosing among them, compare the boundary scale, whether the tool checks declarations or package imports, how it fits your existing CI and Go tooling, and what each one leaves uncovered.

Licensing and source

declscope is released under the MIT License. Its package documentation and README are on the project’s pkg.go.dev page, which describes version v0.18.0, published October 2, 2026. The project’s own tagline is: “Keep your Go packages flat without letting them turn into a free-for-all.” That is the maintainers’ description of their goal, not an independent assessment.

Source for the Go toolchain and dependency guidance: Managing dependencies, The Go Programming Language.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sources: declscope package documentation and README; Why Go is an Ideal Language for AI-Assisted Software Engineering, Google Developers Blog, August 11, 2026.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.