How to Use Claude Code with Clay for AI-Powered Lead Generation
Use Claude Code as an orchestrator and Clay as your data source to find, enrich, and write personalized cold outreach at scale automatically.
Why Claude Code and Clay Work So Well Together
Sales teams have tried to automate lead generation for years. The problem isn’t finding leads — it’s that generic outreach doesn’t work, and personalized outreach doesn’t scale. Until recently, you had to choose one or the other.
Claude Code changes that equation. When you use Claude Code as an orchestrator and Clay as your data source, you can build a pipeline that finds prospects, enriches their profiles with deep research, and writes genuinely personalized cold emails — all without you touching a spreadsheet or drafting a single message by hand.
This guide walks through exactly how to set that up, step by step.
What Each Tool Actually Does
Before getting into the workflow, it helps to be clear on what each tool contributes.
Clay
Clay is a data enrichment platform built around a spreadsheet-like interface. You give it a list of companies or contacts, and it pulls information from 75+ data providers — LinkedIn, Apollo, Clearbit, Crunchbase, Hunter.io, and more — into a single table.
What makes Clay useful isn’t just aggregation. It’s the way you can layer enrichment. For example:
- Start with a company domain
- Pull the company’s headcount, funding stage, and tech stack
- Find the right contact (VP of Sales, Head of Engineering, etc.)
- Pull that contact’s LinkedIn activity and recent posts
- Run a “Claygent” AI research task to summarize their role and likely pain points
Seven tools to build an app. Or just Remy.
Editor, preview, AI agents, deploy — all in one tab. Nothing to install.
The result is a table where each row is a fully enriched prospect profile, not just a name and email.
Claude Code
Claude Code is Anthropic’s agentic coding environment. It runs in your terminal and can write code, execute it, call APIs, read and write files, and iterate on its own output based on results.
In this context, Claude Code acts as the brain of the operation. It:
- Pulls enriched data from Clay’s API
- Processes and structures that data
- Generates personalized outreach for each prospect
- Handles errors, retries, and edge cases automatically
- Outputs results wherever you need them — a CSV, a CRM, an email tool
You don’t write the scripts manually. You describe what you want, and Claude Code figures out the implementation.
Prerequisites
Before building this workflow, make sure you have:
- A Clay account with at least one enriched table of leads (a paid plan gives you API access)
- Claude Code installed — run
npm install -g @anthropic-ai/claude-codeand authenticate with your Anthropic API key - A working knowledge of your ideal customer profile (ICP) — industry, company size, job titles you’re targeting
- An export destination in mind: CSV, HubSpot, Instantly.ai, Smartlead, or wherever your outreach runs
You don’t need to know Python or JavaScript. Claude Code will write the code for you. But understanding what you’re asking for makes your prompts more effective.
Step 1: Build and Enrich Your Clay Table
Your outreach is only as good as your data. Spend time here.
Define Your ICP in Clay
Start a new table in Clay. You can import from:
- A CSV of company domains
- LinkedIn Sales Navigator exports
- Apollo.io search results
- Clay’s built-in company search
Filter aggressively. Target fewer, better-fit prospects rather than large undifferentiated lists.
Add the Right Enrichment Columns
For cold outreach, you want enough context to write a message that feels specific. The columns that matter most:
- Company name and domain
- Industry and sub-industry
- Headcount range (helps gauge messaging complexity)
- Funding stage or recent funding (if relevant to your pitch)
- Tech stack — Clay can pull this from BuiltWith or similar sources
- Contact name, title, and email
- LinkedIn URL for the contact
- Recent LinkedIn posts or activity — this is gold for personalization
- News mentions — recent press, product launches, hiring activity
Run Claygent for Deeper Research
Clay’s built-in AI agent (Claygent) can run a research prompt on each row. For example:
“Based on this person’s title, company, and recent LinkedIn activity, summarize in two sentences what business problem they’re likely trying to solve right now.”
This gives Claude Code richer material to work with when drafting outreach.
Export via Clay API
Once your table is enriched, note your Clay API key (found in Settings > API) and your table ID. You’ll pass these to Claude Code in the next step.
Step 2: Set Up Claude Code for the Workflow
Open your terminal and start a Claude Code session in a new project directory.
mkdir lead-gen-workflow && cd lead-gen-workflow
claude
From here, describe what you’re building. Something like:
- ✕a coding agent
- ✕no-code
- ✕vibe coding
- ✕a faster Cursor
The one that tells the coding agents what to build.
“I’m building a lead generation workflow. I need to pull enriched contact data from a Clay table via API, generate a personalized cold email for each contact using their enriched profile, and output the results to a CSV with columns: name, company, email, subject line, and email body.”
Claude Code will ask clarifying questions and then write the script. It handles the API calls, pagination, error handling, and output formatting.
What the Claude Code Script Does
Claude Code will typically generate something that:
- Authenticates with Clay using your API key
- Pulls rows from your specified table (with pagination if needed)
- Structures the enrichment data into a prompt for each contact
- Calls the Claude API to generate personalized email copy
- Writes the output to a CSV or your chosen format
If something breaks — a missing field, an API rate limit, a malformed response — Claude Code catches the error, explains what happened, and fixes the code. You don’t need to debug it yourself.
Step 3: Write Personalization Prompts That Actually Work
This is where most teams underinvest. The quality of your outreach depends almost entirely on how you prompt the model to write it.
The Structure of a Good Personalization Prompt
Claude Code will build a per-contact prompt by combining:
- Static context (your value proposition, your product, your ICP)
- Dynamic context (the enriched data for that specific row)
A well-structured prompt looks something like this:
You are a B2B sales rep at [Company]. We help [ICP] to [solve specific problem].
Write a cold email to [Contact Name], who is [Title] at [Company Name].
Here's what we know about them:
- Company stage: [Funding/Headcount]
- Tech stack: [Relevant tools]
- Recent activity: [LinkedIn post or news item]
- Likely pain point: [Claygent summary]
Guidelines:
- Subject line: under 8 words, specific to them
- Email body: 4-5 sentences max
- Reference one specific detail from their context
- Do not mention their job title in the opening
- End with a single, low-friction CTA
- Do not use generic phrases like "I hope this finds you well"
The more specific your guidelines, the more consistent the output.
Iterate on the Prompt Before Running at Scale
Before running this across your full table, test it on five to ten rows. Read the output critically:
- Does it sound like a human wrote it?
- Is the personalization detail actually relevant, or does it feel forced?
- Is the CTA appropriate for a cold email?
Adjust the prompt with Claude Code. Tell it what’s off, and it will revise the instruction set and re-run.
Step 4: Handle Output and Routing
Once the script runs across your full table, you have a CSV with personalized emails for every contact. Now you need to get that into your outreach tool.
Option A: Direct Import
Most cold email platforms — Instantly.ai, Smartlead, Lemlist, Outreach — accept CSV imports with custom variables. Map your columns to the platform’s fields and import.
Option B: Push to HubSpot or Salesforce
If your sales team works from a CRM, you can have Claude Code write a second script that pushes each enriched contact and email draft into HubSpot as a contact with an associated email task. Claude Code can handle HubSpot’s API directly.
Option C: Trigger from a Webhook
Built like a system. Not vibe-coded.
Remy manages the project — every layer architected, not stitched together at the last second.
For ongoing workflows — where Clay tables update automatically as new leads match your ICP criteria — you can set up a webhook. When Clay adds a new row, it pings an endpoint. Claude Code can run on a server and process each new prospect in near real-time.
This is where the workflow moves from a one-time batch job to a continuous pipeline.
Step 5: Automate the Full Loop
A truly automated lead generation system doesn’t require you to kick it off manually. Here’s how to close the loop:
- Clay pulls new leads automatically — using saved searches, LinkedIn filters, or integrations that push contacts into your table on a schedule
- Clay enriches each new row — running all your enrichment columns and Claygent prompts
- A webhook or scheduled job triggers Claude Code — when new enriched rows appear
- Claude Code generates the email — using the enriched data and your personalization prompt
- Output goes to your outreach tool — automatically staged for sending
Once this is running, the pipeline handles itself. Your job becomes reviewing output quality periodically and refining the prompt.
Extending This Workflow with MindStudio
If you want to add capabilities to this pipeline without writing more custom code, MindStudio’s Agent Skills Plugin is worth knowing about.
The plugin is an npm SDK (@mindstudio-ai/agent) that lets Claude Code call 120+ pre-built capabilities as simple method calls. Instead of writing custom integration code for every downstream action, you call a method:
await agent.sendEmail({ to: contact.email, subject: emailSubject, body: emailBody });
await agent.runWorkflow({ id: 'hubspot-contact-create', inputs: contactData });
This is useful when your pipeline needs to do things like:
- Send emails directly through a verified domain
- Log results to a Google Sheet or Notion database
- Trigger a Slack notification when a high-priority prospect is found
- Run a secondary AI workflow for follow-up sequencing
MindStudio handles the infrastructure — rate limiting, retries, authentication — so Claude Code can stay focused on the reasoning and orchestration layer.
You can try MindStudio free at mindstudio.ai — no API keys or external accounts needed, and it connects directly to the tools your sales team already uses.
Common Mistakes to Avoid
Using Too Many Personalization Variables
More data doesn’t automatically mean better emails. Cramming six personalization details into a four-sentence email makes it read like a template trying too hard. Pick one or two specific, relevant details and make them count.
Skipping the QA Step
Always review a sample of output before sending. Claude Code is good, but it doesn’t know your brand voice perfectly from a first pass. A quick review of 20–30 emails catches patterns you can correct at the prompt level.
Relying on Low-Quality Enrichment Data
If the data Clay pulls is stale or inaccurate, your personalization backfires. Verify high-signal fields — especially LinkedIn activity and tech stack — before building personalization around them.
Sending Without Warmup
If you’re using a new sending domain, warm it up properly before launching at volume. Personalized copy doesn’t help if your emails land in spam.
Not Updating Prompts as You Learn
The first version of your personalization prompt is a starting point. As you see reply rates, update the prompt. The pipeline only gets better if you iterate on the inputs.
FAQ
Remy doesn't write the code. It manages the agents who do.
Remy runs the project. The specialists do the work. You work with the PM, not the implementers.
What is Claude Code and how does it work for lead generation?
Claude Code is Anthropic’s agentic coding tool that runs in your terminal. For lead generation, it acts as an orchestrator: it writes and runs scripts that pull prospect data from tools like Clay, process that data, generate personalized outreach using AI, and push the results to wherever you need them. You describe what you want in plain language, and Claude Code handles the implementation.
Does Clay have an API I can use with Claude Code?
Yes. Clay’s API gives you programmatic access to your enriched tables. You can read rows, filter by column values, and pull the full enrichment data for each contact. You’ll need a paid Clay plan to access the API, and you authenticate with an API key from your account settings.
How personalized can the AI-generated emails actually be?
This depends on the quality of enrichment data you provide. With strong inputs — recent LinkedIn posts, funding news, tech stack details, Claygent research summaries — Claude can write emails that reference specific, verifiable details about each prospect. The more precise your personalization prompt and the richer your Clay data, the more human the output reads.
Can I run this workflow automatically without triggering it manually each time?
Yes. You can set Clay to automatically add and enrich new leads as they match your ICP criteria, then use a webhook to trigger Claude Code whenever new rows appear. This creates a continuous pipeline where new prospects move from identification to personalized draft without manual intervention.
Is this approach better than using Clay’s built-in AI features?
Clay’s AI (Claygent) is excellent at research and data extraction. Claude Code adds a different layer: it can orchestrate complex multi-step logic, write and debug integration code, and generate more nuanced long-form copy. They’re complementary. Use Clay for enrichment and research, and Claude Code for orchestration and email generation.
What’s the best way to validate output quality before sending at scale?
Run the pipeline on a sample of 20–50 rows first. Read every email. Look for patterns where the personalization feels generic or where the tone is off. Adjust the prompt in Claude Code and re-run the sample. Only move to full-scale once you’re consistently happy with the output across diverse prospect types.
Key Takeaways
- Clay and Claude Code address the core tension in cold outreach: Clay handles deep prospect enrichment, while Claude Code orchestrates the pipeline and generates personalized copy at scale.
- Claude Code acts as the technical brain — it writes, runs, and debugs the integration code so you don’t have to.
- Personalization quality depends on enrichment quality. Invest in your Clay table setup before automating outreach.
- The full loop — auto-enrichment in Clay, webhook trigger, Claude Code generation, CRM push — can run continuously with minimal manual oversight.
- MindStudio’s Agent Skills Plugin extends what Claude Code can do downstream, connecting it to 120+ capabilities like email sending, CRM updates, and workflow triggers without custom integration code.
Everyone else built a construction worker.
We built the contractor.
One file at a time.
UI, API, database, deploy.
If you want to build on top of this workflow or experiment with AI-powered outreach without writing any code yourself, MindStudio is a good place to start — the visual workflow builder connects to Clay, your CRM, and your email tools out of the box.