This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Spellbook is Dune Analytics' open-source interpretation layer for blockchain data. It's a dbt monorepo that transforms raw blockchain data into clean, usable datasets ("spells") using SQL + Jinja2 templating on DuneSQL (Trino-based).
The repo is organized as multiple independent dbt sub-projects under dbt_subprojects/:
daily_spellbook— Default location for new spells (daily refresh)hourly_spellbook— Promoted spells with higher frequency (requires Dune team approval)dex— DEX and DEX aggregator trading data (includesdex.trades)nft— NFT-related modelssolana— Solana-specific modelstokens— Token metadata, transfers, and balances
Each sub-project is self-contained with its own dbt_project.yml, profiles.yml, models/, macros/, seeds/, and tests/.
Shared resources live at the repo root:
sources/— 170+ source YAML files (raw table definitions)dbt_macros/— Shared macros (expose_spells,optimize_spell,mark_as_spell,enforce_join_distribution,incremental_predicate, etc.)scripts/— Development utilities (query runner, source generators)docs/— Internal documentation on models, tests, seeds, macros, CI, best practices
uv sync --locked # Create/update .venv with locked dependenciescd dbt_subprojects/<subproject>/
uv run dbt clean # Clean old artifacts
uv run dbt deps # Pull dbt dependencies
uv run dbt compile # Compile Jinja/SQL to plain SQL in target/# Run dbt tests for a model
uv run dbt test --select @model_name
# Compile and run a dbt model against Dune API
uv run python scripts/dune_query.py "@model_name" --limit 100
# Run raw SQL against Dune
uv run python scripts/dune_query.py "SELECT * FROM dex.trades LIMIT 10"
# Run SQL from file
uv run python scripts/dune_query.py --sql-file query.sqlThe dune_query.py script requires a DUNE_API_KEY in .env. It auto-detects the correct sub-project directory for @model_name syntax.
uv run pre-commit install --hook-type pre-push
uv run pre-commit run --hook-stage manual # Manual runPRs trigger GitHub Actions that run dbt slim ci — only modified models are tested. Each sub-project has its own workflow file (e.g., dex.yml, tokens.yml), all calling the shared reusable workflow in dbt_run.yml. Test results appear in tables named test_schema.git_dunesql_<commit_hash>_<table_name> (available ~24 hours).