Agent skill

Refactoring Dbt Models

by AltimateAI in AltimateAI/data-engineering-skills

Safely refactors dbt models with downstream impact analysis.

MITAuto-check passedData & Analytics

Install Refactoring Dbt Models

skills CLI
$ npx skills add AltimateAI/data-engineering-skills --skill refactoring-dbt-models -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install AltimateAI/data-engineering-skills refactoring-dbt-models --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/AltimateAI/data-engineering-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/dbt/refactoring-dbt-models .claude/skills/refactoring-dbt-models && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
refactoring-dbt-models
GitHub stars
128
Token cost
~1.2k tokens
SKILL.md length
303 words
Files
1
Skills in repo
12
Repo updated
First seen
Licence
MIT

At a glance

Safely refactors dbt models with downstream impact analysis.

  • Works in 8 steps: Analyze Current Model → Find All Downstream Dependencies → Check What Columns Downstream Models Use → …
  • Restructuring dbt models for:
  • SKILL.md covers Workflow, Refactoring Checklist, Common Refactoring Triggers and Anti-Patterns
  • Calls dbt

What it does

Refactoring Dbt Models is an agent skill from AltimateAI/data-engineering-skills. Safely refactors dbt models with downstream impact analysis. Use when restructuring dbt models for: (1) Task mentions "refactor", "restructure", "extract", "split", "break into", or "reorganize" (2) Extracting CTEs to intermediate models or creating macros (3) Modifying model logic that has downstream consumers (4) Renaming columns, changing types, or reorganizing model dependencies Analyzes all downstream dependencies BEFORE making changes.

Its SKILL.md is about 1.2k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Data & Analytics, covering Data pipelines and ETL and Refactoring. It works with dbt. The repository describes itself as: Skills related to Data Engineering Work for Claude Code. The licence is MIT.

When your agent uses it

  • Restructuring dbt models for:
  • Task mentions refactor
  • Extracting CTEs to intermediate models
  • Creating macros

Example prompts

  • “refactor”
  • “restructure”
  • “extract”
  • “/refactoring-dbt-models”

Workflow steps

8 steps, taken from the step headings in SKILL.md.

  1. Analyze Current Model
  2. Find All Downstream Dependencies
  3. Check What Columns Downstream Models Use
  4. Plan Refactoring Strategy
  5. Execute Refactoring
  6. Validate Changes
  7. Verify Output Matches Original
  8. Update Downstream Models

What it can do on your machine

Read from SKILL.md and the folder at commit 705c68b. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • dbt

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Refactoring Dbt Models loads about 1.2k tokens when it runs. Until then it costs about 117 tokens; SKILL.md has 303 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~117
When it runs · the whole SKILL.md, loaded when a task matches
~1.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from AltimateAI/data-engineering-skills at commit 705c68b, republished under its MIT licence (© AltimateAI). 303 words, ~1,177 tokens.

Download SKILL.mdSave it as .claude/skills/refactoring-dbt-models/SKILL.md (or your agent's skills folder).
name
refactoring-dbt-models
description
Safely refactors dbt models with downstream impact analysis. Use when restructuring dbt models for: (1) Task mentions "refactor", "restructure", "extract", "split", "break into", or "reorganize" (2) Extracting CTEs to intermediate models or creating macros (3) Modifying model logic that has downstream consumers (4) Renaming columns, changing types, or reorganizing model dependencies Analyzes all downstream dependencies BEFORE making changes.

dbt Refactoring

Find ALL downstream dependencies before changing. Refactor in small steps. Verify output after each change.

Workflow

1. Analyze Current Model
bash
cat models/<path>/<model_name>.sql

Identify refactoring opportunities:

  • CTEs longer than 50 lines → extract to intermediate model
  • Logic repeated across models → extract to macro
  • Multiple joins in sequence → split into steps
  • Complex WHERE clauses → extract to staging filter
2. Find All Downstream Dependencies

CRITICAL: Never refactor without knowing impact.

bash
# Get full dependency tree (model and all its children)
dbt ls --select model_name+ --output list

# Find all models referencing this one
grep -r "ref('model_name')" models/ --include="*.sql"

Report to user: "Found X downstream models: [list]. These will be affected by changes."

3. Check What Columns Downstream Models Use

BEFORE changing any columns, check what downstream models reference:

bash
# For each downstream model, check what columns it uses
cat models/<path>/<downstream_model>.sql | grep -E "model_name\.\w+|alias\.\w+"

If downstream models reference specific columns, you MUST ensure those columns remain available after refactoring.

4. Plan Refactoring Strategy
OpportunityStrategy
Long CTEExtract to intermediate model
Repeated logicCreate macro in macros/
Complex joinSplit into intermediate models
Multiple concernsSeparate into focused models
5. Execute Refactoring
Pattern: Extract CTE to Model

Before:

sql
-- orders.sql (200 lines)
with customer_metrics as (
    -- 50 lines of complex logic
),
order_enriched as (
    select ...
    from orders
    join customer_metrics on ...
)
select * from order_enriched

After:

sql
-- customer_metrics.sql (new file)
select
    customer_id,
    -- complex logic here
from {{ ref('customers') }}

-- orders.sql (simplified)
with order_enriched as (
    select ...
    from {{ ref('raw_orders') }} orders
    join {{ ref('customer_metrics') }} cm on ...
)
select * from order_enriched
Pattern: Extract to Macro

Before (repeated in multiple models):

sql
case
    when amount < 0 then 'refund'
    when amount = 0 then 'zero'
    else 'positive'
end as amount_category

After:

sql
-- macros/categorize_amount.sql
{% macro categorize_amount(column_name) %}
case
    when {{ column_name }} < 0 then 'refund'
    when {{ column_name }} = 0 then 'zero'
    else 'positive'
end
{% endmacro %}

-- In models:
{{ categorize_amount('amount') }} as amount_category
6. Validate Changes
bash
# Compile to check syntax
dbt compile --select +model_name+

# Build entire lineage
dbt build --select +model_name+

# Check row counts (manual)
# Before: Record expected counts
# After: Verify counts match
7. Verify Output Matches Original

CRITICAL: Refactoring should not change output.

bash
# Compare row counts before and after
dbt show --inline "select count(*) from {{ ref('model_name') }}"

# Spot check key values
dbt show --select <model_name> --limit 10
8. Update Downstream Models

If changing output columns:

  1. Update all downstream refs
  2. Update schema.yml documentation
  3. Re-run downstream tests

Refactoring Checklist

  • All downstream dependencies identified
  • User informed of impact scope
  • One change at a time
  • Compile passes after each change
  • Build passes after each change
  • Output validated (row counts match)
  • Documentation updated
  • Tests still pass

Common Refactoring Triggers

SymptomRefactoring
Model > 200 linesExtract CTEs to models
Same logic in 3+ modelsExtract to macro
5+ joins in one modelCreate intermediate models
Hard to understandAdd CTEs with clear names
Slow performanceSplit to allow parallelization

Anti-Patterns

  • Refactoring without checking downstream impact
  • Making multiple changes at once
  • Not validating output matches after refactoring
  • Extracting prematurely (wait for 3+ uses)
  • Breaking existing tests without updating them

© AltimateAI, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/dbt/refactoring-dbt-models of AltimateAI/data-engineering-skills.

Open the folder on GitHubat commit 705c68b

Compare with similar skills

Refactoring Dbt Models next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Refactoring Dbt Models compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Refactoring Dbt Models this skillAltimateAI/data-engineering-skills128—~1.2kAutomated safety check: PassMIT
Deploying Airflowastronomer/agents4511 repos~2.8kAutomated safety check: PassApache-2.0
R Empirical Financeaspi6246/Claude-Code-Skills-for-Academics159—~1.3kAutomated safety check: PassNone
Configuring Dbt MCP ServerKilo-Org/kilo-marketplace190—~2.5kAutomated safety check: NotesApache-2.0
Dbt Databricks PR Readydatabricks/dbt-databricks380—~2.8kAutomated safety check: PassApache-2.0
Mz Dbt ReleaseMaterializeInc/materialize6.4k—~1.2kAutomated safety check: PassCustom licence

Similar skills

  • Deploying Airflow

    astronomer/agents

    Deploys Airflow DAGs and projects. An agent skill from astronomer/agents.

    451 GitHub starsUsed in 1 repo~2.8k tokens
    Data & AnalyticsAuto-check passed
  • R Empirical Finance

    aspi6246/Claude-Code-Skills-for-Academics

    Conventions for writing empirical finance R code with data.table, fixest, arrow, and ggplot2.

    159 GitHub stars~1.3k tokensUpdated 1 mo ago
    Data & AnalyticsAuto-check passed
  • Configuring Dbt MCP Server

    Kilo-Org/kilo-marketplace

    Generates MCP server configuration JSON, resolves authentication setup, and validates server connectivity for dbt.

    190 GitHub stars~2.5k tokensUpdated 10 days ago
    Data & AnalyticsAuto-check: notes
  • Dbt Databricks PR Ready

    databricks/dbt-databricks

    Official

    A skill your agent uses for an open dbt-databricks pull request, including your own PR or a fork PR, to assess merge readiness and optionally repair selected gaps on the PR head branch.

    380 GitHub stars~2.8k tokensUpdated today
    Data & AnalyticsAuto-check passed
  • Mz Dbt Release

    MaterializeInc/materialize

    Cut a dbt-materialize PyPI release: bump the version in version.py and setup.py, date the Unreleased CHANGELOG entry, and open the release PR with a Ship: <url body.

    6.4k GitHub stars~1.2k tokensUpdated today
    Data & AnalyticsAuto-check passed
  • Erd Studio Setup

    liam-machine/erd-studio

    Friendly, step-by-step setup for ERD Studio in an existing dbt project, for people who may be new to dbt or data modelling.

    165 GitHub stars~8.5k tokensUpdated today
    Data & AnalyticsAuto-check passed

More from AltimateAI/data-engineering-skills

All 12 skills in this repo
  • Altimate Data Warehouse Delegate

    AltimateAI/data-engineering-skills

    Delegates dbt and warehouse tasks such as lineage, migrations and cost attribution to the altimate-code CLI agent and relays its answer back.

    128 GitHub stars~1.4k tokensUpdated yesterday
    Auto-check passed
  • dbt Model Builder

    AltimateAI/data-engineering-skills

    Creates or modifies dbt models in line with a project's own conventions, then runs dbt build and dbt show to check the output instead of stopping at compile.

    128 GitHub stars~890 tokensUpdated yesterday
    Auto-check passed
  • dbt Error Debugging

    AltimateAI/data-engineering-skills

    Walks through fixing dbt compilation, database and test errors: read the full error, check upstream models, apply a fix, then verify with dbt build and a data preview.

    128 GitHub stars~1.1k tokensUpdated yesterday
    Auto-check passed
  • dbt Incremental Models

    AltimateAI/data-engineering-skills

    Helps choose an incremental strategy, design a reliable unique_key and debug failing dbt incremental models, and says when a plain table is the better choice.

    128 GitHub stars~2.3k tokensUpdated yesterday
    Auto-check passed
  • dbt Model Documentation

    AltimateAI/data-engineering-skills

    Writes model and column descriptions in dbt schema.yml files, matching the project's existing documentation style and recording grain, business rules and caveats.

    128 GitHub stars~1.2k tokensUpdated yesterday
    Auto-check passed
  • Expensive Snowflake Query Finder

    AltimateAI/data-engineering-skills

    Ranks the costliest, slowest or heaviest-scanning Snowflake queries from query history and suggests how to optimize them.

    128 GitHub stars~662 tokensUpdated yesterday
    Auto-check passed

Works with

Questions about Refactoring Dbt Models

What does Refactoring Dbt Models do?

Safely refactors dbt models with downstream impact analysis. Refactoring Dbt Models is an agent skill from AltimateAI/data-engineering-skills. Safely refactors dbt models with downstream impact analysis.

When should I use Refactoring Dbt Models?

Refactoring Dbt Models fits situations like: restructuring dbt models for:; task mentions refactor; extracting CTEs to intermediate models; creating macros.

How do I install Refactoring Dbt Models in Claude Code?

Run `npx skills add AltimateAI/data-engineering-skills --skill refactoring-dbt-models -a claude-code`. Or copy the skill folder (skills/dbt/refactoring-dbt-models in AltimateAI/data-engineering-skills) into .claude/skills/refactoring-dbt-models in your project. Claude Code loads it when a task matches its description.

How do I install Refactoring Dbt Models in Codex?

Run `npx skills add AltimateAI/data-engineering-skills --skill refactoring-dbt-models -a codex`. Or copy the skill folder (skills/dbt/refactoring-dbt-models in AltimateAI/data-engineering-skills) into .agents/skills/refactoring-dbt-models in your project. Codex loads it when a task matches its description.

Can I use Refactoring Dbt Models in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add AltimateAI/data-engineering-skills --skill refactoring-dbt-models -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/refactoring-dbt-models, .gemini/skills/refactoring-dbt-models, .github/skills/refactoring-dbt-models and .opencode/skills/refactoring-dbt-models in your project.

What does Refactoring Dbt Models need to run?

Going by SKILL.md and its folder, Refactoring Dbt Models needs the command-line tools its instructions call (dbt).

Does Refactoring Dbt Models access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Refactoring Dbt Models safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Refactoring Dbt Models use?

Refactoring Dbt Models is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Refactoring Dbt Models use?

About 1.2k tokens (SKILL.md is roughly 4.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Refactoring Dbt Models?

Skills that share tags, products or a category with Refactoring Dbt Models: Deploying Airflow (astronomer/agents, 451 stars), R Empirical Finance (aspi6246/Claude-Code-Skills-for-Academics, 159 stars), Configuring Dbt MCP Server (Kilo-Org/kilo-marketplace, 190 stars) and Dbt Databricks PR Ready (databricks/dbt-databricks, 380 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Refactoring Dbt Models?

AltimateAI (a GitHub organization) maintains it in AltimateAI/data-engineering-skills, which has 128 GitHub stars. The repository holds 12 skills in this directory. The repository was last updated on October 8, 2026.

Source: AltimateAI/data-engineering-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.