bazel go hygiene

    1

    Keep Bazel Go repositories green by automating Gazelle, Buildifier, and bzlmod dependency synchronization.

    Free

    1 installSecurity scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+22 more

    bazel go hygiene

    Example session with this skill installed

    I just added a new dependency to go.mod and updated my imports in main.go. Can you make sure Bazel is updated and everything builds?

    • Read your context and instructions
    • Compiled the bazel go hygiene

    I have synchronized your Go dependencies with Bazel and updated the generated build files. I ran go mod tidy followed by bazel mod tidy to update your MODULE.bazel file, then executed Gazelle to update your go_library targets.

    Hygiene Results

    ActionCommandResult
    Dependency Syncgo mod tidy && bazel mod tidySuccess: Updated use_repo in MODULE.bazel
    BUILD Generationbazel run //:gazelleSuccess: Updated deps for //cmd/app:app_lib
    Formattingbazel run //:buildifierSuccess: Formatted 2 files
    Build Validationbazel build //...Success: 14 targets built
    Static Analysisbazel test //...Success: nogo passed

    Updated MODULE.bazel snippet

    go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
    go_deps.from_file(go_mod = "//:go.mod")
    use_repo(
        go_deps,
        "com_github_rs_zerolog", # New dependency added
        "org_golang_x_sys",
    )
    

    Updated cmd/app/BUILD.bazel snippet

    go_library(
        name = "app_lib",
        srcs = ["main.go"],
        importpath = "github.com/user/repo/cmd/app",
        visibility = ["//visibility:public"],
        deps = [
            "@com_github_rs_zerolog//:zerolog", # Gazelle injected
        ],
    )
    

    Next steps

    • Verify the new dependency functions as expected by running bazel test //cmd/app/....
    • Check if you need to add any gazelle_override in MODULE.bazel if the dependency has non-standard build requirements.
    • Commit the changes to MODULE.bazel and BUILD.bazel before opening your PR.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Maintaining a Bazel-managed Go repository often feels like fighting two build systems at once. Code compiles with the Go toolchain but fails in Bazel due to stale BUILD files, missing dependencies in MODULE.bazel, or nogo static analysis failures. Manual edits to use_repo lists or deps arrays lead to brittle repositories that break in CI.

    This skill automates the hygiene required to keep rules_go, gazelle, and bzlmod in sync. It ensures your go.mod changes propagate correctly to your Bazel workspace and that your Starlark files remain formatted.

    What it does

    • Synchronizes dependencies by mapping go.mod updates to MODULE.bazel via bazel mod tidy.
    • Regenerates BUILD files using Gazelle to track added, removed, or renamed Go files and imports.
    • Enforces formatting across BUILD.bazel, .bzl, and MODULE.bazel files using Buildifier.
    • Validates builds against the source of truth, ensuring nogo static analysis passes within the Bazel sandbox.
    • Resolves pathing issues for transitive dependencies and OS/CPU specific select() statements.

    How it works

    1. Analyze changes to identify if the user updated Go source, dependencies, or Bazel configuration.
    2. Execute hygiene pipeline by running the sequence of go mod tidy, bazel mod tidy, and gazelle.
    3. Audit against nogo to catch static analysis failures that go build ignores but Bazel rejects.
    4. Format Starlark to ensure all configuration files meet the repository's style standards.

    Frameworks & tools

    Bazel, Go, rules_go, Gazelle, Buildifier, bzlmod, and nogo static analysis.

    Why this beats prompting it yourself

    Generic AI agents often suggest standard Go commands that bypass Bazel's sandbox. This skill understands the specific requirements of bzlmod and the use_repo extension, preventing the common "no such package" errors that occur when manually editing Bazel files.

    Use cases

    • Adding new internal Go packages and generating their corresponding go_library targets.
    • Upgrading third-party dependencies and updating the go_deps extension in MODULE.bazel.
    • Fixing CI failures where Gazelle indicates a diff between source code and BUILD files.
    • Implementing OS-specific build tags or platform-dependent dependencies correctly.

    Known limitations

    Requires a functional Bazel installation and a pre-configured gazelle target in the root BUILD.bazel file. Hermetic Go SDK settings may require a matching host Go version for local linting.

    How to use

    Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    1 install

    Downloaded by developers to date

    Free forever

    No account required to browse

    Trust & safety

    Security scanned

    Verified clean 4 days ago

    • Free to download with an account

    Requires

    bazel
    golang

    Listed4 days ago

    What's inside

    Frequently Asked Questions