Chapter 3: Setting Up Your AI Partner
The Problem
You're convinced that AI can help with your marketing operations. But how do you actually start? Where do you type? What do you install? The gap between "this sounds useful" and "I'm actually using it" feels enormous.
This chapter bridges that gap. By the end, you'll have a working environment where you can ask AI to help you build segments, explore data, and automate workflows.
The Key Idea
Core concept
You need two things: a CLI tool that connects to Treasure Data (tdx), and an AI assistant that can use it (Claude Code).
tdx is the bridge between your computer and Treasure Data. Claude Code is the AI that reads, writes, and runs commands through that bridge.
What You'll Install
| Tool | What It Does |
|---|---|
| Node.js | Runtime that powers tdx |
| tdx | CLI for Treasure Data operations |
| Claude Code | AI assistant that works in your terminal |
Step 1: Install Node.js
tdx runs on Node.js. If you don't have it installed:
Mac (using Homebrew):
brew install nodeWindows/Mac/Linux (using installer): Download from nodejs.org and follow the installer.
Verify it works:
node --versionYou should see a version number like v20.10.0. Any version 18 or higher works.
Step 2: Install tdx
With Node.js installed, you can install tdx globally:
npm install -g @treasuredata/tdxVerify it works:
tdx --versionYou should see something like tdx/0.10.0.
Step 3: Authenticate with Treasure Data
tdx needs to know who you are. Run the setup command:
tdx auth setupThis will prompt you for:
- Region — Where your Treasure Data account lives (US, JP, EU, or AP)
- API Key — Your personal API key from Treasure Data
Where to find your API key:
- Log into the Treasure Data console
- Click your profile icon → "API Keys"
- Copy your API key (or create one if you don't have it)
Verify authentication works:
tdx database listIf you see a list of databases, you're connected.
Step 4: Install Claude Code
Claude Code is the AI assistant that will help you write marketing configurations.
npm install -g @anthropic-ai/claude-codeVerify it works:
claude --versionStep 5: Launch Claude Code with Treasure Data Skills
Here's where the magic happens. Instead of launching Claude Code directly, use tdx to launch it with Treasure Data skills pre-loaded:
tdx claudeThis command:
- Launches Claude Code
- Loads TD-specific skills (SQL, segments, journeys, workflows)
- Gives AI the context it needs to help with Treasure Data operations
Mental Model: Your AI Marketing Assistant
Think of this setup as hiring a new team member:
- tdx is their access badge — it lets them into Treasure Data
- Claude Code is the person — intelligent, helpful, ready to work
- TD Skills are their training — they know how Treasure Data works
When you run tdx claude, you're bringing this trained assistant to your desk, badge in hand, ready to help.
What You Can Now Do
With this setup complete, you can:
# Ask AI to explore your data
> "What tables do I have in the marketing database?"
# Ask AI to write a query
> "How many customers made a purchase last month?"
# Ask AI to build a segment
> "Create a segment for customers who spent over $500"
# Ask AI to explain something
> "What does this YAML file do?"The AI reads your request, figures out what tdx commands or files to create, and does the work.
Common Issues
"Command not found: tdx"
Node.js didn't add the global bin folder to your PATH. Try:
# Find where npm installs global packages
npm config get prefix
# Add that path's bin folder to your shell profile
# For Mac/Linux, add to ~/.zshrc or ~/.bashrc:
export PATH="$PATH:$(npm config get prefix)/bin""Authentication failed"
Your API key might be incorrect or expired. Run tdx auth setup again and double-check the key from the Treasure Data console.
"tdx claude hangs or errors"
Make sure you have a valid Anthropic API key or TD AI Foundry access configured. Check with your Treasure Data administrator.
What You've Learned
- tdx connects your terminal to Treasure Data
- Claude Code is an AI assistant that works in your terminal
tdx claudelaunches Claude Code with TD-specific skills- You can now ask AI to explore data, write queries, and build segments
Next Step
You have the tools. Now you need to understand what AI produces. Chapter 4 teaches you to read YAML—the format AI uses to define your marketing configurations.
Your AI partner is ready. The next chapter teaches you its language.