# Add golangci-lint to a Go CLI's CI

Yes. An agent replaces a dead linter script with a golangci-lint config, fixes or documents what the first run finds, adds a CI job and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-golangci-lint-to-ci/go-cli/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the CLI into its own cloud sandbox and reads how it is built and checked today. In a tool like tomnomnom/gron, `go.mod` declares `go 1.24` with four direct dependencies, `fatih/color`, `mattn/go-colorable`, `nwidger/jsoncolor` and `pkg/errors`, and the code is a handful of files at the root: `main.go` with the `flag` parsing, exit codes and a `gronVersion` set through `-ldflags`, `identifier.go` and `statements.go` with their `_test.go` files, and a `testdata/` directory of JSON and gron fixtures. `.github/workflows/build.yml` runs `go test` on a matrix of `stable` and `oldstable` with `actions/setup-go@v5` and its cache; `release.yml` runs `goreleaser/goreleaser-action@v6` on tags with a `TAP_GITHUB_TOKEN` for a Homebrew tap, against a `.goreleaser.yml` that vendors modules and publishes a source archive.

Linting exists on paper. `script/lint` installs `gometalinter` with `go get` if it is missing and runs it with `gocyclo`, `dupl` and `gas` disabled and `goimports` enabled, each with a comment explaining why; `CONTRIBUTING.mkd` asks contributors to run `gofmt`, `./script/test` and `./script/lint` before a pull request. But `gometalinter` has been archived for years and `go get` no longer installs binaries, so the script cannot run on a current toolchain, and no workflow calls it. A `.travis.yml` lists Go `1.13` through `1.23` and `tip` for a CI that no longer runs. `gofmt -l .` and `go vet ./...` are quiet on the current tree.

The agent writes `.golangci.yml` in the current config format, translating the old choices rather than starting from a maximal preset: `errcheck`, `govet`, `staticcheck`, `unused` and `ineffassign` on, `gofmt` and `goimports` as formatters, `gocyclo` and `dupl` left off for the reasons the old script gave, and `gosec` on but with its TLS verification rule excluded for the one place `main.go` sets `InsecureSkipVerify` when the user asks for it. Then it runs `golangci-lint run ./...` in the sandbox. Findings that are bugs, an unchecked `Close` on a file handle is the common one in a CLI of this age, are fixed in their own commit; findings that are style are listed as exclusions in the config with a one-line reason each, so the check starts green and every exclusion is a visible decision.

`script/lint` becomes a three-line script that calls `golangci-lint run`, installing it with `go install` from its module path at a pinned version when it is absent, so the contributing instructions stay true. `.github/workflows/build.yml` gains a `lint` job beside `build` that checks out, sets up Go with the same action and runs the official `golangci-lint` action pinned to the same version as the script, on the stable toolchain only. `.travis.yml` is left alone and named in the pull request as a file that could go in a separate change.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add golangci-lint to this Go CLI. Read go.mod, every file under script/, CONTRIBUTING.mkd and every workflow under .github/workflows first. Write a .golangci.yml that keeps the intent of the existing lint script: enable errcheck, govet, staticcheck, unused and ineffassign, use gofmt and goimports as formatters, leave gocyclo and dupl off, and enable gosec with an exclusion for the deliberate InsecureSkipVerify. Run golangci-lint in the sandbox; fix findings that are real bugs in a separate commit and record style findings as exclusions with a reason each, so the check passes. Rewrite script/lint to call golangci-lint, installing a pinned version if missing. Add a lint job to the existing build workflow using the official action at the same version, on the stable toolchain. Run go test to confirm nothing else changed. Open a pull request that quotes the first and the final lint output.",
  "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 with up to three commits: the fixes to real findings, if any, then `.golangci.yml` and the rewritten `script/lint`, then the `lint` job in `build.yml`. The description quotes the first `golangci-lint run` output and the final clean one, and lists every exclusion with its reason next to the linter that raised it.

The run's record keeps the install of the pinned linter, both lint runs and `go test`, so a reviewer can see which findings became fixes and which became exclusions, and that the test suite is unchanged by the fixes. The release workflow and `.goreleaser.yml` are untouched.

Before merging, a reviewer reads the exclusions and decides whether any should be fixes instead, confirms the pinned linter version is the one they want to maintain in two places, and chooses whether to delete `.travis.yml` and the `gometalinter` reference in `CONTRIBUTING.mkd` in this change or the next.

## Run it on every Linear issue labelled lint

A maintainer who keeps several small Go tools labels the chore instead of doing it ten times. An automation with a `linear` trigger on `linear.issue.labeled` and the label `lint` starts one run per labelled issue, with the issue after the prompt above; the issue names the repository and any linters the team wants on or off beyond the defaults, and the run opens one pull request on its own branch that links back to it.

A run whose final lint or `go test` does not pass ends `needs_review` instead of opening a pull request that would fail its own new check, and its trajectory shows the finding it could not resolve, so the maintainer answers on the issue rather than re-running the linter locally to find out.

## Why run it on Rush?

The hard part of adding a linter to an old repository is not the YAML; it is the first run, whose findings have to be sorted into bugs, style and deliberate choices one by one, with the code open. The agent does that in its own sandbox with the real tool at a pinned version, keeps the first and last output in the record, and turns each decision into a line in the config or a commit, so the pull request shows its reasoning instead of a green badge.

The same request across an organisation's Go tools returns one pull request per repository, each with a config translated from that repository's own lint script and comments rather than one shared file, and each with its own list of what was excluded and why. The repositories whose old lint script still ran get a smaller diff; the ones whose script had quietly died get a working one.

## Frequently asked questions

### Why not keep gometalinter?

It is archived, and `script/lint` installs it with `go get`, which no longer installs binaries on a current toolchain, so the script fails before it lints anything. golangci-lint runs the same family of linters, including `goimports`, under one pinned binary.

### Will it turn on every linter?

No. The config keeps the old script's intent: a small set of correctness linters plus formatters, with `gocyclo` and `dupl` off for the reasons the old script gives. Adding more is a one-line change later, and the pull request names a few worth considering.

### What happens to the InsecureSkipVerify finding?

`gosec` flags it, and the code sets it only when the user passes the flag that asks for it, which the old script's comment also explains. The agent excludes that one rule for that one place in `.golangci.yml`, with the comment carried over, rather than disabling `gosec`.

### Does the lint job run on both Go versions?

No. The test matrix stays on `stable` and `oldstable`; the `lint` job runs once on `stable`, because the linter is pinned to one version and its result does not depend on the toolchain matrix.

## More Go CLI jobs

- [Set Up GoReleaser Releases for a Go CLI](https://getrush.ai/run/add-goreleaser/go-cli/)
- [Add govulncheck to a Go CLI's CI](https://getrush.ai/run/add-govulncheck-to-ci/go-cli/)
- [Add HTTP Timeouts to a Go CLI](https://getrush.ai/run/add-http-timeouts/go-cli/)

## The same job on other stacks

- [Add golangci-lint to an Echo API's CI](https://getrush.ai/run/add-golangci-lint-to-ci/echo/)

## More jobs like this: Turn a Linear label into a PR

- [Add Google Login to an AdonisJS App](https://getrush.ai/run/add-google-login/adonisjs/)
- [Add Google Login to a Next.js App with NextAuth.js](https://getrush.ai/run/add-google-login/next-auth/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
