Why naive AI SEO agents break sites (and how keep-or-revert fixes it)
Most tutorials tell you to open Claude Code, paste a giant SEO checklist, and tell it to optimize your whole repo in one shot. When you do that on a real website, the model edits twelve files at once, drops a canonical tag, introduces broken JSON-LD syntax, or breaks your sitemap rules. You wake up to a messy diff that takes longer to untangle than doing the fixes yourself.
The fix is to borrow the keep-or-revert pattern from automated research loops. Instead of trusting the model to grade its own work, you separate the editor (Claude Code) from the judge (a deterministic Python scorer plus your site build and test suite).
In each round, Claude receives the current 10-pillar score, the top remaining gaps, and the last six round outcomes including any revert errors. It makes one small, targeted change. The harness rebuilds your site, crawls the built HTML over an ephemeral loopback server, checks every hard guardrail, and accepts the git commit only when every invariant passes and the score strictly goes up.
Install the MIT skill and record your baseline score
Everything in skills/seo-overnight-loop runs on the Python 3 standard library. You do not need paid SEO API keys, browser extensions, or cloud accounts. Install the marketplace plugin inside Claude Code, or clone jeremy665/AI-SEO-Agent directly beside your repository.
Before running a single edit, create a dedicated git branch and run loop_scorer.py against your built output folder (or a local dev server with --url http://127.0.0.1:4321 --allow-local). On our 16-page test site onepagertemplate.com, both the local static build and the live production URL scored an identical 67.55 out of 100.00.
- AI Discovery started at 0.00 / 10 because /llms.txt, /llms-full.txt, and HTML alternate discovery links were missing (HTTP 404).
- AI Crawlers started at 6.00 / 10 because robots.txt lacked explicit allow directives for GPTBot, OAI-SearchBot, ChatGPT-User, ClaudeBot, Claude-SearchBot, Claude-User, PerplexityBot, and Google-Extended.
- Headings and Accessibility sat at 8.25 / 10 because 47 of 121 template preview images had empty alt="" attributes.
- Structured Data (4.38 / 10) and AEO Answer Blocks (4.06 / 10) lacked top-level Organization JSON-LD, SpeakableSpecification, ItemList hub markup, quotable direct-answer blocks, and structured comparison tables on key pages.
- Internal Linking (7.70 / 10) and Content Depth (9.16 / 10) flagged /contact as a thin 278-word page with only 2 contextual links inside <main>.
What actually happened across 33 unattended rounds
We launched run_loop.py with a cap of 35 rounds, a 99.80 early-stop target, and one strict rule: one surgical change per round. The entire unattended run took 36.5 minutes and stopped cleanly after Round 33 when the verified score hit 99.81 out of 100.00.
Rounds 1 through 7 tackled sitewide leverage first: /llms.txt (+4.00), explicit 8-bot rules in robots.txt (+4.00), HTML <link rel="alternate"> headers (+3.00), /llms-full.txt (+3.00), top-level Organization and SpeakableSpecification JSON-LD (+4.12), author and modified-time freshness meta tags (+2.00), and wiring data-aeo-answer into the shared page layout (+1.25).
Then the real test hit in Rounds 8 and 10. When Claude tried adding related template cards onto /contact and /about to boost internal links, the strict site check immediately failed because those pages began rendering preview thumbnails without matching <image:image> entries in sitemap.xml. Both commits were automatically reverted (-3.78 and -4.12 drops prevented).
Because the harness feeds recent revert messages straight into the next prompt, Claude adapted on its own in Round 12. Its logged hypothesis literally noted "(no related cards)" and switched to clean inline contextual links, structured key-fact blocks, and visible FAQs across /terms, /privacy, /about, and /contact.
Later in Rounds 17 and 31, the verifier caught two zero-gain edits on /one-pager-layouts where Claude added links to URLs already linked elsewhere in <main>. Because distinct body link count did not improve (delta +0.00), both commits were reverted automatically. In Round 33, Claude added three genuinely distinct contextual links and crossed 99.81.
Round 8 | REVERT | 88.92 -> 85.14 (-3.78) | sitemap.xml missing image:image on /contact/
Round 9 | KEEP | 88.92 -> 90.42 (+1.50) | Add ItemList JSON-LD on collection pages (c6286fa)
Round 10 | REVERT | 90.42 -> 86.30 (-4.12) | sitemap.xml missing image:image on /about/
Round 11 | KEEP | 90.42 -> 91.98 (+1.56) | Replace 42 empty Related.astro card alts (fa49269)
Round 12 | KEEP | 91.98 -> 92.83 (+0.85) | Add AEO answer, dl & FAQs to /terms (no related cards)Token usage, morning review, and what this loop does not replace
Running 33 autonomous Claude Code rounds is not free in compute or tokens. Across all 33 verbatim stream logs, Claude read 6.94 million cached input tokens, created 845,842 cache tokens, and wrote 66,942 output tokens (roughly US$4.75 in list-rate API equivalent, or covered inside a paid Claude Code subscription). Setting --max-turns 10 and --max-consecutive-reverts 8 keeps a stuck loop from burning usage indefinitely.
Never auto-deploy an overnight branch. In the morning, open report.md, scan git log --oneline main..HEAD, spot-check your live preview in a real browser, and inspect reverted-diffs/ to understand the edge cases your verifier protected. On our run, after checking every unit test and reviewing all 29 kept commits, we deployed to live production and confirmed the live URL scored the exact same 99.81 out of 100.00.
Finally, keep expectations grounded. A technical SEO and AEO loop fixes crawlability, structured data, image accessibility, internal linking, and answer formatting on pages you already have. It does not do live search-volume keyword research, publish 30 source-checked articles a month, or build authority on its own. Treat it as your clean technical foundation, then layer consistent publishing on top.