Intermediate

Paste this guide into Claude Code and it will walk you through every step interactively.

Generate Winning Ads While You Sleep

What this gives you: A system that generates ad copy variations, creates visual assets, tracks what works, and continuously improves your cost per lead. The Karpathy method applied to advertising.

Most people write one ad, run it, wonder why it underperforms, and give up. The ones who win run structured experiments, log every result, and let the data drive the next iteration. This guide gives you that system.

The Auto-Research Loop

Andrej Karpathy popularised a simple but powerful framework for continuous improvement in any measurable system. It works just as well for ad creative as it does for neural networks.

The loop has five steps:

  1. Define your metric. For ads, this is CPL - cost per lead. Pick one number and track only that.
  2. Form a hypothesis. A specific, falsifiable statement. "Demo-first hooks will lower CPL by 20% compared to pain-point hooks."
  3. Make the change. Change exactly one variable. If you change two things at once, you learn nothing.
  4. Assess the result. Run for at least 48 hours with equal budget. Compare CPL, CTR, and conversion rate.
  5. Log and repeat. If the variant wins, it becomes the new control. If it loses, you still log the result - negative findings are data too.

Applied to ads: your baseline is your current best-performing creative. Every test is a hypothesis about what will beat it. Claude Code generates the variants. You run the numbers. The loop runs continuously.

Tip: Run your first 3 tests before trying to optimize. You need baseline data before the loop becomes useful. Without a baseline CPL, you have no reference point for what "better" actually means.

Ad Copy Generation

Use this prompt template in Claude Code to generate Facebook and Meta ad variations. Swap the bracketed fields for your business, and run it every time you need a new batch of creative.

# Ad copy generation prompt claude "Write 5 Facebook ad variations for [BUSINESS TYPE]. Target audience: [ICP DESCRIPTION] Offer: [YOUR OFFER] Tone: Direct, no fluff, proof-driven Format: Hook (1 line) + Body (3-4 lines) + CTA (1 line) Rules: - Lead with a specific result or demo, not a pain point - Include a number in the hook - No rhetorical questions - No 'tired of...' or 'struggling with...'"

The rules section does most of the work. "Lead with a specific result" forces demo-first hooks. "Include a number" forces specificity. Banning rhetorical questions and pain-point openers eliminates the two most overused formulas in direct response advertising.

Run this prompt, take the 5 outputs, and pick the 2-3 that feel most authentic to your offer. Those go into testing. The rest go into a swipe file for future reference.

What Makes Hooks Work

Demo-first hooks outperform everything else. This is not a theory - it is consistently the highest-performing format across performance data going back years. The reason is simple: a demo proves the claim before the reader has time to object.

Hook Type Example Why It Performs
Demo-first (best) "We booked 47 appointments last month using one AI voice agent." Specific result + implicit proof. The number does the selling.
Outcome-first "Our clients cut their CPL from $42 to $14 in 30 days." Comparison creates contrast. Before/after is a powerful frame.
Curiosity (use carefully) "This one change dropped our no-show rate by 60%." Works only when the mechanism is genuinely non-obvious.
Pain-point (weakest) "Tired of chasing leads that never convert?" Every competitor writes this. Reader is desensitised to it.
Rhetorical question (avoid) "Struggling to fill your calendar?" Signals low confidence in the offer. Readers scroll past.

The practical rule: if your hook could apply to any business in your space, it is too generic. "We booked 47 appointments for a solar installer in Bristol in March" is specific enough that it could only be you.

Visual Creative with fal.ai

Use Nano Banana 2 via fal.ai for ad image generation. The same principles that apply to thumbnails apply here: use real photos of real people, keep compositions simple, and treat text as a design element rather than an afterthought.

# fal.ai prompt template for ad creative "Professional marketing image for a [BUSINESS TYPE] advertisement. Setting: [LOCATION/CONTEXT] Subject: [YOUR REAL HEADSHOT or STOCK PERSON] in foreground Prop: [ONE RELEVANT PROP ONLY - laptop, phone, product] Lighting: clean, bright, professional Background: clean or contextually relevant, not busy Text area: leave [TOP/BOTTOM] 30% clear for ad copy overlay Style: high-contrast, direct-response ad creative, no clutter"

Three rules for ad visuals that consistently outperform:

Warning: Never use AI-generated faces of real people in ads. Use your actual photos or stock images. AI face generation in advertising can create legal liability around likeness rights, false endorsement, and platform policy violations across Meta and Google.

The Testing Framework

Every test needs four defined elements before you run it. Without these, you cannot interpret the result.

# Test structure - fill this in before launching Control: [YOUR CURRENT BEST PERFORMER - the ad you are trying to beat] Hypothesis: [ONE SPECIFIC CHANGE AND WHY IT SHOULD WIN] Example: "Demo-first hook vs pain-point hook - demo should lower CPL by showing proof before the ask" Budget: [EQUAL SPEND, MINIMUM $10-15/day per variant] Duration: [48 HOURS MINIMUM - less than this is noise] Metrics: CPL (primary), CTR (secondary), conversion rate (secondary)"

The single-variable rule is non-negotiable. If you change the hook and the image in the same test, you will not know which change drove the result. Discipline here is what separates useful data from expensive guesses.

After 48 hours, check three numbers in order:

  1. CPL. The primary metric. If it is lower on the variant, the variant wins.
  2. CTR. If CPL is similar but CTR is higher on the variant, the variant has better hooks but the landing page may be the bottleneck.
  3. Conversion rate. If CTR is high but CPL is high, the landing page is failing the ad's promise.

The winner becomes the new control. The loser gets logged. Both outcomes advance the loop.

Logging Results

Create a file called ad-tests.md in your project folder. Every test goes in here in exactly this format:

## Test 012 - 2024-03-15 Hypothesis: Demo-first hook beats pain-point hook Control: "Struggling to fill your pipeline?" (CPL: $23) Variant: "We booked 47 appointments last month with one voice agent." (CPL: $14) Result: -39% CPL. Demo hooks win. Action: New control. Apply demo-first to all campaigns. ## Test 013 - 2024-03-22 Hypothesis: Number in hook increases CTR vs no number Control: "We booked 47 appointments last month..." (CPL: $14, CTR: 2.1%) Variant: "47 appointments. 1 AI agent. 30 days." (CPL: $16, CTR: 2.8%) Result: CTR up but CPL up - higher click volume, lower conversion. Action: Revert. Keep control. Investigate landing page for this audience.

The format matters. Hypothesis first forces you to commit before you see results. Logging the action means future-you can see the full decision chain, not just the data points. Over time, this file becomes a proprietary research asset - no competitor has your specific data about your specific audience.

Scaling with Sub-Agents

When you need 25+ variations across multiple angles, single-agent generation is too slow and too expensive. Use Claude Code's parallelization pattern instead.

# Fan out: 5 Sonnet agents in parallel, each with a different angle claude -p "Write 5 Facebook ad variations for [BUSINESS]. Angle: Focus on SPEED of results. How fast does the client see ROI? Format: Hook + Body (3-4 lines) + CTA. Demo-first hooks only." --model claude-sonnet-4-5 > angle-speed.txt & claude -p "Write 5 Facebook ad variations for [BUSINESS]. Angle: Focus on PROOF. Use case studies, numbers, client results only. Format: Hook + Body (3-4 lines) + CTA. Demo-first hooks only." --model claude-sonnet-4-5 > angle-proof.txt & claude -p "Write 5 Facebook ad variations for [BUSINESS]. Angle: Focus on RISK REVERSAL. What happens if it doesn't work? Format: Hook + Body (3-4 lines) + CTA. Demo-first hooks only." --model claude-sonnet-4-5 > angle-risk.txt & claude -p "Write 5 Facebook ad variations for [BUSINESS]. Angle: Focus on SIMPLICITY. How little work does the client have to do? Format: Hook + Body (3-4 lines) + CTA. Demo-first hooks only." --model claude-sonnet-4-5 > angle-simple.txt & claude -p "Write 5 Facebook ad variations for [BUSINESS]. Angle: Focus on SPECIFICITY. Name the exact audience, exact problem, exact fix. Format: Hook + Body (3-4 lines) + CTA. Demo-first hooks only." --model claude-sonnet-4-5 > angle-specific.txt & # Wait for all agents to complete wait # Fan in: Opus picks the top 3-5 from the full set claude -p "You have 25 Facebook ad variations across 5 angles. Select the best 3-5 based on: specificity of hook, strength of proof, clarity of CTA, and distinctiveness from typical ad copy. Explain why each selected ad is stronger than the alternatives. Ads: $(cat angle-speed.txt angle-proof.txt angle-risk.txt angle-simple.txt angle-specific.txt)" --model claude-opus-4-5

This approach costs approximately 60% less than running the same task sequentially with Opus. Sonnet handles the generation work - which is primarily pattern-following - and Opus handles the synthesis work, which requires genuine comparative judgment.

The output: 3-5 high-confidence ad variants, ranked with reasoning, ready for testing. Run them through your testing framework and start the loop.

Platform-Specific Adjustments

The base prompt generates generic copy. Each platform needs a small modification to the format constraints.

Platform Key Constraint Prompt Adjustment
Facebook / Meta 125 characters for best display in primary text Add: "Primary text: max 125 characters. Hook only. Body in first comment or expanded text."
Google Search Headline: 30 chars, Description: 90 chars Add: "Format: Headline (30 chars max) + Description (90 chars max). No punctuation at end of headline."
Google Display Multiple headlines, responsive format Add: "Write 5 separate headlines (30 chars each) and 5 descriptions (90 chars each) for responsive display."
LinkedIn Professional tone, longer form accepted Add: "Tone: professional but direct. Body can extend to 6-8 lines. Reference business outcomes, not personal pain."

For LinkedIn specifically, replace "tired of" and "struggling with" with outcomes and peer comparisons. LinkedIn audiences respond to "companies in your sector are using X to achieve Y" far better than pain-point framing. The professional context makes peer benchmarking the strongest emotional lever.

Want an AI-powered ad system for your business?

I can build a complete ad generation and testing pipeline for your campaigns.

Book a Call
Next Guide
Write 30 Video Scripts in One Command