πŸ“– 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, and nothing you type ever leaves your machine. 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

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)
β”œβ”€β”€ llm-worker.js              # Web Worker host for the in-browser LLM (web-llm)
β”œβ”€β”€ brain.html                 # Brain viewer / admin page
β”œβ”€β”€ about.html                 # This page (documentation)
β”œβ”€β”€ staticwebapp.config.json   # Azure SWA routing config
β”œβ”€β”€ Dockerfile                 # Static serve for local testing (nginx)
β”œβ”€β”€ docker-compose.yml         # `docker compose up` -> localhost:8080
β”œβ”€β”€ nginx.conf                 # Clean-route parity with Azure SWA
β”œβ”€β”€ README.md                  # Setup instructions
└── api/
    β”œβ”€β”€ host.json              # Azure Functions runtime config
    β”œβ”€β”€ package.json           # Dependencies (@azure/cosmos)
    β”œβ”€β”€ shared/
    β”‚   └── cosmos.js          # Cosmos DB client (lazy-init)
    β”œβ”€β”€ inputs/
    β”‚   β”œβ”€β”€ function.json      # HTTP trigger (POST /api/inputs)
    β”‚   └── index.js           # Records user input to Cosmos
    └── shared-brain/
        β”œβ”€β”€ function.json      # HTTP trigger (GET /api/shared-brain)
        └── index.js           # Returns aggregated brain data

πŸ’¬ 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 Tab or clicking 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

After sanitization, learned keywords are highlighted in blue using word-boundary regex, being careful not to highlight inside existing HTML spans.

⌨️ 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

Four app settings configured in the Azure Portal (not GitHub):

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

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 (progress shown in the status bar).

πŸ€” 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.