# Add Dialyzer to an Elixir App from a Linear Issue

Yes. Label the Linear issue and an agent adds dialyxir, builds the PLT once, clears or lists the existing warnings, and opens a PR with a cached CI job that runs it.

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

## What the agent does

The agent reads the issue, then the project. In an app shaped like hexpm/hexpm, mix.exs declares `elixir: "~> 1.20"`, a `deps/0` of roughly ninety entries including phoenix, ecto_sql, oban, broadway and a finch pinned to a git ref with `override: true`, and aliases where `test` runs `ecto.create --quiet`, `ecto.load --skip-if-loaded` and `ecto.migrate` before `test`. There is no dialyxir in the list and no `dialyzer` key in `project/0`. A .credo.exs is checked in even though credo is not a dependency, which the agent notes but leaves alone. Under lib there are 485 .ex files and 152 `@spec` lines spread over 33 of them, so most of the code has no specs and Dialyzer will infer types from success typing alone.

It reads the pipeline next, because the PLT is the whole cost of this job. .github/workflows/main.yml pins OTP 29.1 and Elixir 1.20.4 through erlef/setup-beam, restores deps and _build from actions/cache/restore keyed on mix.lock and the config files, lets only main save the cache, and runs `mix compile --warnings-as-errors`, `mix format --check-formatted` and `mix ecto.setup` in the Format job and `mix test` in Test Hexpm with a postgres:18 service. The Dockerfile builds from the same 1.20.4 and 29.1.1 pair. The dialyzer job the agent adds copies that shape exactly: the same setup-beam pin, the same restore and main-only save pattern, and a second cache for the PLT files keyed on the OTP and Elixir versions plus mix.lock, so a dependency bump rebuilds the PLT and nothing else does.

The code change is small. mix.exs gains `{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}` and a `dialyzer` entry in `project/0` with `plt_file: {:no_warn, "priv/plts/project.plt"}` so the PLT lives in a path CI can cache, `plt_add_apps: [:mix, :ex_unit]` because lib/mix holds Mix tasks and test/support is compiled in the test env, and `flags: [:unmatched_returns, :error_handling]` as the starting strictness. The agent runs `mix dialyzer` in the sandbox, which builds the core PLT and the dependency PLT once, then reads every warning the project produces. Warnings it can fix in a line, such as a spec whose return type omits an `{:error, _}` branch the function clearly returns, it fixes; anything that needs a design decision goes into .dialyzer_ignore.exs with a comment naming the module and the reason, so the first CI run is green and the ignore file is the to-do list.

Finally it wires the job in. The new `dialyzer` job in main.yml restores deps, _build and priv/plts, runs `mix dialyzer --format github` so each warning becomes an annotation on the pull request's changed lines, and runs after compilation under the same `MIX_OS_DEPS_COMPILE_PARTITION_COUNT: 2` the other jobs set. It carries the same `if` guard the Format job uses so a branch push and its own pull request do not run the job twice. The agent runs `mix format --check-formatted` and `mix compile --warnings-as-errors` after its edits, because the Format job would refuse an unformatted mix.exs, and runs `mix test` once so the `only:` list and the new alias do not disturb the suite.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "A Linear issue labelled agent asks for Dialyzer in this Elixir project's CI. Read mix.exs, mix.lock, config/config.exs, config/test.exs, the Dockerfile and every workflow under .github/workflows first, and note the OTP and Elixir versions they pin, how deps and _build are cached, and which jobs run on pull requests. Add dialyxir as a dev and test dependency with runtime false, and a dialyzer key in the project with a PLT path under priv/plts, plt_add_apps for mix and ex_unit, and the unmatched_returns and error_handling flags. Run mix dialyzer in the sandbox, fix warnings that are a one-line spec correction, and put the rest in .dialyzer_ignore.exs with a comment per entry saying why. Add a dialyzer job to the main workflow that uses the same setup-beam pin and cache pattern as the existing jobs plus a cache for priv/plts keyed on the OTP and Elixir versions and mix.lock, and runs mix dialyzer --format github. Run mix format --check-formatted, mix compile --warnings-as-errors and mix test afterwards, and open a pull request that links the issue, quotes the dialyzer summary and lists every ignored warning.",
  "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 that changes mix.exs and mix.lock, adds .dialyzer_ignore.exs and a `priv/plts/.gitkeep` with the PLT path in .gitignore, fixes a handful of `@spec` lines in lib, and adds a `dialyzer` job to .github/workflows/main.yml. The description links the Linear issue, states the dialyxir version resolved, and pastes the summary line `mix dialyzer` printed in the sandbox.

The evidence is in that run: the PLT build log, the full warning list before fixes, the shortened list after, and the output of `mix format --check-formatted`, `mix compile --warnings-as-errors` and `mix test` on the branch. The ignore file is listed entry by entry in the description so nobody has to open it to know what was deferred.

Before merging, a reviewer reads the ignore file and decides which entries are debt and which are false positives, checks that the PLT cache key includes the OTP and Elixir versions so a toolchain bump does not reuse a stale PLT, and watches the first pull request run to see how long the job takes with and without a cache hit. Raising the flags to `:underspecs` or removing an ignore entry is a follow-up on the same session.

## Run it on every Linear issue labelled agent

Sign in to Linear once with `POST /me/connections {"type": "app", "name": "linear"}` and finish the authorize URL in the console. Then add an automation to the Project with this prompt and a `linear` trigger on the label you triage with. The trigger adds the issue after the prompt, so the flags the team wants or the modules to start with come from the issue text; the automation's `max_runs_per_hour` caps how many issues it picks up.

Each labelled issue runs in its own sandbox and opens its own pull request. Once dialyxir is in, later issues such as `make dialyzer strict on lib/hexpm/accounts` start in a fresh sandbox, build the PLT once more, and the agent edits .dialyzer_ignore.exs and the flags rather than the pipeline.

## Why run it on Rush?

Adding Dialyzer is cheap to write and expensive to run: the first PLT over an OTP release and ninety dependencies is the slow step, and until it exists nobody knows how many warnings the project has or whether any of them are real. Doing that on a laptop ties it up and leaves the PLT on one machine. In the sandbox the agent builds it once, reads every warning, and arrives at the pull request with the list already triaged into fixes and documented ignores.

The run keeps the proof: the dialyzer summary, the diff of each spec it corrected, and the CI job that will reproduce the result with a cached PLT. A reviewer who disagrees with an ignore entry answers in a follow-up, and the parked sandbox, PLT included, reruns `mix dialyzer` on the change in the time a cold build would still be compiling.

## Frequently asked questions

### Will the first CI run take much longer?

The first run on a branch has to build the PLT, and that is the slow part of Dialyzer. The job caches priv/plts keyed on the OTP and Elixir versions and mix.lock, and only main saves it as the other jobs do, so every later run restores the PLT and checks the project's own code only.

### Does every existing warning get fixed?

No. One-line spec corrections are fixed in the pull request; anything that needs a decision goes into .dialyzer_ignore.exs with a comment per entry, so the first job is green and the ignore file is the backlog. The description lists each ignored warning.

### Why are the Mix tasks and test support in the PLT?

Because lib/mix defines Mix tasks and test/support is compiled under the test environment, and without the mix and ex_unit applications in the PLT Dialyzer reports unknown functions for both. plt_add_apps names them once.

### Will it slow down mix test or the release?

No. dialyxir is only in the dev and test environments with runtime false, so the release in the Dockerfile does not include it and mix test does not load it. Only the explicit mix dialyzer task and the new CI job run it.

### What about the .credo.exs that is already in the repository?

It stays as it is. Credo is not a dependency in mix.exs, so the file is unused today; the pull request mentions that and leaves adding credo as a separate issue rather than widening the change.

## More Elixir jobs

- [Add mix audit Dependency Scanning to an Elixir Project](https://getrush.ai/run/add-mix-audit/elixir/)
- [Add Property-Based Tests to an Elixir Library](https://getrush.ai/run/add-property-tests/elixir/)
- [Add a Release Workflow to an Elixir Library](https://getrush.ai/run/add-release-workflow/elixir/)

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

- [Add a Discount Function to a Shopify App](https://getrush.ai/run/add-discount-function/shopify-app/)
- [Add a Dead Letter Queue to a Lambda in AWS CDK from a Linear Issue](https://getrush.ai/run/add-dlq/aws-cdk/)
- [Add Doxygen API Docs to a CMake C++ Library](https://getrush.ai/run/add-doxygen-docs/cmake/)

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