# Claude Code Integration

Launch [Claude Code](https://docs.anthropic.com/en/docs/claude-code) with [Treasure AI](/products/customer-data-platform/ai-agent-foundry) as the backend.

Treasure AI customers can use Claude Code with their existing [AI Suite credits](https://www.treasure.ai/terms/ai-suite-credits-definition/) — no separate Claude subscription required.

## Features

- **Use Your Own TD Subscription** - Run Claude Code using [AI Suite credits](https://www.treasure.ai/terms/ai-suite-credits-definition/)
- **Full Claude Code Features** - Extended thinking, plan mode, subagents, and Opus model support
- **TD Documentation Search** - AI-powered search across [Treasure AI documentation](/)
- **TD Skills Integration** - Enhanced with [td-skills](/treasure-code/guide/td-skills) for writing SQL queries, workflows, and building user segments on CDP


## Architecture

```mermaid
flowchart LR
    subgraph TDX["tdx claude"]
        CC["Claude Code<br/>• td-skills • td-docs MCP"]
        Proxy["Local Proxy"]
    end

    subgraph TD[Treasure AI]
        LLM["Anthropic-compatible API"]
    end

    CC <-->|/v1/messages| Proxy
    Proxy <-->|Anthropic API| LLM

    style TDX fill:transparent,stroke:#888
    style CC padding:10px
```

When you run `tdx claude`:

1. Starts a local pass-through proxy to Treasure AI
2. Launches Claude Code with [td-skills](/treasure-code/guide/td-skills) and td-docs MCP pre-configured
3. The proxy forwards Claude Code API requests (`/v1/messages`) to [Treasure AI](/products/customer-data-platform/ai-agent-foundry), which provides Anthropic-compatible API access to Claude models


## Client identification

TD-proxied LLM requests use `X-TD-Client: tdx/claude`. TD API requests made by
child `tdx` commands inherit the same identity through `TDX_CLIENT`. The
User-Agent retains `tdx/<version>` and adds `client=tdx/claude` in its comment;
`X-TD-Client-Version` remains the tdx version.

With `--no-proxy`, only child TD CLI requests receive this identity; external
Claude providers are left unchanged. Parent startup requests and OAuth token
refresh requests are outside this attribution. Explicit user settings can
override the inherited environment.

## Usage

```bash
tdx claude [options] [-- claude-options]
```

## Options

| Option | Description |
|  --- | --- |
| `-c, --continue` | Forwarded to Claude Code to continue the most recent conversation |
| `-r, --resume [session]` | Forwarded to Claude Code to resume a conversation or open its selector |
| `--no-proxy` | Use your own Claude Code account (Anthropic/AWS Bedrock/Vertex AI, etc.) |
| `--disable-1h-cache` | Skip the one-hour cache default (Claude models only) |
| `--refresh` | Force a full td-docs MCP and td-skills refresh before launching |
| `--subagent-model <m>` | Model for Claude Code sub-agents: `inherit` (default), `auto`, or a model |


Claude Code options are forwarded without reordering. To resume a known session ID,
pass it directly after `--resume`:

```bash
tdx claude --model="efficient[1m]" --resume <session-id>
```

## Default model

For TD internal users (signed-in email at `treasure.ai` or `treasure-data.com`),
proxy sessions default to `auto[1m]` when no `--model` option is supplied. This
session-only argument takes precedence over `ANTHROPIC_MODEL` and Claude Code's
configured default; pass `--model <model>` to choose another model.

External users and `--no-proxy` sessions keep Claude Code's own model selection.
An account lookup failure prevents launching rather than skipping policy checks. Resumed sessions
(`-c`/`--continue`, `-r`/`--resume`) keep the model they were started with. No persistent
configuration is changed.

## Production account 1

On production account 1 (TD account ID 1 on a non-dev, non-staging site), `tdx claude`
turns off Claude Code's local conversation history, including the session transcript and
prompt history. It applies this with `CLAUDE_CODE_SKIP_PROMPT_HISTORY=1` in session-scoped
settings, which take precedence over your settings files. This also applies with `--no-proxy`.

- Claude Code 2.1.304 or later is required.
- Sessions cannot be continued or resumed, so `-c`, `-r`, `--fork-session`,
`--session-id`, `--from-pr`, `--teleport`, and your own `--settings` are rejected.
- tdx must verify the signed-in account before launching; if it can't, it does not launch.


This only covers sessions started by `tdx claude`. It does not apply to other agents that run
`tdx` commands, or to output you save yourself.

## Setup

`tdx claude` sets up the td-docs MCP server and td-skills plugins for you, and skips
any step that's already done — so the first launch on a machine does the real work and
later launches start immediately. The other TD skills refresh whenever `tdx` is upgraded,
and at least every two weeks.

The tdx Skills (`tdx-skills`) ship inside `tdx` itself. Each launch installs them into
Claude Code's skills folder, so they always match the installed commands. They use plain
names such as `segment` and `tdx-basic`. To install them for a project or a folder, see
[`tdx skill`](/treasure-code/commands/skill).

`--refresh` forces an update, which you shouldn't normally need.

## Prompt caching

In proxy mode, **Claude models** use a **one-hour prompt cache** for the main
conversation by default. This reduces rewrites after idle gaps, but writes cost
**2× base input** instead of **1.25×** for five minutes.

To skip this default:

```bash
tdx claude --disable-1h-cache
```

The flag leaves prompt caching and explicit TTL settings intact. `--no-proxy`,
sub-agent caching, and non-Claude providers' cache policies are unchanged.

## Sub-agent model

Claude Code often delegates work to sub-agents, for example the built-in `Explore` agent
that searches your codebase, or custom agents defined in `.claude/agents/`. Each sub-agent
can run on a different model from your main conversation, and by default Claude Code picks
those models on its own, so a session you started on a cheaper model can still spend
Opus-tier AI Suite credits in the background.

### What `tdx claude` does by default

- **You picked a model** with `--model` (for example `tdx claude --model sonnet`): every
sub-agent runs on that same model. Your whole session, including `Explore` and `Plan`,
stays on the model you chose.
- **You didn't pick a model and are a TD internal user**: proxy sessions use `auto[1m]`
for both the main conversation and sub-agents.
- **Otherwise, you didn't pick a model**: Claude Code runs the main conversation on
its own default model and routes sub-agents the way it always has.


You don't need to do anything to get this behavior.

### Changing it

Use `--subagent-model` when you want something else:

```bash
# Main conversation on the default model, sub-agents on a cheaper one
tdx claude --subagent-model efficient

# Main conversation on sonnet, sub-agents pinned to a different model
tdx claude --model sonnet --subagent-model haiku

# Let Claude Code choose sub-agent models on its own (no tdx involvement)
tdx claude --subagent-model auto
```

| `--subagent-model` | Sub-agents run on |
|  --- | --- |
| `inherit` (default) | The model selected with `--model`, including tdx's internal `auto[1m]` default. Without a selected model, the default leaves Claude Code's routing as is, while an explicit `--subagent-model inherit` makes every sub-agent follow the main conversation's model. |
| `auto` | Whatever Claude Code decides: each agent's own `model` setting, and its built-in defaults for `Explore`. |
| a model name | That model, for every sub-agent. Any name `--model` accepts works: `haiku`, `efficient`, `efficient[1m]`, `claude-sonnet-5`. |


### Details

- `tdx claude` implements this through Claude Code's `CLAUDE_CODE_SUBAGENT_MODEL` and
`CLAUDE_CODE_SUBAGENT_MODEL_FORCE` environment variables. If you already export either
of them in your shell and don't pass `--subagent-model`, tdx leaves your values alone.
- `ANTHROPIC_MODEL` in your environment counts as a chosen model when no `--model`
argument is present, including tdx's injected internal default.
- With `--no-proxy`, tdx only sets these when you pass `--subagent-model` explicitly.
- Applying the model to the built-in `Explore` and `Plan` agents needs Claude Code
2.1.257 or later. Older versions still honor it for custom agents.


## Examples

```bash
# Launch Claude Code with Treasure AI
tdx claude

# Continue most recent conversation
tdx claude -c

# Run sub-agents on a cheaper model
tdx claude --subagent-model efficient

# Resume a conversation (shows selector)
tdx claude -r

# Start with an initial prompt
tdx claude -- "Explain this code"

# Use your own Claude Code account with TD skills
tdx claude --no-proxy

# Force a td-docs MCP and td-skills refresh
tdx claude --refresh
```

## Example Conversations

Once inside Claude Code, you can ask questions like:

```
> How to set up data ingestion to TD from Snowflake?

> How to add web access log collector in my web page?

> Analyze mydb.user_events data

> Write a workflow to periodically import data from S3

> Create a SQL query to find top customers by revenue

> Build a user segment for customers who purchased in the last 30 days
```

## Requirements

### Install Claude Code

See the [Claude Code Quick Start](https://code.claude.com/docs/en/quickstart) for installation instructions.

```bash
curl -fsSL https://claude.ai/install.sh | bash
```

Minimum Version
Claude Code **2.0.20 or later** is required for td-skills support. Update with:

```bash
claude update
```

### Other Requirements

- Valid TD API key with LLM access


For usage across Claude, Codex, and OpenCode, run [`tdx usage`](/ja/treasure-code/commands/usage).

## Discover models

Use [`tdx ai models`](/ja/treasure-code/commands/ai) to discover model IDs and aliases for `--model` or
`--subagent-model`. Filter by `v1_messages` for Claude Code-compatible models:

```bash
tdx ai models --feature v1_messages
tdx ai models --feature v1_messages --provider anthropic
```

## Subcommands

### statusline

Output credit usage for Claude Code's status bar. This is automatically configured when running `tdx claude`. See [Claude Code Statusline Documentation](https://code.claude.com/docs/en/statusline) for more details.

```bash
tdx claude statusline
```

Reads session info from stdin (JSON with `session_id` and `model`) and outputs a formatted statusline.

When using `--profile`, the statusline shows profile-specific today/month credits:

```bash
tdx --profile myprofile claude
```

**Output:**

```
🤖 tdx - Sonnet 4.5 | 🪙 credit: 0.12 session / 1.23 today / 10.45 month | 🧠 22,396 (11%)
```

The statusline shows:

- Current model name
- Session / Today / Month credits (estimates, filtered by profile when specified)
- Context memory usage


For users with a `treasure.ai` or `treasure-data.com` email, USD cost replaces
credits in the same compact display:

```text
💎 tdx - Sonnet 4.5 | 🪙 $12.28 session / $125.85 today / $1069.24 month | 🧠 22,396 (11%)
```

Costs use tracked proxy token usage and model pricing, following Treasure Work.
The email is cached when starting `tdx claude`; restart it to refresh an existing
account cache. Daily and monthly totals remain filtered by profile when specified.

## Learn More

For generic Claude Code usage, refer to the official documentation:

- [Claude Code Documentation](https://code.claude.com/docs)
- [Claude Code in Action (Tutorial)](https://anthropic.skilljar.com/claude-code-in-action)