๐Ÿ“– 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.

๐Ÿ—๏ธ Architecture

Azure Static Web App index.html (CLI) brain.html (viewer) about.html (docs) api/ (Azure Functions) POST /api/inputs GET /api/shared-brain Cosmos DB (free tier) cludBrain / inputs Partition: /partitionKey

File Structure

/
โ”œโ”€โ”€ index.html                 # Main CLI interface (all HTML/CSS/JS)
โ”œโ”€โ”€ brain.html                 # Brain viewer / admin page
โ”œโ”€โ”€ about.html                 # This page (documentation)
โ”œโ”€โ”€ staticwebapp.config.json   # Azure SWA routing config
โ”œโ”€โ”€ 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 elaboration 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. After 5+ inputs, these reference your learned keywords and topics: "I can see how this relates to the auth module we've been working on."

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 summary with random file/line counts. After 8+ inputs, occasionally references cumulative statistics: "That's 15 tasks we've handled in this project now."

๐Ÿง  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

๐Ÿค” 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.