All jobs

Add CodeQL Scanning to a Go CLI

Yes. An agent adds a CodeQL workflow to your Go CLI that scans on pull requests and a weekly schedule, confirms it builds, and opens a PR with the first findings.

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 reads what already scans the code so CodeQL adds to it instead of repeating it. In a CLI laid out like charmbracelet/glow, go.mod names the module charm.land/glow/v3 with a go 1.26.7 directive and pulls in cobra, viper and the Bubble Tea v2 stack. .github/workflows/build.yml calls reusable workflows from charmbracelet/meta for the build, a goreleaser snapshot, govulncheck, semgrep and ruleguard; lint.yml runs golangci-lint-action v9.3.0 with --issues-exit-code=0 and only-new-issues, over a .golangci.yml that enables gosec among its linters; coverage.yml runs go test -race and posts to Coveralls; goreleaser.yml releases on v*.*.* tags; and .github/dependabot.yml groups monthly gomod, github-actions and docker updates. Nothing uploads results to GitHub code scanning, and no workflow mentions CodeQL.

Before writing anything it checks, with gh api repos/{owner}/{repo}/code-scanning/default-setup, whether the repository already has CodeQL default setup turned on, because an advanced workflow is refused while default setup is active; the pull request says which state it found. It then writes .github/workflows/codeql.yml, triggered on push to the default branch, on pull_request, and on a weekly schedule, with permissions limited to security-events: write, contents: read and actions: read.

The job uses actions/setup-go with go-version-file: go.mod, so the compiler matches the directive, then github/codeql-action/init with languages: go and the security-extended query suite, github/codeql-action/autobuild, and github/codeql-action/analyze with a category per language. The agent pins each action to the same major the other workflows use and adds the codeql workflow to Dependabot's existing github-actions group by leaving the directory unchanged. It also writes a concurrency group keyed on the ref so a force-push cancels the superseded scan.

In its sandbox the agent installs the CodeQL CLI, creates a Go database from the repository and runs the same suite the workflow names, so the pull request can list what the first scan will report rather than promising a clean result. Findings that gosec in .golangci.yml already covers are noted as duplicates a reviewer may want to silence on one side. It runs actionlint on the workflow before opening the pull request.

Start it with one API call

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

{
  "agent": "claude",
  "input": "Add CodeQL scanning to this Go CLI. Read go.mod, .golangci.yml, .github/dependabot.yml and every file under .github/workflows first, and check with the GitHub API whether CodeQL default setup is already enabled. Write .github/workflows/codeql.yml triggered on push to the default branch, pull_request and a weekly schedule, with security-events: write, contents: read and actions: read permissions, a concurrency group per ref, actions/setup-go reading the version from go.mod, and github/codeql-action init, autobuild and analyze for Go with the security-extended queries, pinned to the major versions the other workflows use. Install the CodeQL CLI in this sandbox, build a database and run the same queries so you can list the findings the first scan will produce, marking any that gosec in the linter config already reports. Run actionlint on the workflow and open a pull request with the findings list and the default-setup state you found.",
  "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

The pull request adds .github/workflows/codeql.yml and nothing else. Its description says whether default setup was on, lists every finding the sandbox scan produced with its query id, file and line, marks which of them gosec already reports, and shows the actionlint result.

After the merge, each pull request gets a CodeQL check and the Security tab fills with the weekly scan's alerts; a new finding on a pull request shows up as an annotation on the changed lines, alongside the existing govulncheck, semgrep and ruleguard checks.

Before merging, a reviewer reads the findings list to decide whether any need a fix in the same change, confirms the permissions block is as narrow as the description says, and checks that go-version-file keeps the scan's compiler in step with go.mod as Dependabot bumps it.

Run it on every new repository

A team with many Go tools sends this body once per repository from its own server, each a POST /o/{org}/sessions with that repository in resources and a request_id that is a UUID v5 of the repository's full name, so a retried call returns the run already started. Each run reads its own go.mod and workflows: a module with a tools.go gets autobuild replaced by a manual go build ./... step, and a repository that already runs CodeQL default setup gets a pull request that explains why no workflow was added.

Once scanning is on, an automation on the Project with a github trigger on pull_request.opened and the prompt "if the CodeQL check reported a new alert on this pull request, read it and comment with the data flow it describes and a suggested fix" starts one run per pull request. The trigger adds the pull request after the prompt; the run reads and comments and pushes nothing.

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

Why run it on Rush?

The first CodeQL run on a repository is the one that surprises people, with findings that have been in the code for years. The agent runs that scan in its own sandbox first, so the pull request that enables the check arrives with the list, each item already compared against the linter the repository runs today.

The CLI install, the database build, the query run and the actionlint output stay with the run as proof. A team with dozens of Go repositories starts one run per repository at once, and each pull request arrives with its own findings list.

Frequently asked questions

Does it conflict with CodeQL default setup?

GitHub refuses an advanced workflow upload while default setup is active. The agent checks that state through the API before writing the workflow, and if default setup is on, the pull request explains the choice between keeping it and switching to the workflow.

Why security-extended rather than the default suite?

The default suite is tuned for very few false positives; security-extended adds queries with lower precision that still matter for a tool that reads files, follows URLs and runs editors, as this one does. The sandbox scan shows what that costs in findings before anyone commits to it.

Will it slow down pull requests?

The job runs beside the existing build, lint and coverage jobs rather than in sequence with them, and the concurrency group cancels a scan a force-push has made redundant. Its runtime is the database build plus the query run, which the sandbox scan gives a first measure of.

What about gosec in golangci-lint?

Both stay. gosec runs on every lint pass with only-new-issues, while CodeQL does data-flow analysis across functions and uploads to the Security tab. The pull request marks findings both tools report so a reviewer can decide where to silence duplicates.

More Go CLI jobs

The same job on other stacks

Keep reading