How to Use Hooks in dbt

Last updated July 25, 2026 · By the SaturnSQL team

pre-hook and post-hook run SQL before or after a single model builds, configured in the model or dbt_project.yml. on-run-start and on-run-end run once per invocation, project-wide. Typical uses: grants, audit rows, and warehouse session settings.

Model-level hooks

{{ config(
    post_hook="GRANT SELECT ON {{ this }} TO ROLE reporter"
) }}

Project-level hooks

# dbt_project.yml
on-run-start:
  - "INSERT INTO audit.run_log (started_at) VALUES (current_timestamp)"
on-run-end:
  - "{{ grant_select_on_schemas(schemas, 'reporter') }}"

models:
  my_project:
    +post-hook: "ANALYZE TABLE {{ this }}"

Inside hooks, {{ this }} resolves to the model being built. on-run-end additionally exposes the schemas and results context variables.

Run this in SaturnSQL

SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.

Try it free

Related dbt guides

© 2026 Panda Capital Oy Ab. All rights reserved.