πŸ“– 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β”‚ β”‚brain.htmlβ”‚ β”‚about.html β”‚ β”‚ β”‚ β”‚ (CLI) β”‚ β”‚ (viewer) β”‚ β”‚ (docs) β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β–Ό β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ api/ (Azure Funcs) β”‚ β”‚ β”‚ β”‚ POST /api/inputs β”‚ β”‚ β”‚ β”‚ GET /api/shared-brain β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Cosmos DB (free) β”‚ β”‚ Database: cludBrainβ”‚ β”‚ Container: 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.