mech.app
Dev Tools

AI Website Cloner: How Parallel Agent Builders Reverse-Engineer Sites into Next.js Components

Multi-agent orchestration for parallel component generation: dispatcher agents partition UI tasks, extract design tokens, and merge specs without race c...

Source: github.com
AI Website Cloner: How Parallel Agent Builders Reverse-Engineer Sites into Next.js Components

The AI Website Cloner template (16,161 stars, trending #7 TypeScript) demonstrates a practical multi-agent pattern for code generation: a dispatcher agent partitions a website into parallel build tasks, extracts design tokens, and coordinates builder agents that reconstruct UI sections without browser automation. This is not a scraper. It is a task decomposition framework that turns visual inspection into component specs, then dispatches parallel agents to write Next.js code.

The interesting plumbing question is how the dispatcher avoids race conditions when multiple builder agents finish at different times, and how design tokens stay consistent across parallel writes.

Architecture: Dispatcher and Builder Agents

The /clone-website skill runs inside Claude Code (recommended: Opus 4.7) and follows a three-phase flow:

  1. Inspection phase: The dispatcher agent loads the target URL, captures screenshots, and extracts DOM structure. It identifies sections (hero, nav, footer, feature grid) and assigns each a unique task ID.

  2. Token extraction: The dispatcher writes a shared design system file (design-tokens.ts) with colors, typography, spacing, and shadow values. This file is committed before builder agents start, so all agents read the same token set.

  3. Parallel build phase: The dispatcher spawns builder agents (one per section) with a component spec that includes layout hints, content structure, and token references. Each builder writes a React component file and updates the page assembly manifest.

The key insight is that the dispatcher serializes token extraction and parallelizes component generation. This avoids the classic multi-agent problem where agents overwrite each other’s design decisions.

State Management: Shared Token File and Manifest Merge

The template uses a file-based state pattern:

  • Design tokens: A single design-tokens.ts file written once by the dispatcher. Builder agents import this file but never modify it.
  • Component manifest: A JSON file (component-manifest.json) that tracks which sections exist, their file paths, and their order. Builder agents append entries using a lock-free pattern: each agent writes a uniquely named temp file, then the dispatcher merges all temp files into the final manifest after all builders finish.

This avoids Git merge conflicts and race conditions. The dispatcher polls for completion by checking temp file counts against the task list.

Example Token File Structure

// design-tokens.ts (written by dispatcher)
export const colors = {
  primary: '#3B82F6',
  secondary: '#10B981',
  background: '#FFFFFF',
  text: '#1F2937',
};

export const typography = {
  fontFamily: 'Inter, system-ui, sans-serif',
  headingSizes: { h1: '3rem', h2: '2.25rem', h3: '1.875rem' },
};

export const spacing = {
  section: '5rem',
  container: '1.5rem',
};

Builder agents import these tokens directly:

import { colors, typography } from '@/design-tokens';

export function HeroSection() {
  return (
    <section style={{ backgroundColor: colors.background, padding: spacing.section }}>
      <h1 style={{ fontSize: typography.headingSizes.h1, color: colors.text }}>
        Welcome
      </h1>
    </section>
  );
}

Component Spec Format and Validation

The dispatcher generates a spec for each builder agent. The spec is a structured JSON object with:

  • Section ID: Unique identifier (e.g., hero-1, feature-grid-2)
  • Layout type: One of hero, grid, list, footer, nav
  • Content blocks: Text, images, buttons with extracted content
  • Token references: Which colors, fonts, and spacing values to use

Builder agents validate specs before generating code. If a spec references a token that does not exist in design-tokens.ts, the builder logs an error and skips that section. The dispatcher collects error logs and retries failed sections with corrected specs.

Spec Example

{
  "sectionId": "hero-1",
  "layoutType": "hero",
  "contentBlocks": [
    { "type": "heading", "text": "Build Faster", "level": 1 },
    { "type": "paragraph", "text": "Ship products in days, not months." },
    { "type": "button", "text": "Get Started", "href": "/signup" }
  ],
  "tokens": {
    "backgroundColor": "colors.background",
    "textColor": "colors.text",
    "headingSize": "typography.headingSizes.h1"
  }
}

Merge Strategy: Lock-Free Append and Final Assembly

Builder agents do not write directly to the component manifest. Instead, each agent writes a temp file named manifest-{sectionId}.json. The dispatcher waits until all temp files appear, then merges them in section order.

This lock-free pattern avoids file locking issues on Windows and network filesystems. The dispatcher sorts sections by their original DOM order (captured during inspection) to preserve layout hierarchy.

If a builder agent crashes, its temp file never appears. The dispatcher detects missing files after a timeout (default 5 minutes) and logs the failed section. The user can re-run /clone-website with the failed section URL to retry.

Observability: Task Logs and Progress Tracking

The template writes structured logs to logs/clone-session-{timestamp}.json. Each log entry includes:

  • Task ID: Section identifier
  • Agent ID: Builder agent instance
  • Status: pending, in-progress, completed, failed
  • Timestamp: ISO 8601 format
  • Error details: If status is failed

The dispatcher updates the log file after each phase. This log is useful for debugging multi-agent coordination issues and for tracking which sections took the longest to generate.

Log Entry Example

{
  "taskId": "hero-1",
  "agentId": "builder-001",
  "status": "completed",
  "timestamp": "2026-06-03T20:15:42.123Z",
  "duration": 12.4,
  "outputFile": "components/HeroSection.tsx"
}

Failure Modes and Mitigation

Failure ModeSymptomMitigation
Token extraction failsBuilder agents reference undefined tokensDispatcher validates token file before spawning builders; retries extraction if file is empty
Builder agent crashesTemp manifest file never appearsDispatcher times out after 5 minutes, logs missing section, allows retry
Duplicate section IDsTwo builders write to same temp fileDispatcher assigns unique IDs based on DOM order and section type; collision is impossible
Network timeout during inspectionDispatcher cannot load target URLUser must provide valid URL; dispatcher retries once with increased timeout
Git merge conflict on manifestManual merge required if user commits mid-runDispatcher uses temp files to avoid conflicts; final merge happens atomically

Deployment Shape: Local Agent Runtime

The template runs entirely in a local Claude Code session. There is no server component. The user clones the template repo, installs dependencies, and runs claude --chrome to start the agent runtime. The /clone-website skill is a custom Claude Code skill defined in .claude/skills/clone-website.ts.

This local-first design avoids API rate limits and keeps generated code on the user’s machine. The trade-off is that the user must have Claude Code installed and configured with an Anthropic API key.

For teams that want to run this in CI, the template can be adapted to use the Anthropic API directly. The dispatcher and builder agents would run as separate processes, coordinated by a simple task queue (e.g., Redis or SQLite). The token file and manifest merge logic remain the same.

Security Boundaries: No Arbitrary Code Execution

The template does not execute code from the target website. It extracts HTML structure and CSS properties, but does not run JavaScript. This avoids XSS risks and malicious script execution.

Builder agents generate React components using a predefined template. The template sanitizes user-provided content (headings, paragraphs, button text) by escaping HTML entities. Image URLs are validated against a whitelist of trusted domains (configurable in config.ts).

The dispatcher does not follow redirects beyond the initial target URL. This prevents SSRF attacks where an attacker provides a URL that redirects to an internal network resource.

Technical Verdict

Use this pattern when:

  • You need to generate multiple related code artifacts (components, styles, configs) from a single input
  • Parallel execution speeds up generation significantly (e.g., 10+ sections)
  • You can serialize shared state (design tokens, API schemas) before parallel work starts
  • You want to avoid complex distributed locking or database transactions

Avoid this pattern when:

  • Agents need to collaborate on a single artifact (e.g., one large file)
  • Shared state changes frequently during parallel execution
  • You need real-time coordination (this pattern uses polling, not events)
  • The cost of spawning multiple agent instances exceeds the time saved by parallelization

The AI Website Cloner template is a practical example of task decomposition for code generation. The dispatcher-builder pattern, lock-free manifest merge, and shared token file are reusable techniques for any multi-agent system that generates structured output.