/aa-jl:fixing-julia-exportsfrom aa-jl
Audits and trims excessive Julia package exports — internal helpers exported only for test access, stale exports, and namespace pollution. Covers export inventory, public vs internal classification, and safe removal with Aqua.jl verification.
Ships in aa-jl. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
using MyPkg brings every name in export ... into the caller's scope. When a
package exports an internal helper just because its own tests need it, that
helper becomes part of the de-facto public API: it shows up in names(MyPkg),
in the docs namespace, and in name-collision warnings for every user of the
package.
The fix is almost always on the test side, not the source side: stop exporting the helper, and import it explicitly in the tests. This skill finds those exports and removes them safely.
See [[developing-julia-package]] for the general style rule ("Avoid excessive
exports"); this skill is the concrete audit-and-fix workflow.
On Julia 1.11 and later, names(MyPkg) lists public names marked with either
public or export; it is not an export-only inventory. Use
Base.isexported when you need to distinguish names imported by using:
$ julia --project -e 'using MyPkg; println(sort(filter(n -> Base.isexported(MyPkg, n), names(MyPkg; all=true))))'
$ rg -n '^\s*export\b' src/
names(MyPkg; all=true) includes all bindings for comparison. A single
export line can list many names, so read the statements rather than grepping
for one name.
For every exported name, find out whether it is genuinely public:
docs/ (@docs blocks), the
README, or package examples. Keep it exported (or see Step 4 for public).src/ or only by test/ — internal; remove the export.Search each candidate across the whole repository:
$ rg -n --glob '!Manifest.toml' '\bhelper_name\b'
If the only hits outside src/ are in test/, the export exists solely for
Pkg.test, which is exactly the case to fix. Treat docs as the source of
truth: a name that is documented is public even if nothing in src/ calls it.
Before editing, tell the user which files you are about to change (especially
when modifying an existing package). Then delete the name from the export
list in src/MyPkg.jl — the function itself stays exactly where it is — and
update the test suite to reach it explicitly.
Before (documented only by an accidental export):
# src/MyPkg.jl
export fit_model, initial_guess # initial_guess is internal
# test/runtests.jl
using Test
using MyPkg
@testset "initial_guess" begin
@test initial_guess(x, y) isa NamedTuple # works only because of the export
end
After — import only what the test needs, keeping the public API clean:
# src/MyPkg.jl
export fit_model
# test/runtests.jl
using Test
using MyPkg
using MyPkg: initial_guess # explicit internal import
@testset "initial_guess" begin
@test initial_guess(x, y) isa NamedTuple
end
Prefer testing through the public API first. Import an internal directly only when the helper has meaningful behavior that cannot be exercised through the public path (see [[developing-julia-package]]).
Notes that matter when editing tests:
using MyPkg: name imports just that name; import MyPkg plus a fully
qualified MyPkg.name is the other acceptable form. Avoid pulling in
MyPkg wholesale in a test whose point is to exercise internals.using MyPkg: @internal_macro.test/ instead of exporting from src/.public (not export) when a name is public but unexportedSometimes a symbol is meant to be callable but should not be dumped into
every caller's namespace. On Julia 1.11+, mark it with public:
module MyPkg
public internal_api_for_advanced_users
internal_api_for_advanced_users(x) = ...
end
public records the name as public API (so doc tooling and users know it is
supported) without adding it to the names exported by using MyPkg; callers
still write MyPkg.internal_api_for_advanced_users. Do not use public as a
substitute for fixing tests that merely needed an import — Step 3 is the fix
for test-only access.
Run the full test suite; the explicit imports should keep every test passing:
$ julia --project -e 'using Pkg; Pkg.test()'
See [[testing-julia-package]] for test setup and optional focused or parallel runs while iterating.
Confirm the exported surface shrank:
$ julia --project -e 'using MyPkg; println(sort(filter(n -> Base.isexported(MyPkg, n), names(MyPkg; all=true))))'
A successful cleanup looks like:
Pkg.test() still passes.using MyPkg: name.If the package runs quality checks, let Aqua.jl catch exported-but-undefined names and other API mistakes (see [[generating-julia-package]] for adding Aqua to the test environment):
using Aqua
Aqua.test_all(MyPkg) # includes undefined_exports and unbound_args checks
If you are preparing the package for registration, continue with the pre-registration checklist in [[generating-julia-package]] (compat bounds, version, full test suite).
Removing an export is a breaking change for anyone who relied on
using MyPkg; helper — even if your intent was that the helper be internal. In
practice:
public if you only want to stop
auto-injecting it into caller scopes.export
lines or re-listed after a refactor; grep for the name, not just the first
export.using MyPkg and calls the bare name fails with
UndefVarError — add using MyPkg: name (or qualify it).docs/ and the README before cutting an export.public to paper over test access. public does not put the name
in scope for using MyPkg, so tests would still not see it; import it
explicitly instead.export @m and public @m have the same semantics;
import macros the same way in tests.using MyPkg; when in doubt, deprecate rather than delete.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
14 skills in this plugin
/auditing-julia-package-practicesUse when you review an existing or in-progress Julia package against this repository's development practices and want prioritized, evidence-based findings and concrete remediation suggestions/creating-julia-appUse when you create a CLI written in Julia packages or MCP servers/debugging-juliaUse when Julia code errors, throws an exception, produces wrong results, or crashes and you need to find the cause from the command line: capturing and reading stack traces, locating the failing method with @which/@code_warntype/@code_typed, finding potential runtime errors with JET.jl, and narrowing to a minimal reproductionnpx claudepluginhub atelierarith/atelier-arith-julia-development-skills --plugin aa-jl