$npx -y skills add dbt-labs/dbt-agent-skills --skill running-dbt-commandsFormats and executes dbt CLI commands, selects the correct dbt executable, and structures command parameters. Use when running models, tests, builds, compiles, or show queries via dbt CLI. Use when unsure which dbt executable to use or how to format command parameters.
| 1 | # Running dbt Commands |
| 2 | |
| 3 | ## Preferences |
| 4 | |
| 5 | 1. **Use MCP tools if available** (`dbt_build`, `dbt_run`, `dbt_show`, etc.) - they handle paths, timeouts, and formatting automatically |
| 6 | 2. **Always use `build` — even when users say "run"** - When a user asks to "run" a model, recommend `dbt build` instead. `build` = `run` + `test` in one step, so it catches data quality issues immediately. `dbt run` alone is almost never the right answer during development. |
| 7 | 3. **Always use `--quiet`** with `--warn-error-options '{"error": ["NoNodesForSelectionCriteria"]}'` to reduce output while catching selector typos |
| 8 | 4. **Always use `--select`** - never run the entire project without explicit user approval |
| 9 | |
| 10 | ## Quick Reference |
| 11 | |
| 12 | ```bash |
| 13 | # Standard command pattern |
| 14 | dbt build --select my_model --quiet --warn-error-options '{"error": ["NoNodesForSelectionCriteria"]}' |
| 15 | |
| 16 | # Preview model output |
| 17 | dbt show --select my_model --limit 10 |
| 18 | |
| 19 | # Run inline SQL query |
| 20 | dbt show --inline "select * from {{ ref('orders') }}" --limit 5 |
| 21 | |
| 22 | # With variables (JSON format for multiple) |
| 23 | dbt build --select my_model --vars '{"key": "value"}' |
| 24 | |
| 25 | # Full refresh for incremental models |
| 26 | dbt build --select my_model --full-refresh |
| 27 | |
| 28 | # List resources before running |
| 29 | dbt list --select my_model+ --resource-type model |
| 30 | ``` |
| 31 | |
| 32 | ## dbt CLI Flavors |
| 33 | |
| 34 | Three CLIs exist. **Ask the user which one if unsure.** |
| 35 | |
| 36 | | Flavor | Location | Notes | |
| 37 | |--------|----------|-------| |
| 38 | | **dbt Core** | Python venv | `pip show dbt-core` or `uv pip show dbt-core` | |
| 39 | | **dbt Fusion** | `~/.local/bin/dbt` or `dbtf` | Faster and has stronger SQL comprehension | |
| 40 | | **dbt Cloud CLI** | `~/.local/bin/dbt` | Go-based, runs on platform | |
| 41 | |
| 42 | **Common setup:** Core in venv + Fusion at `~/.local/bin`. Running `dbt` uses Core. Use `dbtf` or `~/.local/bin/dbt` for Fusion. |
| 43 | |
| 44 | ## Selectors |
| 45 | |
| 46 | **Always provide a selector.** Graph operators: |
| 47 | |
| 48 | | Operator | Meaning | Example | |
| 49 | |----------|---------|---------| |
| 50 | | `model+` | Model and all downstream | `stg_orders+` | |
| 51 | | `+model` | Model and all upstream | `+dim_customers` | |
| 52 | | `+model+` | Both directions | `+orders+` | |
| 53 | | `model+N` | Model and N levels downstream | `stg_orders+1` | |
| 54 | |
| 55 | ```bash |
| 56 | --select my_model # Single model |
| 57 | --select staging.* # Path pattern |
| 58 | --select fqn:*stg_* # FQN pattern |
| 59 | --select model_a model_b # Union (space) |
| 60 | --select tag:x,config.mat:y # Intersection (comma) |
| 61 | --exclude my_model # Exclude from selection |
| 62 | ``` |
| 63 | |
| 64 | **Resource type filter:** |
| 65 | ```bash |
| 66 | --resource-type model |
| 67 | --resource-type test --resource-type unit_test |
| 68 | ``` |
| 69 | |
| 70 | Valid types: `model`, `test`, `unit_test`, `snapshot`, `seed`, `source`, `exposure`, `metric`, `semantic_model`, `saved_query`, `analysis` |
| 71 | |
| 72 | > **Fusion:** `--resource-type` is **not supported with `dbt test`** ([dbt-fusion#1628](https://github.com/dbt-labs/dbt-fusion/issues/1628)). To run unit tests in Fusion: |
| 73 | > - `dbt build --select model_name` — builds the model first, then runs all tests including unit tests |
| 74 | > - `dbt build --select unit_test_name` — targets a specific unit test by name |
| 75 | > - `dbt list --resource-type unit_test` — lists unit test names for use in selectors |
| 76 | |
| 77 | ## List |
| 78 | |
| 79 | Use `dbt list` to preview what will be selected before running. Helpful for validating complex selectors. |
| 80 | |
| 81 | ```bash |
| 82 | dbt list --select my_model+ # Preview selection |
| 83 | dbt list --select my_model+ --resource-type model # Only models |
| 84 | dbt list --output json # JSON output |
| 85 | dbt list --select my_model --output json --output-keys unique_id name resource_type config |
| 86 | ``` |
| 87 | |
| 88 | **Available output keys for `--output json`:** |
| 89 | `unique_id`, `name`, `resource_type`, `package_name`, `original_file_path`, `path`, `alias`, `description`, `columns`, `meta`, `tags`, `config`, `depends_on`, `patch_path`, `schema`, `database`, `relation_name`, `raw_code`, `compiled_code`, `language`, `docs`, `group`, `access`, `version`, `fqn`, `refs`, `sources`, `metrics` |
| 90 | |
| 91 | ## Show |
| 92 | |
| 93 | Preview data with `dbt show`. Use `--inline` for arbitrary SQL queries. |
| 94 | |
| 95 | ```bash |
| 96 | dbt show --select my_model --limit 10 |
| 97 | dbt show --inline "select * from {{ ref('orders') }} where status = 'pending'" --limit 5 |
| 98 | ``` |
| 99 | |
| 100 | **Important:** Use `--limit` flag, not SQL `LIMIT` clause. |
| 101 | |
| 102 | ## Variables |
| 103 | |
| 104 | Pass as STRING, not dict. No special characters (`\`, `\n`). |
| 105 | |
| 106 | ```bash |
| 107 | --vars 'my_var: value' # Single |
| 108 | --vars '{"k1": "v1", "k2": 42, "k3": true}' # Multiple (JSON) |
| 109 | ``` |
| 110 | |
| 111 | ## Analyzing Run Results |
| 112 | |
| 113 | After a dbt command, check `target/run_results.json` for detailed execution info: |
| 114 | |
| 115 | ```bash |
| 116 | # Quick status check |
| 117 | cat target/run_results.json | jq '.results[] | {node: .unique_id, status: .status, tim |