# Add Slim CI for a dbt Project With GitHub Actions

Yes. An agent adds a GitHub Actions workflow that builds only the models a pull request changed, deferring to a production manifest, and proves it on Postgres.

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

## What the agent does

The agent reads how the project is built and how it is already tested before adding a workflow. In a project like dbt-labs/jaffle-shop, `dbt_project.yml` names `jaffle_shop` at version 3.0.0, requires dbt 2.0.0 or later, points `profile` at `default`, materializes `staging` as views and `marts` as tables, puts seeds in a `raw` schema and switches the `jaffle-data` seeds on only when the `load_source_data` var is true. `models/staging/__sources.yml` declares the `ecom` source with six raw tables, `models/staging` has six `stg_` models and `models/marts` has `customers`, `orders`, `order_items`, `products`, `locations`, `supplies` and a `metricflow_time_spine`; the YAML beside them carries `not_null`, `unique` and `relationships` tests and `dbt_utils.expression_is_true` checks with the `arguments:` key, with semantic models and metrics in the same files. `packages.yml` pulls `dbt_utils` 1.4.1 and `dbt-audit-helper` from git, pinned in `package-lock.yml`. `macros/cents_to_dollars.sql` dispatches by adapter with `default`, `postgres`, `bigquery` and `fabric` versions, and `macros/generate_schema_name.sql` sends seeds to `raw` and prefixes custom schemas only when the target is `prod`.

The existing CI is dbt Cloud. `.github/workflows/ci.yml` runs on pull requests to `main` and `staging` and has three jobs, Snowflake, BigQuery and Postgres, each on `macos-latest`, each installing `requirements.txt` with uv and running `.github/workflows/scripts/dbt_cloud_run_job.py`, which POSTs to the dbt Cloud API with the branch and a `schema_override` of `dbt_jsdx__pr_<branch>` and polls the run until it succeeds or fails. `cd_prod.yml` and `cd_staging.yml` do the same on pushes. That needs a `DBT_CLOUD_API_KEY` secret and the three Cloud projects whose ids are in the file, and the README's tip notes that dbt defers to the production manifest automatically when `dbt-cloud.project-id` and Cloud credentials are present. A fork or a team without that account has no CI at all, which is what the agent adds: a dbt Core job that builds only what a pull request changed, next to the Cloud jobs rather than replacing them.

Slim CI needs three things, and the agent builds each from what the repository already has. First, a production manifest: a new `dbt-core-prod.yml` on pushes to `main` starts a `postgres:16` service, writes a `profiles.yml` for the `default` profile with a `prod` target, runs `dbt deps`, `dbt seed --vars '{"load_source_data": true}'` so the six CSVs under `seeds/jaffle-data` land in `raw`, then `dbt build`, and uploads `target/manifest.json` as an artifact named `prod-manifest`. Second, the pull request job in `dbt-core-ci.yml`: the same service and profile with a `ci` target whose schema is `ci_pr_` plus the pull request number, `dbt deps` and the seed step, then a download of the newest `prod-manifest` artifact from `main` into `prod-state/`, and `dbt build --select state:modified+ --defer --state prod-state --target ci`, so an edit to `stg_orders.sql` builds `stg_orders`, `orders`, `order_items`, `customers` and `locations` with their tests and reads everything else from the production schema. When no artifact exists yet, the job falls back to a full `dbt build` and says so in the log. Third, cleanup: a job on `pull_request` `closed` that drops the `ci_pr_<number>` schema.

The agent proves the workflow in the sandbox before pushing it. It starts a Postgres container, writes the same `profiles.yml`, runs the `prod` sequence and keeps `target/manifest.json`, then edits one staging model, runs the `ci` command against that manifest and checks that `dbt ls --select state:modified+ --state prod-state` lists the model and its descendants and nothing else, and that `--defer` resolved the untouched refs to the `prod` schema in the compiled SQL under `target/compiled`. It confirms the `postgres__cents_to_dollars` dispatch is what the staging models compile to, which is why the Postgres path works without edits. It also runs `pre-commit run --all-files`, since the repository's `.pre-commit-config.yaml` runs `ruff` and whitespace hooks on every file, including the new YAML.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Add Slim CI with dbt Core and GitHub Actions to this dbt project, alongside the existing dbt Cloud workflows, without changing them. Read dbt_project.yml, packages.yml, package-lock.yml, the models and their YAML, macros/, seeds/, .github/workflows/ci.yml and the script it runs, Taskfile.yml and .pre-commit-config.yaml first. Add two workflows. The first runs on pushes to main: start a Postgres service, write a profiles.yml for the default profile with a prod target, run dbt deps, dbt seed with load_source_data true, and dbt build, then upload target/manifest.json as an artifact named prod-manifest. The second runs on pull requests: the same service and profile with a ci target whose schema is ci_pr_ plus the pull request number, dbt deps and the seed step, download the newest prod-manifest artifact from main into prod-state/, and run dbt build --select state:modified+ --defer --state prod-state --target ci; when no artifact exists, run a full dbt build and say so in the log. Add a job on pull request close that drops the ci_pr_<number> schema. Prove it in the sandbox: run the prod sequence against a local Postgres, keep the manifest, change one staging model, and show with dbt ls --select state:modified+ --state prod-state and the compiled SQL under target/compiled that only that model and its descendants build and that other refs defer to the prod schema. Run pre-commit run --all-files. Open a pull request that pastes the dbt ls output and the relevant compiled SQL, lists the models that would build for the example change, and quotes every command you ran with its 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 two new workflow files under `.github/workflows`, a CI `profiles.yml` with `prod` and `ci` targets, and no change to `ci.yml`, `cd_prod.yml`, `cd_staging.yml`, the models or the macros. The body pastes the `dbt ls --select state:modified+` output for the example change, the compiled SQL showing untouched refs resolved to the `prod` schema, and the `dbt deps`, `dbt seed`, `dbt build` and `pre-commit` commands with their output from the sandbox.

On the pull request itself the new job runs for the first time. Because no `prod-manifest` artifact exists until `main` has run the production workflow, that first run takes the full-build path and says so in its log; after the merge, the production workflow uploads the manifest and the next pull request builds only what it changed. The dbt Cloud jobs run as before for repositories that have the secret.

A reviewer checks three things: that the `ci` target's schema is per pull request and dropped on close, that the state selection includes tests through `state:modified+` so a changed model's `unique` and `relationships` tests run, and that the seed step is what makes the `raw` source tables exist in the service container, since without it every `stg_` model fails on a missing source.

## Run it on every dbt project without a Core CI workflow

A team with several dbt projects starts one run per repository: `POST /o/{org}/sessions` with this prompt and that repository in `resources`, with a `request_id` per repository so a retried request returns the run it already started. Each run reads its own `dbt_project.yml` and macros, so a project whose macros dispatch for Postgres gets the Postgres service and one that does not gets a note explaining what would need a dispatch first.

A `webhook_url` on the API key receives `run.completed` with `data.session_url` when each turn ends. A follow-up on `POST /o/{org}/sessions/{id}/messages` after the turn finishes wakes the same sandbox, for example to switch the service to another warehouse's adapter or to add a `dbt source freshness` step.

## Why run it on Rush?

Slim CI is three moving parts that are hard to test from a laptop: an artifact handed from one workflow to another, a state comparison that depends on an exact manifest, and a deferral that only shows in compiled SQL. In a Rush sandbox the agent runs the production sequence, keeps the manifest, makes a change and reads `target/compiled` to show which refs deferred, and all of that is in the transcript before the workflow ever runs on GitHub.

A project with a dozen models can build in full without anyone noticing, and the point of Slim CI is the day it can no longer do that. Adding it now, with the evidence that the selection and the deferral behave, is cheaper than adding it when every pull request already takes too long.

## Frequently asked questions

### Why not change the existing dbt Cloud CI instead?

The Cloud jobs already defer to the production environment for teams that have the account and the `DBT_CLOUD_API_KEY` secret, and they run on three warehouses. The new workflows run dbt Core on a Postgres service for forks and teams without that account, and the agent leaves `ci.yml` untouched so both paths exist.

### What happens on the first pull request, before a manifest exists?

The job looks for the newest `prod-manifest` artifact from `main`; finding none, it runs a full `dbt build` and prints a line saying why. Once the production workflow has run on `main`, the next pull request downloads the manifest and builds only `state:modified+`.

### Does the seed step make the job slow?

The seeds under `seeds/jaffle-data` are what the `ecom` source points at, so the service container needs them before any staging model can build. The agent keeps the step and records its duration in the sandbox output pasted into the pull request, so you can decide whether to load a smaller sample for CI later.

### Will the macros work on Postgres?

`cents_to_dollars` has a `postgres__` implementation and `generate_schema_name` only changes behaviour when the target is named `prod`, which the agent uses for the manifest workflow. The compiled SQL in the pull request shows the Postgres dispatch resolved.

## More dbt jobs

- [Add Snapshots to a dbt Project](https://getrush.ai/run/add-snapshots/dbt/)
- [Add Source Freshness Checks to a dbt Project](https://getrush.ai/run/add-source-freshness/dbt/)
- [Add SQLFluff Linting to a dbt Project](https://getrush.ai/run/add-sqlfluff-linting/dbt/)

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

- [Add Slow Query Logging to a Drizzle App](https://getrush.ai/run/add-slow-query-logging/drizzle/)
- [Add Slow Query Logging to a GORM App](https://getrush.ai/run/add-slow-query-logging/gorm/)
- [Add Slow Query Logging to a Mongoose App](https://getrush.ai/run/add-slow-query-logging/mongoose/)

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