Skip to content

Repository files navigation

Claude dbt Package

This dbt package transforms data from Fivetran's Claude connector into analytics-ready tables covering API cost reporting, message usage, Claude Code activity, and enterprise user management.

Resources

What does this dbt package do?

This package enables you to understand Claude API cost and usage, Claude Code developer activity, and enterprise user cost and engagement at your company. It allocates organization-level cost down to the API key that consumed it, joins per-user enterprise cost to per-user token usage, and rolls up cost, usage, and product activity into a single summary per enterprise user.

This package is also designed to roll up alongside Fivetran's OpenAI dbt package into the AI Reporting package, which combines Claude and OpenAI data into unified, cross-vendor AI usage and cost reporting models.

Output schema

Final output tables are generated in the following target schema:

<your_database>.<connector/schema_name>_claude

Final output tables

By default, this package materializes the following final tables:

Table Description
claude__platform_cost_usage_report Organization cost allocated down to the API key that consumed it, joined with API message usage. One row per API key, day, model, cost type and token type.

Example Analytics Questions:
  • Which API keys or workspaces are driving the most Claude API spend?
  • How is cost split between input, output, and cache tokens by model?
  • What share of cost can't be attributed to a specific API key, and why?
claude__enterprise_cost_usage_report Enterprise per-user cost joined to per-user token usage. One row per actor, day, product, model, cost type and token type.

Example Analytics Questions:
  • Which actors or products are consuming the most enterprise cost and tokens?
  • How does per-user Claude spend trend over time by model?
  • Which users have usage but no matching cost, or vice versa?
claude__code_report Claude Code activity, one row per actor, day, terminal type and customer type.

Example Analytics Questions:
  • Which developers or API keys are most active with Claude Code, by sessions, commits, and pull requests?
  • How many lines of code are being added and removed through Claude Code, and by whom?
  • What is the estimated Claude Code cost per session?
claude__user_summary One row per enterprise actor, summarizing cost, usage and product activity over two windows: all time and the current calendar month.

Example Analytics Questions:
  • Which users are the heaviest Claude spenders or most active this month versus all time?
  • How many workspaces does each user belong to, and what roles do they hold?
  • Which enterprise actors have no matching workspace user record (offboarded people or API-only actors)?

¹ Each Quickstart transformation job run materializes these models if all components of this data model are enabled. This count includes all staging, intermediate, and final models materialized as view, table, or incremental.


Prerequisites

To use this dbt package, you must have the following:

  • At least one Fivetran Claude connection syncing data into your destination.
  • A BigQuery, Snowflake, Redshift, PostgreSQL, Databricks, or DuckDB destination.

How do I use the dbt package?

You can either add this dbt package in the Fivetran dashboard or import it into your dbt project:

  • To add the package in the Fivetran dashboard, follow our Quickstart guide.
  • To add the package to your dbt project, follow the setup instructions in the dbt package's README file to use this package.

Install the package (skip if also using the ai_reporting combo package)

Include the following claude package version in your packages.yml file if you are not also using the upstream AI Reporting combination package:

TIP: Check dbt Hub for the latest installation instructions or read the dbt docs for more information on installing packages.

packages:
  - package: fivetran/claude
    version: [">=0.1.0", "<0.2.0"]

Define database and schema variables

Option A: Single connection

By default, this package runs using your destination and the anthropic_claude schema. If this is not where your Claude data is (for example, if your Claude schema is named claude_fivetran), add the following configuration to your root dbt_project.yml file:

vars:
    claude_database: your_destination_name
    claude_schema: your_schema_name

Option B: Union multiple connections

If you have multiple Claude connections in Fivetran and would like to use this package on all of them simultaneously, we have provided functionality to do so. For each source table, the package will union all of the data together and pass the unioned table into the transformations. The source_relation column in each model indicates the origin of each record.

To use this functionality, you will need to set the claude_sources variable in your root dbt_project.yml file:

# dbt_project.yml

vars:
  claude:
    claude_sources:
      - database: connection_1_destination_name # Required
        schema: connection_1_schema_name # Required
        name: connection_1_source_name # Required only if following the step in the following subsection

      - database: connection_2_destination_name
        schema: connection_2_schema_name
        name: connection_2_source_name

Optional: Incorporate unioned sources into DAG

If you use Fivetran Transformations for dbt Core™ and are unioning multiple Claude connections, you can define your sources in a property .yml file, using this as a template. Set the variable has_defined_sources: true under the Claude namespace in your dbt_project.yml. Otherwise, your Claude connections won't appear in your DAG. See the union_connections macro documentation for full configuration details.

Disable models for non-existent sources

Your Claude connection might not sync every table that this package expects. If your syncs exclude certain tables, it is because you either do not use that functionality in Claude or have actively excluded some tables from your syncs.

To disable the corresponding functionality in the package, you must set the relevant config variables to false. By default, all variables are set to true. Alter variables only for the tables you want to disable:

vars:
    claude__using_cost_report: false # Disable if you do not have COST_REPORT synced.
    claude__using_enterprise_user_cost_report: false # Disable if you do not have ENTERPRISE_USER_COST_REPORT synced.
    claude__using_message_usage_report: false # Disable if you do not have MESSAGE_USAGE_REPORT synced.
    claude__using_enterprise_user_usage_report: false # Disable if you do not have ENTERPRISE_USER_USAGE_REPORT synced.
    claude__using_claude_code_usage_report: false # Disable if you do not have CLAUDE_CODE_USAGE_REPORT synced.
    claude__using_claude_code_usage_report_model_breakdown: false # Disable if you do not have CLAUDE_CODE_USAGE_REPORT_MODEL_BREAKDOWN synced.
    claude__using_users: false # Disable if you do not have USERS synced.
    claude__using_enterprise_user_actor: false # Disable if you do not have ENTERPRISE_USER_ACTOR synced.
    claude__using_api_key: false # Disable if you do not have API_KEY synced.
    claude__using_enterprise_user_activity: false # Disable if you do not have ENTERPRISE_USER_ACTIVITY synced.
    claude__using_organization: false # Disable if you do not have ORGANIZATION synced. Removes the organization_name column and the join to it from the claude__code_report and claude__enterprise_cost_usage_report transform models.
    claude__using_workspace: false # Disable if you do not have WORKSPACE synced. Removes the workspace_name column and the join to it from int_claude__api_key, claude__platform_cost_usage_report, and claude__user_summary.
    claude__using_workspace_member: false # Disable if you do not have WORKSPACE_MEMBER synced. Removes the count_workspaces, workspace_names, is_workspace_admin, and is_workspace_developer columns from claude__user_summary.

(Optional) Additional configurations

Expand/Collapse details

Passing Through Additional Fields

This package includes all source columns defined in the macros folder. You can add more columns using our pass-through column variables. These variables allow for the pass-through fields to be aliased (alias) and casted (transform_sql) if desired, but not required. Datatype casting is configured via a sql snippet within the transform_sql key. You may add the desired sql while omitting the as field_name at the end and your custom pass-through fields will be casted accordingly. Use the below format for declaring the respective pass-through variables:

# dbt_project.yml

vars:
  claude__enterprise_user_activity_pass_through_metrics:
    - name: "that_field"
      alias: "renamed_to_this_field"
      transform_sql: "cast(renamed_to_this_field as string)"
    - name: "this_field"

claude__enterprise_user_activity_pass_through_metrics fields are expected to be numeric metrics; they are summed into the lifetime_<field>/month_to_date_<field> columns of claude__user_summary alongside the default activity metrics.

Please create an issue if you'd like to see passthrough column support for other tables in the Claude schema.

Configuring Cent to Dollar Conversion

The Claude API reports cost-based fields, such as amount and estimated_cost_amount, in the smallest denomination of the currency (cents, or fractional cents on some endpoints, for USD). By default, this package divides these fields by 100 in staging so every downstream cost column is in major currency units (dollars for USD) instead.

If you'd rather keep these fields in their raw, undivided form, set claude__convert_cost to false in your dbt_project.yml:

vars:
    claude__convert_cost: false # default is true

Claude cost is currently always reported in USD, so this conversion is safe and enabled by default. If Claude later reports cost in a currency with no minor unit, this variable lets you turn the conversion off without editing the package.

Changing the Build Schema

By default this package will build the Claude staging models within a schema titled (<target_schema> + _claude_staging) and the final transform models within a schema titled (<target_schema> + _claude_reports) in your target database. If this is not where you would like your Claude staging and final models to be written to, add the following configuration to your dbt_project.yml file:

models:
    claude:
      +schema: my_new_schema_name # Leave +schema: blank to use the default target_schema.
      staging:
        +schema: my_new_schema_name # Leave +schema: blank to use the default target_schema.

Change the source table references

If an individual source table has a different name than the package expects, add the table name as it appears in your destination to the respective variable:

IMPORTANT: See this project's src_claude.yml source declarations to see the expected names.

vars:
    claude_<default_source_table_name>_identifier: your_table_name

Source casing for case-sensitive destinations

By default, the package applies case-insensitive comparisons when resolving source_relation values. If your destination is case-sensitive and you want downstream transformations to respect the exact casing of your source database and schema names, set the following variable:

vars:
    fivetran_using_source_casing: true

(Optional) Orchestrate your models with Fivetran Transformations for dbt Core™

Expand for details

Fivetran offers the ability for you to orchestrate your dbt project through Fivetran Transformations for dbt Core™. Learn how to set up your project for orchestration through Fivetran in our Transformations for dbt Core setup guides.

Does this package have dependencies?

This dbt package is dependent on the following dbt packages. These dependencies are installed by default within this package. For more information on the following packages, refer to the dbt hub site.

IMPORTANT: If you have any of these dependent packages in your own packages.yml file, we highly recommend that you remove them from your root packages.yml to avoid package version conflicts.

packages:
    - package: fivetran/fivetran_utils
      version: [">=0.4.12", "<0.5.0"]

    - package: dbt-labs/dbt_utils
      version: [">=1.0.0", "<2.0.0"]

How is this package maintained and can I contribute?

Package Maintenance

The Fivetran team maintaining this package only maintains the latest version of the package. We highly recommend you stay consistent with the latest version of the package and refer to the CHANGELOG and release notes for more information on changes across versions.

Contributions

A small team of analytics engineers at Fivetran develops these dbt packages. However, the packages are made better by community contributions.

We highly encourage and welcome contributions to this package. Learn how to contribute to a package in dbt's Contributing to an external dbt package article.

Are there any resources available?

  • If you have questions or want to reach out for help, see the GitHub Issue section to find the right avenue of support for you.
  • If you would like to provide feedback to the dbt package team at Fivetran or would like to request a new dbt package, fill out our Feedback Form.

Releases

Packages

Contributors