Skip to main content

Importing Claude Code usage metrics

Updated this week

This guide explains how to upload Claude Code usage metrics into DX using a CSV file. Once an API is made available by Anthropic, this process will be automated through a DX data connector.

Prerequisites

  • an Anthropic account with access to export Claude Code API usage

  • a DX database user with write access

Instructions

Step 1- Create custom table

To import Claude Code usage metrics into DX, you’ll first need to create a custom table in your DX database.

  1. Use a Postgres client (Postico or pgAdmin) to connect to your DX database.

  2. Then, execute the SQL statement​ below:

CREATE TABLE custom.claude_code_daily_usages (
id SERIAL PRIMARY KEY,
date DATE NOT NULL,
model_version text,
api_key text,
workspace text,
usage_type text,
usage_input_tokens_no_cache integer,
usage_input_tokens_cache_write_5m integer,
usage_input_tokens_cache_write_1h integer,
usage_input_tokens_cache_read integer,
usage_output_tokens integer,
web_search_count integer
);

Step 2- Prepare Claude Code data

Download a raw export of your Claude Code usage metrics and update the CSV file to match the schema in Step 1. Ensure that the usage_date_utc header is renamed to date!

Step 3- Import Claude Code data

Use the Import CSV feature in Postico or pgAdmin to upload your data to DX.

  1. Right-click the custom.claude_code_daily_usages table and click Import CSV.

  2. Select the formatted CSV from Step 2.

  3. Ensure “First row is header” is checked.

  4. Click Import.

Step 4- Create & View reports

Once your data is uploaded, use DX's prebuilt reports or use Data Studio to create custom reports. Please reach out and we can set up some standardized custom reports with this data.

Did this answer your question?