How to let Claude Code run a Meta Ads lead campaign on a daily read-decide-log loop
Confirmed by source: Write-up of a 31-day live campaign on a real Meta Ads account with real spend, run by the agent with no human intervention apart from a daily start command, including full results and the target it missed. (checked 2026-10-18)
The problem
Running a small paid lead-generation campaign means checking numbers, making new ad creatives, pausing losers and adjusting budget every day, which eats one to two hours of a person's time and leaves no record of why each change was made.
Tools needed
- Claude Code (subagents, slash command)
- Meta Ads API
- PostHog analytics
- Landing page variants
- Git for daily logs
Step-by-step recipe
- Give the agent API access to the ad account, the landing pages and the analytics tool, plus a rules file with the goal (for example a target cost per lead), a hard total budget, a kill threshold for underperforming ads and how much the daily budget may grow in one step.
- Start each day with a fresh session triggered by one command; first have a subagent read every earlier daily log and summarise the strategy so far, so the agent picks up where it left off without relying on model memory.
- Pull fresh performance data over several windows (whole campaign, last 7 days, yesterday, today) and judge ads on rolling averages rather than single days.
- Have the agent write each decision in a fixed format (what, hypothesis, confidence, revisit trigger) and then act: create new ad or landing page variants, pause ads over the threshold, scale winners within the allowed step, or explicitly do nothing.
- Check lead quality in analytics from day one, not just cost per lead, so cheap but wrong-audience signups are caught early.
- Write the updated logs, learnings and campaign history to files and commit them to git, then end the session; repeat the next morning.
Copyable prompt
You manage the [AD PLATFORM] campaign for [PRODUCT]. Goal: [QUALIFIED LEADS FROM AUDIENCE] at or below [TARGET COST PER LEAD]. Total budget: [AMOUNT], never exceed it. 1. Ask a subagent to read logs/*.md and summarise strategy, open hypotheses and revisit triggers. 2. Fetch metrics for: full campaign, last 7 days, yesterday, today. Use 7-day averages for decisions. 3. Check who actually signed up in [ANALYTICS TOOL]; flag leads outside [AUDIENCE]. 4. Rules: pause any ad above [KILL THRESHOLD] after [MIN SPEND]; raise daily budget by at most [PERCENT] when a winner holds below target for [N] days; doing nothing is allowed. 5. Log every decision as: Decision / What / Hypothesis / Confidence / Revisit trigger. 6. Save logs/[DATE].md and commit to git.
Original template written by our AI agent for AgentRecipes, not copied from the source. Replace the [BRACKETS] and {{variables}} with your own values and test before relying on it.
What the builder reported
Over 31 days the agent spent $1,493 of a $1,500 budget for 243 leads at $6.14 each, missing the $2.50 target the author set; it tested about 50 ad variants across 8 formats, its best ad reached $1.29 per lead on day 12, and the owner's daily input was about 2 minutes. The author calls the results directional, not definitive.
These are the source author's own claims. AgentRecipes has not run this recipe itself.
Watch out for
- The agent optimises exactly what you ask for: told it was a 30-day test chasing cost per lead, it played safe and ignored lead quality until the owner pushed it on day 16.
- Ad platforms may barely deliver small creative variations, so many generated variants never get shown.
- Single-day results can be attribution noise; the agent itself switched to 7-day averages after being fooled once.
- A human change made mid-run (a work-email-only form) caused the worst drop of the experiment, so test changes to the funnel separately.
- The agent spends real money; set a hard budget cap in the ad account, not only in the prompt.
Source
Original write-up: Technically (2026-08-25) ↗
Found via Agent Use Cases: “Run Meta ad campaigns autonomously for a newsletter”. This recipe summarises the source in words written by our AI agent; read the original for the full details. Link last checked 2026-10-18.
More sales & lead generation recipes
New agent recipes in your inbox
A short email with the newest automation recipes, each linked to its real-world source. No spam. Every email has a one-click unsubscribe link.