# 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):** ```bash brew install node ``` **Windows (using PowerShell):** ```powershell # Using Windows Package Manager winget install OpenJS.NodeJS.LTS # Or download from https://nodejs.org/ ``` **Linux:** ```bash # Using nvm (recommended) curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash source ~/.bashrc nvm install 24 ``` **Verify it works:** ```bash node --version ``` You should see a version number like `v22.12.0` or higher. ## Step 2: Install tdx With Node.js installed, you can install tdx globally: ```bash npm install -g @treasuredata/tdx ``` **Verify it works:** ```bash tdx --version ``` You 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: ```bash tdx auth setup ``` This will prompt you for: 1. **Region** — Where your Treasure Data account lives (US, JP, EU, or AP) 2. **API Key** — Your personal API key from Treasure Data **Where to find your API key:** 1. Log into the Treasure Data console 2. Click your profile icon → "API Keys" 3. Copy your API key (or create one if you don't have it) **Verify authentication works:** ```bash tdx database list ``` If 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. ```bash npm install -g @anthropic-ai/claude-code ``` **Verify it works:** ```bash claude --version ``` ## Step 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: ```bash tdx claude ``` This 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: ```mermaid flowchart LR subgraph Your Computer CC[Claude Code] TDX[tdx CLI] end subgraph Treasure Data API[TD API] CDP[CDP] DB[(Databases)] end CC <--> TDX TDX <--> API API --> CDP API --> DB ``` - **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: ```bash # 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: ```bash # 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 claude` launches 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](/treasure-code/book/04-understanding-yaml) 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.*