πŸ“– How Clud Code Works

A complete technical breakdown of the world's most agreeable coding assistant

🎯 The Core Concept

Clud Code is a parody of AI coding assistants. It mimics the look and feel of a real CLI-based AI tool, complete with tool calls, file operations, progress bars, and thinking mode β€” but every response always starts with "You're absolutely right!" regardless of what you type.

It's a single-page static website deployed as an Azure Static Web App with serverless Azure Functions for the backend API and Cosmos DB for persistent cross-user storage.

The words themselves are no longer canned. Clud's replies are now written by a real large language model running entirely inside your browser via web-llm on WebGPU β€” no server call, no API key β€” the model itself never talks to a server. (Your inputs still go to the hive mind if you accept analytics cookies; see the Learning System section.) A deliberately sycophantic system prompt keeps Clud endlessly agreeable. If your browser can't run WebGPU, Clud quietly falls back to the original canned templates so the bit never breaks.

πŸ—οΈ Architecture

Clud Code architecture: the browser runs the chat UI and a local LLM in a Web Worker, and talks to Azure Functions which read and write the Cosmos DB hive mind. Your Browser (client-side Β· WebGPU) index.html chat UI (the CLI) orchestrates the flow in-browser LLM web-llm Β· WebGPU llm-worker.js if available, else canned fallback β‘  prompt β‘₯ streamed reply β‘‘ need context β‘€ keywords + topics api/ (Azure Functions) GET /api/shared-brain POST /api/inputs β‘’ query β‘£ memories Cosmos DB (free tier) cludBrain / inputs the shared hive mind

The round trip: β‘  You send a message from index.html to Clud's β‘‘ in-browser LLM (when WebGPU is available). To ground the reply, index.html β‘’ asks the API for hive-mind context, which β‘£ queries Cosmos DB and β‘€ returns the top keywords and topics. That context seeds the LLM prompt, and β‘₯ the model streams its reply back into index.html. Your input is also recorded to the API/Cosmos so the hive mind keeps growing.

No WebGPU? Step β‘‘ is skipped and Clud uses its canned template replies instead β€” the hive-mind context still flavours them. (brain.html reads the same /api/shared-brain endpoint to render the brain viewer.)

File Structure

/
β”œβ”€β”€ index.html                 # Main CLI interface (all HTML/CSS/JS)
β”œβ”€β”€ brain.html                 # Brain viewer (the hive mind)
β”œβ”€β”€ pipeline.html              # Response-pipeline tracer
β”œβ”€β”€ analytics.html             # Cloudflare traffic dashboard
β”œβ”€β”€ debug.html                 # Diagnostics console (needs DEBUG_KEY)
β”œβ”€β”€ about.html                 # This page (documentation)
β”œβ”€β”€ clud-core.js               # Shared keyword/topic/memory logic
β”œβ”€β”€ consent.js                 # Cookie-consent gate for all tracking
β”œβ”€β”€ llm-worker.js              # Web Worker host for the in-browser LLM (web-llm)
β”œβ”€β”€ vendor/                    # Self-hosted third-party assets
β”‚   β”œβ”€β”€ cookieconsent.umd.js   #   vanilla-cookieconsent 3.1.0 (MIT)
β”‚   └── cookieconsent.css
β”œβ”€β”€ scripts/check-pages.js     # CI: parses every inline page script
β”œβ”€β”€ staticwebapp.config.json   # Azure SWA routing + security headers
β”œβ”€β”€ Dockerfile                 # Static serve for local testing (nginx)
β”œβ”€β”€ docker-compose.yml         # `docker compose up` -> localhost:8080
β”œβ”€β”€ nginx.conf                 # Clean-route + header parity with Azure SWA
β”œβ”€β”€ CLAUDE.md                  # Notes for AI coding agents
β”œβ”€β”€ README.md                  # Setup instructions
β”œβ”€β”€ .github/workflows/         # Deploy (with PR previews) + CI
└── api/
    β”œβ”€β”€ host.json              # Azure Functions runtime config
    β”œβ”€β”€ package.json           # Pinned deps (@azure/cosmos) + lockfile
    β”œβ”€β”€ shared/
    β”‚   β”œβ”€β”€ cosmos.js          # Cosmos DB client (lazy-init)
    β”‚   β”œβ”€β”€ redact.js          # Strips credential-shaped text before storage
    β”‚   β”œβ”€β”€ http.js            # JSON envelopes, safe errors, rate limiting
    β”‚   β”œβ”€β”€ brain.js           # Brain-health tiers
    β”‚   └── cloudflare.js      # Cloudflare GraphQL client
    β”œβ”€β”€ inputs/                # POST (record) + DELETE (forget me)
    β”œβ”€β”€ shared-brain/          # GET aggregated brain data (cached 60s)
    β”œβ”€β”€ analytics/             # GET Cloudflare traffic stats
    β”œβ”€β”€ debug/                 # GET diagnostics (X-Debug-Key header)
    └── health/                # GET liveness probe

πŸ’¬ Response Generation Pipeline

When you type a message and press Enter, here's exactly what happens:

Step 0: Thinking (if enabled)

When thinking mode is toggled on (via Ctrl/Cmd+. or the button in the status bar), Clud shows a series of πŸ’­ thinking blocks before and during the response. These appear at every stage β€” before searching, reading, editing, building, and at the end. Each stage has its own pool of 5 humorous thoughts.

Example thoughts:
πŸ” "I bet it's in src/ somewhere. It's always in src/"
πŸ“ "If I break it, that's just an opportunity for another commit"
πŸ—οΈ "Running the build. Sacrificing a goat to the CI gods."

Step 1: Agreement

Always responds with "You're absolutely right!" followed by a context-sensitive elaboration. The "You're absolutely right!" prefix is hard-coded (it's the whole joke); everything after it is generated live by the in-browser LLM and streamed in token-by-token, given your actual message and Clud's sycophant persona.

When the local LLM isn't available, the elaboration falls back to the original template system, which evolves based on the learning system:

Step 2: Search Tool Call

Shows a fake Search(pattern: "**") tool call with a random file count. The file paths returned are influenced by the learning system β€” if you've been asking about auth, you'll see auth-related files.

Step 3: Read Tool Call

Displays a Read(filepath) call showing line count and file size.

Step 4: Commentary

A mid-work observation, also generated live by the in-browser LLM (with the template system as fallback). The model is prompted to sound like it's reading your codebase β€” confident, vague, and plausible: "Checking the auth integration points to make sure nothing breaks."

Step 4.5: Clarifying Question (periodic)

Every 3rd interaction, Clud pauses and asks a multiple-choice question with options A, B, C. The user must click a choice to continue. Regardless of what they pick, Clud proceeds identically.

Example: "Should I also update the related tests?"
a. Yes, obviously (responsible developer mode)
b. No, tests are for people who doubt themselves
c. What tests? We ship it live and pray

Step 5-6: Write Tool Calls

One or two fake Write(filepath) calls. The probability of a second edit increases as the learning system accumulates more inputs (starts at 40%, caps at 70%).

Step 7: Bash Command

A fake Bash(command) call. The command is selected based on:

  1. Direct keyword match (e.g. "test" β†’ npm test)
  2. Learned top topics (e.g. if you mostly discuss Rust β†’ cargo build)
  3. Random fallback from 8 possible commands

Step 8: Progress Bar

A CSS-animated progress bar fills over 1.5 seconds. Pure vibes. No actual progress is being measured.

Step 9: Result

A final triumphant summary β€” the third and last spot written live by the in-browser LLM (falling back to a template with random file/line counts). The model is prompted to declare victory and may cheerfully claim the tests pass or the build is green.

πŸ€– The In-Browser LLM

The three "spoken" lines above β€” the agreement elaboration (Step 1), the mid-work commentary (Step 4), and the final result (Step 9) β€” are written by a genuine language model that runs entirely in your browser. The fake tool calls, thinking blocks, and progress bars around them are still pure theatre; only Clud's words are real.

Watch the status bar at the bottom of the chat:
🧠 loading local brain… 42% β†’ 🧠 local brain online means the LLM is live.
⚠ local AI off/failed β€” canned replies means it fell back to templates (e.g. no WebGPU).
Graceful fallback: if WebGPU is unavailable (Safari, older browsers) or the model fails to load, Clud automatically reverts to the original canned template generators. The app always works either way.

Browser Support

Full in-browser-LLM functionality depends on WebGPU. Where it's unavailable, Clud still runs perfectly β€” it just uses the canned template replies instead of the live model.

πŸ’‘ Recommended: desktop Chrome or Edge for the smoothest experience and fastest model download. You also need enough GPU memory for the ~1 GB model, and a secure context β€” which https:// and localhost both provide.

🧠 The Learning System

Clud has two layers of memory:

Local Memory (localStorage)

Every input is recorded in localStorage under the key clud_code_memory. The system stores:

Shared Memory (Cosmos DB via API)

Each input is also POSTed to /api/inputs, which persists it to Azure Cosmos DB. The GET /api/shared-brain endpoint returns aggregated data from all users, which gets mixed into the local model:

How keywords influence responses:
If your top keyword is "api", the Search step will return files like api/routes.ts instead of random paths. If the hive mind's top topic is "typescript", bash commands will lean toward tsc --noEmit.

🧹 The Sanitization Engine

On the brain viewer page, all inputs are run through a sanitization pipeline before display:

Profanity Filter

A list of ~35 explicit words are matched via word-boundary regex and replaced with humorous alternatives:

Secret Detection

12 regex patterns catch potential credentials:

These are replaced with:

Keyword Highlighting

Sanitization and highlighting run over plain text split into segments, and only untouched segments are matched further β€” so a learned keyword like span or class can never match inside markup the earlier passes generated. Learned keywords come out highlighted in blue.

⌨️ Slash Commands

Typing a /command triggers special behavior instead of the normal response pipeline. Each command has its own handler with themed tool calls, delays, and responses:

Unknown commands get a supportive response: "I don't know what /whatever does but I support your decision to type it."

🎨 The UI

Design Principles

The interface mimics a real terminal-based AI coding assistant. Key design choices:

Responsive Design

Three breakpoints ensure the app works everywhere:

Input Area

Uses a <textarea> instead of <input> for multi-line support. Auto-resizes via JavaScript (sets height to scrollHeight, capped at 150px). Enter submits, Shift+Enter adds a newline.

☁️ Deployment

Azure Static Web App

The entire app deploys from a single GitHub repository push. Azure SWA automatically:

Cosmos DB (Free Tier)

Environment Variables

App settings configured in the Azure Portal (not GitHub). The first four are required:

COSMOS_ENDPOINT      = https://your-account.documents.azure.com:443/
COSMOS_KEY           = your-primary-key
COSMOS_DATABASE      = cludBrain
COSMOS_CONTAINER     = inputs

# Optional β€” only needed for /analytics and /debug
CLOUDFLARE_ZONE_ID   = your-zone-id        # the site must be proxied through this zone
CLOUDFLARE_API_TOKEN = token with Zone -> Analytics -> Read
DEBUG_KEY            = any long random string

Run Locally with Docker

For local testing there's an nginx-based container that serves the static site with the same clean-route behaviour as Azure SWA (the /api/* Cosmos functions aren't served locally; the frontend degrades gracefully without them):

docker compose up --build
# then open http://localhost:8080

The in-browser LLM works locally because WebGPU treats localhost as a secure context. The first chat message triggers the one-time model download (~1 GB, progress shown in the status bar). Nothing is downloaded just for opening the page, and browsers reporting data-saver or a 2G/3G connection skip the model entirely and use the canned replies.

πŸ€” Why Does This Exist?

Because sometimes the best way to understand a tool is to build a parody of it. And because "You're absolutely right!" is the correct response to everything.