# Add Clippy to CI for a Tokio Project

Yes. An agent runs Clippy across your Tokio crate's library, binaries, tests and examples, fixes or scopes what it reports, adds a clippy job to CI, and opens a PR.

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

## What the agent does

The agent reads the workflow first, because the point of this job is to leave CI red when a lint regresses and green now. In a Tokio project laid out like tokio-rs/mini-redis, `.github/workflows/ci.yml` has one `build` job on a matrix of `ubuntu-latest`, `macos-latest` and `windows-latest` that runs `cargo build --verbose`, the same with `--features otel`, `cargo test --verbose` twice the same way, and `cargo fmt --all --check`. There is no Clippy step and no `rust-toolchain` file, and `Cargo.toml` is an edition 2018 crate with two binaries (`mini-redis-cli` from `src/bin/cli.rs`, `mini-redis-server` from `src/bin/server.rs`), an `otel` feature that pulls in `opentelemetry`, `tracing-opentelemetry`, `opentelemetry-aws` and `opentelemetry-otlp`, four examples and four integration test files under `tests/`. `src/lib.rs` carries no crate-level `allow` or `deny` attribute.

Then it runs Clippy the way CI will, in its own sandbox: `cargo clippy --all-targets --all-features -- -D warnings`. `--all-targets` reaches the examples, the integration tests and both binaries, which `cargo clippy` alone skips; `--all-features` compiles the `otel` code path in `src/bin/server.rs`, where `set_up_logging` has a second definition under `#[cfg(feature = "otel")]`. The agent reads every warning in the output against the source: `src/connection.rs`, `src/db.rs`, `src/frame.rs`, `src/parse.rs`, `src/server.rs`, the `cmd` modules and the three clients. A warning with a mechanical fix is fixed and the test suite rerun; a warning that would change a public signature, or that the code's own comments justify, gets a `#[allow(clippy::...)]` on that item with a one-line reason, never a crate-wide allow in `lib.rs`.

Next it adds a `clippy` job to `ci.yml` beside `build`: checkout, a stable toolchain with the `clippy` component, the same command, on `ubuntu-latest` only, since lints do not vary by operating system and the build matrix already covers the three. It keeps `-D warnings` so a new warning fails the job, and records in the workflow the trade-off that brings: a new stable Clippy can add lints, so the pull request explains how to bump or pin the toolchain when that happens. `cargo fmt --all --check` stays where it is, since formatting and lints are different failures and a reviewer wants to know which one tripped.

Last it reruns `cargo build`, `cargo test` and the `--features otel` variants exactly as `ci.yml` does, so the pull request shows the lint job passing on a tree where the existing jobs still pass, and lists every source change and every `allow` with its reason.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Add Clippy to this Tokio project's CI. Read Cargo.toml, .github/workflows/ci.yml, src/lib.rs, src/bin/server.rs, src/bin/cli.rs, src/server.rs, src/connection.rs, src/db.rs, src/frame.rs, src/parse.rs, the modules under src/cmd and src/clients, the tests directory and the examples directory first. Run cargo clippy --all-targets --all-features -- -D warnings and read every warning against the source. Fix the ones that are mechanical and keep behaviour the same; for any you leave, add a targeted allow attribute on that item with a one-line reason, never a crate-wide allow. Add a clippy job to ci.yml on ubuntu-latest with a stable toolchain and the same command. Rerun cargo build, cargo test and both --features otel variants as the workflow does, and open a pull request that lists each change and each allow with its reason.",
  "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 changes `.github/workflows/ci.yml` and whichever source files Clippy pointed at under `src/`, `tests/` and `examples/`. Its description quotes the Clippy output before and after, lists each fix with the lint name that asked for it, and lists each `allow` with its reason, so a reviewer can disagree with one line rather than re-run the tool.

`CI` runs on the pull request with its new `clippy` job next to the three `build` jobs; the lint job is the one that would go red on a later pull request that introduces a warning.

Before merging, a reviewer checks that the fixes changed no public signature among `src/lib.rs`'s exports (`Client`, `BlockingClient`, `BufferedClient`, `Command`, `Connection`, `Frame`, `server`), decides whether any `allow` should instead be a fix, and decides whether `-D warnings` is right for a teaching crate that many people build with whatever toolchain they have, or whether the job should only warn until the next toolchain bump.

## Run it on every Rust crate without Clippy in CI

A team with several Rust services starts one run per repository from its own server: one `POST /o/{org}/sessions` each, 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 `Cargo.toml` and workflow, so a workspace gets `--workspace` added to the command, a crate with a `rust-toolchain.toml` gets the job pinned to that file, and one that already has a `clippy` step gets its warnings fixed and no workflow change.

After the merge, an automation on the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` and the prompt "run cargo clippy --all-targets --all-features -- -D warnings on this pull request's branch and, for each new warning, comment with the file, line and the fix" turns a red job into a review comment with the fix attached. The trigger puts the pull request after the prompt; only pushes by an owner, member or collaborator fire it, never a fork's.

## Why run it on Rush?

Adding a Clippy step is one line; the work is the first run against a crate that has never been linted, where every warning is a judgement about code someone wrote with a reason. The agent runs the tool in its own sandbox at the toolchain CI will use, reads each warning in context, reruns the test suite after each kind of change, and keeps the full output with the run so the pull request opens green rather than with a list of annotations for a person to triage.

The `otel` feature, the examples and the integration tests all compile in the sandbox the way the workflow compiles them, so a lint that only appears under `--all-features` or `--all-targets` is caught before the job exists. For a team with many crates, each gets its own run and its own pull request, fitted to its own targets and toolchain.

## Frequently asked questions

### Why run Clippy with --all-targets and --all-features?

Because the default invocation lints only the library and binaries with default features. This crate has four examples, four integration test files and an `otel` feature with its own code path in `src/bin/server.rs`; without both flags those compile in the `build` job but are never linted, and a warning there would surface the first time someone enables the feature.

### Will -D warnings break CI when a new Rust release adds lints?

It can, and the pull request says so. The job uses the stable channel, so a new release can add a warning that fails the job until it is fixed or allowed. The alternative is to drop `-D warnings` and let the job warn, which keeps CI green but means nobody reads the output. The agent picks the strict setting and leaves the choice visible to the reviewer.

### Does the agent change the existing build matrix?

No. The three `build` jobs keep their build, test and `cargo fmt --all --check` steps on all three operating systems. The lint job is a separate job on Linux only, so a Clippy failure and a formatting failure show up as different checks.

### What does it do with a warning it cannot fix safely?

It adds `#[allow(clippy::<lint>)]` on that function or type with a comment saying why, and lists it in the pull request. It does not add `#![allow(...)]` to `src/lib.rs`, because a crate-wide allow hides every future instance of that lint too.

## More Tokio jobs

- [Add a Config File to a Tokio Server](https://getrush.ai/run/add-config-file/tokio/)
- [Add Code Coverage to CI for a Tokio Service](https://getrush.ai/run/add-coverage-to-ci/tokio/)
- [Add Criterion Benchmarks to a Tokio Server](https://getrush.ai/run/add-criterion-benchmarks/tokio/)

## More jobs like this: Hand off a long task

- [Add CloudWatch Alarms to a Serverless Framework Service](https://getrush.ai/run/add-cloudwatch-alarms/serverless/)
- [Add CMakePresets.json to a CMake Project](https://getrush.ai/run/add-cmake-presets/cmake/)
- [Add a Custom Code Block Renderer to an Obsidian Plugin](https://getrush.ai/run/add-code-block-processor/obsidian-plugin/)

## 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/)
