🎯 Introduction
Most lead gen advice starts with "take your lead list and...". But what if you don't have one? Buying lists is expensive, and the lists are stale. Even with leads, reps waste most of their time on prospects that were never a fit. And "good fit" usually lives in someone's head as a gut feel, so it's inconsistent and impossible to delegate.
This agent fixes all of that in one pipeline. Starting from nothing but a written description of your ideal customer, it answers three questions:
And you build the whole thing by talking to Claude Code in plain language. You never write Python by hand. Claude writes the code, runs it, and fixes its own errors.
The finished project
lead-qualification-agent/
icp.md # Your ideal customer profile, written as a scoring rubric. The only input.
find_leads.py # Ark AI: find prospects matching the ICP + reveal verified emails -> leads.csv
leads.csv # Generated: the discovered leads (name, title, company, domain, linkedin_url, email)
score_leads.py # Scores each lead 0-100 vs the ICP, assigns A/B/C tier + reasons
enrich.py # Apify: scrape LinkedIn profile + company website -> personalization hooks
draft_outreach.py # Claude: writes a personalized first-touch email per A/B lead
push_to_instantly.py # Optional: create a campaign + add A-tier leads
send_digest.py # Email a weekly digest of the new A/B leads + drafts
run_weekly.sh # Orchestrator: find -> score -> enrich -> draft -> digest, scheduled
output/
qualified_leads.csv # Ranked, tiered, with the reason each lead scored the way it did
drafts/ # One personalized email per qualified lead
README.md # How to point it at your own ICP, run it, and schedule it
The end state: every Monday at 8am the agent re-runs on its own, finds fresh prospects, and emails you a digest of the new A and B tier leads with their drafts. Qualified prospects come to you.
⚙️ How It Works
Five stages, each one feeding the next. One input file drives everything.
| Stage | What Happens | Output |
|---|---|---|
| 1. Define | You write your ICP as a weighted scoring rubric in icp.md | The single source of truth |
| 2. Find | The agent searches B2B data for companies matching your firmographics, then finds the decision maker at each and reveals their verified email | leads.csv |
| 3. Score | Every lead is judged against the rubric: a 0-100 score, an A/B/C tier, and a one-sentence reason | qualified_leads.csv |
| 4. Personalize | For A and B leads only: scrape their LinkedIn and company site, extract 2-3 real hooks, draft a sub-90-word first-touch email | output/drafts/ |
| 5. Deliver | A-tier leads land in a paused sending campaign for your review, and a weekly digest email summarizes everything new | Your Monday morning inbox |
The key shift: there is no lead list to begin with. You describe who you want, and the agent goes and finds them. Sourcing, scoring, and personalization all flow from one file: icp.md.
🧰 Tools & Costs
The categories matter more than the specific tools: a build environment, a lead source, a scraper, and a sender. These are the ones I use today.
| Tool | Role | Needed? |
|---|---|---|
| Claude Code | The build environment and the agent runtime. You describe the agent in plain language and it writes and runs the code. Also powers the scoring, hook extraction, and drafting through your existing login, so there is no separate API key to manage. | Yes (your existing subscription) |
| Ark AI (ai-ark.com) | The lead source. Finds B2B prospects matching your ICP and reveals verified emails. This is how the agent gets leads with no database to start from. About 1 credit per verified email. | Yes (small free credit allowance covers a 20-lead run) |
| Apify | Scrapes each qualified lead's LinkedIn profile and company website to pull real personalization hooks. | Optional (free tier works) |
| Instantly | Sending platform with warmup and deliverability, where the A-tier leads and drafts land, paused for your review. | Optional (only when you're ready to send) |
| Plain CSV files | The data layer. No database, no vendor lock-in. Everything is portable and inspectable. | Built in |
🚀 Before You Start
- Install Claude Code and sign in. Instructions at claude.com/claude-code. That's all you need for every AI step: scoring, enrichment, and drafting run through Claude Code, so there is no separate Anthropic API key to manage.
- Create an Ark AI account at ai-ark.com and grab your API token. This is the lead source, the one paid tool the pipeline needs. A small free credit allowance is enough to build and test. Export it in your terminal:
export ARK_API_TOKEN=your_token_here
- Optional: create a free Apify account at apify.com for the personalization step:
export APIFY_API_TOKEN=your_token_here
- Optional: Instantly + Gmail, only for the sending and digest steps at the end. You can add these later.
Cost check before you build: one full run on a 20-lead batch costs about 20 Ark credits and stays inside Apify's free tier. The agent prints its credit usage every run, so it scales without surprises.
Step 1: Create the Project
Scaffold the folder structure and explain the plan
Open a terminal in an empty folder and launch Claude Code. First prompt:
📋 PROMPT • PASTE INTO CLAUDE CODECreate a new project called lead-qualification-agent. We are building an agent that starts from just an ideal customer profile, finds matching B2B prospects with verified emails, scores each one against that profile, and drafts personalized outreach for the good-fit ones. There is no existing lead list, the agent has to source the leads itself. Set up the folder structure: an icp.md config, a find_leads.py for sourcing, an output/ folder, and a README. Do not write any logic yet, just scaffold it and explain the plan.
Step 2: Write Your ICP as a Rubric
The single most important file in the whole system
Everything downstream reads from this file. Describe your real ideal customer, not a generic one:
📋 PROMPT • PASTE INTO CLAUDE CODEHelp me turn my ideal customer profile into a scoring rubric in icp.md. My ICP is: [describe yours, for example: B2B companies with 10+ employees, repetitive manual processes, a decision maker in ops or the founder, based in NL or EU]. Turn this into weighted criteria that each contribute to a 0-100 score, with clear signals for what a strong, medium, and weak match looks like on each criterion. Keep it editable so anyone can swap in their own ICP.
Then let Claude interview you to close the gaps:
📋 PROMPT • PASTE INTO CLAUDE CODEInterview me to make sure icp.md is complete. Ask about firmographics, buying signals, target persona, and value prop, and fill the gaps.
What a good rubric looks like
Weighted criteria that add up to 100, with explicit signals per level:
| Criterion | Weight | Strong (full points) | Medium (half) | Weak (zero) |
|---|---|---|---|---|
| Title / decision power | 30 | Founder / C-level / ops lead | Manager | Individual contributor |
| Company size fit | 25 | In range | Slightly outside | Way outside |
| Industry fit | 25 | Core target vertical | Adjacent | Unrelated |
| Buying signal | 20 | Clear recent signal | Some signal | None |
Tiers: A = 80+, B = 60-79, C = below 60. Only A and B leads get enriched and drafted, so you never spend scraping runs or writing effort on poor fits.
Step 3: Find the Leads
The "from nothing to a list" moment
This step solves "I have no database":
📋 PROMPT • PASTE INTO CLAUDE CODEWrite find_leads.py. We have no lead list, so build one from the ICP using the Ark AI API. Here are the docs: https://docs.ai-ark.com. Read them to work out the endpoints and how auth works. Do it in two stages: first find companies that match the ICP firmographics (industry/keywords, employee size, location from icp.md), then for each company find the decision-maker matching the persona (titles/seniority in icp.md) and reveal their verified email. Read the Ark token from the environment (ARK_API_TOKEN). Write the results to leads.csv with columns: name, title, company, domain, linkedin_url, email. Start with a small batch (for example 20 leads) and print how many credits that used.
Then run it:
📋 PROMPT • PASTE INTO CLAUDE CODERun find_leads.py and show me the leads.csv it created.
You did not buy a list. You described who you want, and the agent found companies that fit the niche, then the right decision maker at each, with verified emails.
Technical note: Ark's bulk endpoints require a webhook. Use the synchronous People Search plus export/single path instead, which needs no webhook. The prompt above steers Claude there, but if it reaches for a bulk endpoint, tell it to switch.
Step 4: Score Them
LLM as judge: same rubric, every lead, auditable reasons
Write score_leads.py. For each row in leads.csv, score the lead 0-100 against the criteria in icp.md. Do the scoring through Claude Code (the claude CLI in headless -p mode), not the Anthropic API, so it uses my Claude Code login and needs no API key. Use a structured output with: score, tier (A 80+, B 60-79, C below 60), and a one-sentence reason. Write the results to output/qualified_leads.csv sorted by score descending. Print a short summary of how many A, B, and C leads there are.📋 PROMPT • PASTE INTO CLAUDE CODE
Run score_leads.py on the leads we just found and show me the top of qualified_leads.csv.
This is the LLM-as-judge pattern: same rubric, every lead, with an auditable reason. Even leads the agent found itself still get filtered. Sourcing is not the same as fit.
Step 5: Enrich for Personalization
Scrape real signals so the outreach says something true
Add enrich.py. For the A and B tier leads only, use Apify to scrape each lead's LinkedIn profile and their company website. Use my APIFY_API_TOKEN from the environment. Extract 2-3 concrete personalization hooks per lead (a recent post, a role detail, something the company recently shipped or announced) and save them next to each lead in output/qualified_leads.csv. Be efficient: only enrich qualified leads so we do not waste Apify runs on C-tier.
Actor choice matters: use a no-login LinkedIn actor on Apify (for example apimaestro/linkedin-profile-detail). The email-enabled actors require a one-time account approval that will stall you. Apify does the scraping; Claude distills the 2-3 hooks.
Step 6: Draft the Outreach
The payoff moment
Write draft_outreach.py. For each A and B tier lead, use Claude Code (the claude CLI, not the API) to write a short personalized first-touch email. It must reference one of the real personalization hooks from enrichment, connect it to the value we offer (described in icp.md), and end with a soft call to action. Keep it under 90 words, conversational, first person, and do not use em-dashes. Save one file per lead in output/drafts/. Then print the drafts for the top 3 leads so we can read them.
Read a few drafts and compare them to what a generic template would have said. "Saw your post about the new warehouse in Utrecht" beats "I came across your profile" every single time. That one real detail is the difference between a reply and a delete.
Step 7: Send the Best Ones
A-tier leads into a paused campaign, ready for review
Add push_to_instantly.py. Take only the A-tier leads with their drafted email, create a campaign in Instantly via the API, and add those leads with their personalized first line. Do not launch it automatically, leave it paused so a human reviews before anything sends.
Human in the loop, always: the campaign stays paused until you review it. You check the drafts, then the sending platform handles warmup and drip so you protect your domain. Never let an agent blast cold email unreviewed.
Step 8: Turn It Into a Weekly System
From a script you run to a system that runs itself
First the digest:
📋 PROMPT • PASTE INTO CLAUDE CODEWrite send_digest.py. After a run, build a short HTML email summarizing the new A and B tier leads from output/qualified_leads.csv: name, company, score, the one-line reason, and a link to their drafted email. Send it to me by email using my Gmail, subject line "Your best prospects this week - [count] new leads". Keep it scannable.
Then the orchestrator and the schedule:
📋 PROMPT • PASTE INTO CLAUDE CODEWrite run_weekly.sh that runs the full pipeline in order: find_leads.py, score_leads.py, enrich.py, draft_outreach.py, then send_digest.py. Make find_leads.py skip prospects already seen in previous runs so the digest only shows genuinely new leads. Then show me how to schedule it to run every Monday at 8am, both as a plain cron job and as a Claude Code scheduled agent, and explain the trade-offs of each.
The set-it-and-forget-it payoff: every Monday the agent re-runs, finds fresh prospects, and emails the new A/B leads with their drafts. The leads come to you.
Step 9: Document It
So future-you (or your team) can run it cold
Update the README so someone can run this on their own business: how to edit icp.md, which environment variables they need (ARK_API_TOKEN, and APIFY_API_TOKEN for enrichment), the fact that the AI steps run through Claude Code (so no Anthropic API key), and the order to run the scripts. Keep it short.
🧠 The Concepts Behind It
The prompts get you a working agent. These are the ideas that make it a good one, and they transfer to every agent you build after this.
Agent, not script
A script is hard-coded if/else. An agent has a goal (fill my pipeline with good-fit prospects), a set of tools (a lead source, a scraper, a writer), and judgment (the scoring rubric). That's why one edited file can repoint the whole system at a different business.
ICP as a scoring rubric
"They feel like a good fit" cannot be delegated or automated. Weighted, explicit criteria can. Writing the rubric forces you to articulate what you actually look for, and that alone is worth the exercise even without the agent.
LLM as a judge, with structured output
Every lead is scored the same way: a number, a tier, and a written reason. The reason is the audit trail. When a score looks wrong, you read the reason, fix the rubric, and re-run. The system gets sharper every iteration.
Personalize from real signals
Generic outreach gets ignored, and personalizing by hand does not scale. Scraping public signals gives the drafter something true to say, and referencing something real is the difference between a reply and a delete.
Human in the loop and deliverability
The agent drafts, you approve. Campaigns stay paused until reviewed, and a proper sending platform handles warmup and drip. Your domain reputation is not worth automating away.
Cost awareness
About 1 credit per verified email, printed on every run. An agent that knows what it spends is an agent you can safely scale.
🔧 Make It Yours
The whole system is driven by one file. To run this on your own business:
- Edit icp.md to describe your ideal customer: firmographics, persona, buying signals, and what you offer.
- Run find_leads.py with a small batch (20 leads) and check the quality of what comes back.
- Run the scorer, read the reasons, and tune the rubric weights until the A-tier matches your gut.
- Only then scale the batch size and turn on the weekly schedule.
Iterate on the rubric, not the code. If the leads coming back are wrong, the fix is almost never in the Python. It's in icp.md. Sharper criteria in, better prospects out.
❓ FAQ
Do I need to know how to code?
No. Every prompt in this guide is pasted into Claude Code in plain language. Claude writes the Python, runs it, and fixes its own errors. Your job is describing your ideal customer well.
Do I need an Anthropic API key?
No. The scoring, hook extraction, and email drafting all run through the Claude Code CLI using your existing login. The prompts explicitly steer the build that way.
What does a run actually cost?
Ark AI charges about 1 credit per verified email, so a 20-lead run is about 20 credits, and a small free allowance covers your first builds. Apify's free tier covers the enrichment. Claude usage falls under your existing Claude Code subscription.
Can I use a different lead source or sender?
Yes. The architecture is the point, not the vendors: a sourcing step, a scoring step, an enrichment step, a drafting step, a delivery step. Swap any layer by telling Claude Code which API to use instead, and the rest of the pipeline stays identical.
Is scraping LinkedIn profiles okay?
You're pulling public profile data through established Apify actors for one-to-one sales research, at low volume, on leads you already qualified. Stay away from mass scraping and always review before sending.
Why not just let it send emails automatically?
Deliverability and reputation. The agent's job ends at a reviewed draft in a paused campaign. You approve, the sending platform warms up and drips. That's the difference between a system that fills your pipeline and one that burns your domain.
The leads coming back are off. What do I fix?
The rubric, not the code. Read the one-line scoring reasons, find the pattern in what's scoring too high or too low, and tighten the criteria or weights in icp.md. Then re-run.