All jobs

Fix golangci-lint Findings in a Go CLI and Make Lint Block Merges

Yes. An agent runs your Go CLI's own golangci-lint config, fixes every finding in the code, keeps go test green and opens a PR that shows lint at zero.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts by finding out why lint never fails. In a CLI like charmbracelet/glow, .github/workflows/lint.yml runs golangci/golangci-lint-action on every push and pull request, but with args: --issues-exit-code=0 and only-new-issues: true, so findings are printed and never block. The configuration is .golangci.yml, version: "2", with twenty-odd linters enabled (bodyclose, goconst, gosec, noctx, nolintlint, wrapcheck among them), tests: false, and gofumpt and goimports as formatters. .github/workflows/lint-sync.yml calls a shared lint-sync workflow in charmbracelet/meta every Sunday that keeps that configuration in step with the organisation's template, so a local edit would not stick; the fix has to be in the code. build.yml already runs govulncheck, semgrep and ruleguard from the same shared workflows, coverage.yml runs go test -race with a coverage profile, and go.mod is charm.land/glow/v3 on Go 1.26.

It then runs the real linter at the version the action would use and reads every finding before touching one. On this repository the output is a short, mixed list: nolintlint reporting //nolint:gosec and //nolint:prealloc directives in main.go, ui/editor.go, ui/pager.go, ui/stash.go, ui/stashitem.go and utils/utils.go that no longer suppress anything, because the linter they name stopped flagging those lines; goconst on "esc", "enter" and "cancel" strings in ui/ui.go and ui/stashhelp.go where keyEsc and keyEnter constants already exist; one staticcheck S1025 on a fmt.Sprintf("%s", …) in ui/stash.go; two wrapcheck returns of unwrapped os.OpenFile and term.MakeRaw errors in ui/rawpaint_unix.go; one noctx on exec.Command in main.go; and one gosec G122 on an os.Open inside a filepath.Walk callback.

Each class gets the fix the linter is asking for, not a suppression. Stale //nolint directives are deleted; the repeated key strings use the existing constants and a new keyCancel beside them; the Sprintf becomes the plain string; the two unwrapped errors get fmt.Errorf("…: %w", err) in the style log.go already uses for unable to get cache dir; exec.Command becomes exec.CommandContext(cmd.Context(), …) since the call sits inside a Cobra command that has one. The gosec G122 finding about opening a path handed in by filepath.Walk is the one the agent reads most carefully: the walk is over a directory the user named and the path comes from the walk itself, so the agent either moves the open to os.Root as the finding suggests or, if that changes behaviour on symlinked documents, keeps the code and adds a //nolint:gosec with a reason, which nolintlint requires. The pull request says which it chose and why.

The proof is the linter and the tests. The agent runs golangci-lint run ./... again to show zero findings with the repository's own config, gofumpt -l . and goimports -l . to show the formatters are clean, and go test -race ./... across glow_test.go, url_test.go, ui and utils to show nothing changed behaviour. It then proposes the one workflow change that makes this stick: dropping --issues-exit-code=0 and only-new-issues from lint.yml, in its own commit, with a note that lint-sync.yml may rewrite the workflow and that the charmbracelet/meta template is where a permanent change belongs.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Fix every golangci-lint finding in this Go CLI and make lint able to block merges. Read go.mod, .golangci.yml, Taskfile.yaml, every workflow under .github/workflows and the files the linter reports first, and note that lint-sync.yml syncs .golangci.yml from a shared template, so do not edit that file. Run golangci-lint with the repository's own configuration, fix each finding in the code rather than suppressing it, delete nolint directives that no longer apply, and where a finding is a false positive keep the code and add a nolint directive with a reason. Run golangci-lint again to show zero findings, run gofumpt and goimports in list mode, and run go test -race ./... Then, in a separate commit, remove --issues-exit-code=0 and only-new-issues from lint.yml and explain in the pull request that the shared template is where that change should also be made. Open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch with two commits. The first touches only Go files: a handful in ui/, main.go and utils/utils.go, each change a few lines, with no new dependency and no edit to .golangci.yml. The second is one small change to .github/workflows/lint.yml that lets the action's exit code fail the job, kept apart so a reviewer can merge the fixes and hold the policy change if they prefer.

The description lists every finding by file, line and linter with the one-line fix it got, quotes the final golangci-lint run summary and the go test -race result, and calls out the one finding the agent judged a false positive, if any, with the reason it wrote into the directive. The transcript at GET /o/{org}/sessions/{id}/messages keeps the full linter output before and after.

Before merging, a reviewer reads the gosec decision, checks the wrapcheck messages read well in the CLI's error output, and decides whether to change the shared template in charmbracelet/meta so the next Sunday sync does not undo the workflow change. A follow-up message to the same session can open that second pull request against the template repository if it is connected too.

Run it on every Go repository you maintain

A maintainer with many Go CLIs starts one run per repository with one POST /o/{org}/sessions each, the repository in resources and this prompt as input. Each run uses that repository's own .golangci.yml, so a project with a different linter set gets different fixes, and each opens its own pull request with its own before-and-after output.

A key may have at most max_concurrent runs in progress at once, four by default, and a loop over more repositories can send every call without spacing them: the extra runs are answered 202 with status: "queued" and start, oldest first, when a slot frees. Send a request_id, one UUID per repository, so a retried call returns the run it already started.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

A lint job that cannot fail is the same as no lint job, and turning it on usually means an hour of small, scattered fixes that nobody wants to do by hand: stale directives, a constant that already exists, an unwrapped error, one security finding that needs real thought. The agent does the whole list with the repository's own configuration and version of the tool, in a sandbox of its own, and keeps the output of every run.

The pull request carries the finding-by-finding table and the final linter and test output, so the review is a read of small diffs and one judgment call. Several repositories can be handled at once, each in its own sandbox with its own pull request.

Frequently asked questions

Why not edit .golangci.yml to quiet the noisy linters?

Because in this repository lint-sync.yml syncs that file from a shared template every week, so the edit would vanish, and because the findings are real: stale directives, duplicated strings and unwrapped errors. The agent fixes the code; where a linter is wrong, a directive with a reason records that.

What does it do with the gosec finding?

It reads the code. G122 flags opening a path handed back by filepath.Walk, which can race with a symlink change. If moving to os.Root keeps the CLI's behaviour on the user's documents, it does that; if not, it keeps the code and writes a //nolint:gosec with the reason, which nolintlint accepts. Either way the pull request says which.

Will this change how CI behaves right away?

Only if the second commit is merged. It removes --issues-exit-code=0 and only-new-issues from lint.yml so the job fails on findings. It is a separate commit so you can take the fixes first and the policy when you are ready, and the description notes that the shared template should carry the same change.

Does it run the tests?

Yes, go test -race ./..., the same command coverage.yml uses minus the coverage profile, over the root package, ui and utils. The result is quoted in the pull request, and a fix that changed a test's outcome is reverted and reported in the description rather than merged into the branch.

More Go CLI jobs

More jobs like this: Hand off a long task

Keep reading