Skip to main content

Agent-friendly companion utilities for dbt-cloud-cli — solves the multi-step-job artifact trap

Project description

dbtcx

Agent-friendly companion to dbt-cloud-cli — solves the multi-step-job artifact trap.

The problem this solves

dbt-cloud-cli defaults to last-step artifacts when you call dbt-cloud run get-artifact. For any dbt Cloud job that ends with dbt docs generate (so: virtually every production job), the resulting run_results.json has empty adapter_response on every row. The BigQuery / Snowflake / Redshift job ID, slot_ms, bytes_processed — all live in adapter_response for the actual dbt run / dbt build step. So post-run diagnostic pulls are useless without manual step discovery.

dbtcx fetch-run probes the run's steps until it finds the materialization step (args.which ∈ {run, build, seed, snapshot} AND ≥1 non-empty adapter_response), and pulls artifacts from THAT step.

Quickstart

pip install dbtcx
# or
uv pip install dbtcx

Configure (token from dbt Cloud → Settings → API Tokens):

cat > .env <<'EOF'
DBT_CLOUD_API_TOKEN=dbtu_...
DBT_CLOUD_ACCOUNT_ID=12345
DBT_CLOUD_HOST=cloud.getdbt.com    # bare hostname, no scheme
EOF

Pull diagnostic artifacts for a run (auto-detect materialization step):

dbtcx fetch-run 12345678

Bundle a model's compiled SQL too:

dbtcx fetch-run 12345678 --model-path 'compiled/<project>/models/marts/my_model.sql'

Output → ./artifacts/run_<run_id>/:

  • run_results.json — pulled from the materialization step (adapter_response populated)
  • manifest.json — full project state
  • manifest.slim.json — agent-friendly index (no compiled SQL bodies; node deps + materialization + schema only)
  • <model>.compiled.sql — if --model-path was given (falls back to default-step if not in materialization bundle)
  • .step_used — marker file noting which step the artifacts came from

CLI

dbtcx fetch-run

dbtcx fetch-run <run_id> [--step N] [--model-path PATH] [--out-dir DIR] [--force] [--max-probe-steps N]
  • --step N — manual override (skip auto-detect)
  • --force — re-download even if files exist
  • --out-dir — default ./artifacts/run_<id>/
  • --max-probe-steps — default 15

Idempotent: re-runs skip existing files unless --force. If the resolved step changes between runs (e.g. you pass --step 4 after a default auto-detect), the previous artifacts are cleared to avoid mixing step-specific files.

dbtcx proxy

dbtcx proxy <dbt-cloud-cli args>

Pass-through to dbt-cloud with .env already loaded. Examples:

dbtcx proxy run list --job-id 12345 --order-by '-id' --limit 5
dbtcx proxy account get
dbtcx proxy job list --account-id 12345

dbt-cloud-cli reads DBT_CLOUD_API_TOKEN / DBT_CLOUD_ACCOUNT_ID / DBT_CLOUD_HOST natively — no flag plumbing.

Why agents love this

When a coding agent (Claude Code, Cursor, Aider, etc.) is asked to "diagnose why this dbt model is slow", the workflow is:

  1. Find the latest production run.
  2. Pull run_results.json to get adapter_response.job_id for the model.
  3. Dump the warehouse query plan.
  4. Rank hot stages.

Step 2 is where dbt-cloud-cli quietly fails on multi-step prod jobs — the agent gets adapter_response: {} and burns N round-trips figuring out which step it actually needed. dbtcx fetch-run collapses all that to one call, with progress logs that tell the agent exactly which step won.

Configuration reference

Var Required Notes
DBT_CLOUD_API_TOKEN yes Service token (dbtu_...) from dbt Cloud → Settings → API Tokens
DBT_CLOUD_ACCOUNT_ID yes Numeric account ID (visible in the URL after /accounts/)
DBT_CLOUD_HOST yes Bare hostname only — no https://. Multi-tenant US: cloud.getdbt.com; single-tenant US: <prefix>.us1.dbt.com; EMEA: emea.dbt.com; AU: au.dbt.com
DBT_CLOUD_READONLY no When true, suppresses destructive subcommands

.env is loaded from the current working directory by default. Use --env-file PATH to point elsewhere:

dbtcx --env-file ~/.config/dbtcx/prod.env fetch-run 12345678

Development

git clone https://github.com/luutuankiet/dbtcx.git
cd dbtcx
uv venv
uv pip install -e ".[dev]"
pytest

Acknowledgements

Wraps dbt-cloud-cli by data-mie. This package adds the multi-step-aware fetcher + a thin env-loader pass-through; everything else delegates to the upstream CLI.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbtcx-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dbtcx-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file dbtcx-0.1.0.tar.gz.

File metadata

  • Download URL: dbtcx-0.1.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dbtcx-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cc7b85714f5993ad8913d482b242ce2da2c565535e3e5e7cd87ae9ca309f0941
MD5 5ca58cf1d738dd2bf5039764444636f1
BLAKE2b-256 264748bdeb8839e10c3f181734e2e1e32a1f30149fa77d0dd1ad11adb700de3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbtcx-0.1.0.tar.gz:

Publisher: release.yaml on luutuankiet/dbtcx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dbtcx-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dbtcx-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dbtcx-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cac9997afcd924c24015f78bc2d53f91ee4d50aac0638326385958aff2c32cad
MD5 5ec3f7a3143fb521013efc9efb735c23
BLAKE2b-256 a433892d2ed5f1962cbdc21541f115e4121bf100341325b2d54eb464cc30ac02

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbtcx-0.1.0-py3-none-any.whl:

Publisher: release.yaml on luutuankiet/dbtcx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page