01 Overview
NEXUS is a single-file, browser-hosted AI agent built on the Anthropic Claude API. It combines a hacker-aesthetic terminal UI, persistent multi-turn conversation, real-time system visualisation, and hands-free voice command into one self-contained HTML application — no build step, no backend, no dependencies to install.
api.anthropic.com) receives outbound network traffic. Google Fonts CDN is optionally used for typefaces.| Property | Value |
|---|---|
| File | nexus-agent.html — single self-contained file |
| Size | ~12 KB (no external assets; fonts via Google Fonts CDN) |
| Dependencies | None — vanilla HTML / CSS / JS |
| API | Anthropic /v1/messages (claude-sonnet-4-20250514) |
| Browser req. | Chrome 90+, Edge 90+, Safari 15+. Chrome recommended for voice. |
| Voice API | Web Speech API — SpeechRecognition (not available in Firefox) |
02 Architecture
The file is structured into five logical layers, each separated by comment banners inside the source. All state lives in-memory; the only persistence is the conversationHistory[] array for the current session.
Layer Map
Data Flow
03 Boot Screen & Waiting Animation
The boot screen is the first thing a user sees. It serves as both a loading sequence and a brand statement, composed of four independent visual layers stacked via position:fixed.
Visual Layers (bottom → top)
| Layer | Element | Description |
|---|---|---|
| 1 — Matrix Rain | #matrix-canvas | Canvas set to position:fixed with opacity:0.07. Random katakana and hex characters fall on a 50 ms interval. Canvas is shared with the main app behind the UI. |
| 2 — Hex Grid | .hexgrid | SVG <pattern> of 60×52 px hexagons via a filled <rect>. Opacity 0.12. Provides structural depth without competing with foreground. |
| 3 — Foreground | Centred flex column | Pulsing NEXUS logotype (Orbitron 900, CSS glow), subtitle in VT323, loading bar with sweeping gradient pseudo-element, and staggered boot log lines (400 ms → 3900 ms delays). |
| 4 — Corners | .corner ×4 | Four divs with partial border-width at viewport corners, giving a targeting-reticle frame. Pure CSS, zero JS. |
Dismissal
The ENTER NEXUS button appears at delay 4500 ms via animation-delay. Clicking it calls enterApp() which adds the .hidden class, transitioning opacity → 0 and visibility → hidden. The Matrix canvas continues running behind the main UI.
function enterApp() { document.getElementById('waiting-screen').classList.add('hidden'); addLog('Session initialized', 'success'); addLog('All modules loaded', 'info'); }
04 Chat Engine
Conversation History
All messages are stored in a module-level array. The full history is sent on every request so the model maintains context across turns.
const conversationHistory = []; // Before every API call: conversationHistory.push({ role: "user", content: userMessage }); // After every API response: conversationHistory.push({ role: "assistant", content: reply });
System Prompt
The agent's personality is defined in the system field of every API call:
system: `You are NEXUS — an autonomous AI agent. You are precise, technical, and slightly intimidating. You speak like a terminal: concise, direct, with occasional use of system/hacker terminology. You do not use markdown formatting. You keep responses under 3 paragraphs. You address the user as "operator". You occasionally reference your memory system, tools, or reasoning process.`
Message Rendering
Each message is inserted into #messages as a .msg div. User messages align right; agent messages align left. A one-shot CSS animation (msgSlide) fades the bubble in from below. Agent responses gain a .glitch class that plays a 0.4 s text-shadow animation simulating screen artefacts.
A "thinking" placeholder (blinking cursor) is added immediately, then removed and replaced with the real response once the API returns.
05 Voice Command Subsystem
Voice input is powered by the browser-native Web Speech API. No third-party library is required.
Initialisation
function initSpeech() { const SR = window.SpeechRecognition || window.webkitSpeechRecognition; if (!SR) { showToast('Voice not supported'); return null; } const r = new SR(); r.lang = 'en-US'; // BCP-47 locale r.interimResults = true; // live transcription while speaking r.maxAlternatives = 1; return r; }
The recognition object is created lazily on first mic press — not at page load — to avoid unnecessary permission prompts.
Event Lifecycle
| Event | Behaviour |
|---|---|
| onstart | Sets isRecording=true. Adds .recording to mic button (red pulsing glow). Shows waveform visualiser bars. Updates input placeholder. |
| onresult | Joins all transcripts; writes interim text to input field in real time. When final result fires, calls stopVoice() then sendMessage(). |
| onerror | Logs the error type to the event log sidebar and calls stopVoice(). |
| onend | Calls stopVoice() — normalises state regardless of how recognition ended. |
Waveform Visualiser
Five .viz-bar divs animate via CSS keyframes (vizAnim). Each bar cycles its height from 4 px to 20 px on a staggered animation-delay (0 s → 0.4 s), creating a rolling waveform. The container is hidden by default and shown only while isRecording === true.
06 System Metrics Panel
The right sidebar displays simulated real-time telemetry to reinforce the hacker aesthetic. In a production deployment these values would be replaced with actual data from a backend health endpoint.
function updateMetrics() { const cpu = 15 + Math.random() * 35; // 15–50% const ram = 40 + Math.random() * 20; // 40–60% const lat = Math.floor(80 + Math.random() * 120); // 80–200 ms cpuHist.push(cpu); cpuHist.shift(); // rolling 60-sample buffer // … draws canvas sparkline … } setInterval(updateMetrics, 1200);
The sparkline canvas is drawn at 2× pixel density (width = offsetWidth * 2) to avoid blurriness on HiDPI screens. On each tick the 60-sample CPU history is plotted as a continuous path with a green CSS shadowBlur. The canvas clears entirely each frame.
07 Event Log
The log stream in the right sidebar is driven by addLog(message, type). Four severity levels map to colours:
| Type | Colour | Usage |
|---|---|---|
| info | ■ green-dim | Routine operational messages |
| success | ■ green | Confirmations and completions |
| warn | ■ amber | Non-critical notices, pending states |
| err | ■ red | Failures, API errors, voice errors |
Timestamps are injected automatically using toLocaleTimeString with 24 h format. The container has scrollbar-width:none to stay visually clean while still scrollable programmatically via scrollTop = scrollHeight.
An ambient interval fires every 4000 ms and cycles through eight canned log lines, maintaining the illusion of background agent activity when idle.
08 API Connection
NEXUS talks to the Anthropic API to power all AI responses. You need an API key to activate it. There are two ways to connect — choose based on whether you are testing locally or deploying for others.
Getting Your API Key
nexus-local).sk-ant- and is shown only once.Direct Browser Call
Fastest way to get NEXUS running. Your key lives directly in the HTML file. Use only for personal local testing — never deploy this publicly.
Open nexus-agent.html, find the callClaude() function, and update the fetch() headers:
const response = await fetch('https://api.anthropic.com/v1/messages', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': 'sk-ant-YOUR-KEY-HERE', // ← your key 'anthropic-version': '2023-06-01', // ← required 'anthropic-dangerous-direct-browser-calls': 'true' // ← allows browser origin }, body: JSON.stringify({ /* existing body unchanged */ }) });
That's it. Save the file, open it in Chrome, and NEXUS is live.
Proxy Server (Recommended)
A lightweight proxy sits between NEXUS and Anthropic. Your key stays on the server — the browser never sees it. This is the correct pattern for any shared or deployed instance.
Step 1 — Create the proxy (Node.js / Express):
const express = require('express'); const app = express(); app.use(express.json()); // Allow NEXUS (served from any origin) to reach the proxy app.use((req, res, next) => { res.setHeader('Access-Control-Allow-Origin', '*'); res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); if (req.method === 'OPTIONS') return res.sendStatus(200); next(); }); app.post('/v1/messages', async (req, res) => { const response = await fetch('https://api.anthropic.com/v1/messages', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': process.env.ANTHROPIC_API_KEY, // key from env var 'anthropic-version': '2023-06-01', }, body: JSON.stringify(req.body), }); const data = await response.json(); res.json(data); }); app.listen(3000, () => console.log('Proxy running → http://localhost:3000'));
Step 2 — Start the proxy:
npm install express ANTHROPIC_API_KEY=sk-ant-your-key node proxy.js
Step 3 — Point NEXUS at the proxy. In callClaude() change the fetch URL:
// Before (direct to Anthropic): fetch('https://api.anthropic.com/v1/messages', ...) // After (through your proxy): fetch('http://localhost:3000/v1/messages', ...)
No other changes needed. The proxy forwards all request bodies and responses transparently.
wrangler secret put ANTHROPIC_API_KEY.Which method should I use?
| Situation | Method |
|---|---|
| Testing locally, just you | Direct browser call with key in headers |
| Sharing with friends / colleagues | Node proxy on your machine or a VPS |
| Public deployment / production | Cloudflare Worker or server-side proxy with rate limiting |
09 Extending NEXUS
Changing the Model
// Current (balanced performance / cost) model: 'claude-sonnet-4-20250514', // Haiku — lower latency and cost model: 'claude-haiku-4-5-20251001', // Opus — maximum capability model: 'claude-opus-4-6',
Modifying Agent Personality
Edit the system string inside callClaude(). The prompt is sent on every request so changes take effect immediately from the next message. You can make NEXUS more verbose, change its address style, give it a domain focus, or instruct it to simulate tool calls.
Adding Tools (UI Only)
The left sidebar tool list is decorative in v3.0.1. To add a display entry:
<div class="side-item active"> <span class="dot"></span>your_tool_name </div>
To wire real tool execution, implement Anthropic's tool_use API pattern: define tools in the request body, parse tool_use content blocks in the response, execute client-side, and return a tool_result in the next message turn.
Context Window Management
const MAX_TURNS = 20; const recentHistory = conversationHistory.slice(-MAX_TURNS); // use recentHistory in the API call instead of conversationHistory
Persisting Conversations
function saveHistory() { localStorage.setItem('nexus_history', JSON.stringify(conversationHistory)); } // On page load: const saved = localStorage.getItem('nexus_history'); if (saved) conversationHistory.push(...JSON.parse(saved));
Real Backend Metrics
{
"cpu": 23.4, // percentage 0–100
"ram": 51.2, // percentage 0–100
"latency": 142 // milliseconds
}
10 Configuration Reference
CSS Variables (:root)
| Variable | Default | Purpose |
|---|---|---|
| --green | #00ff41 | Primary accent — text, borders, glows, matrix rain |
| --green-dim | #00aa2a | Secondary accent — inactive items, labels |
| --green-dark | #003310 | Background fill for dark panels and memory bars |
| --cyan | #00fff9 | Agent message bubbles and section headings |
| --red | #ff003c | Recording state, error log entries |
| --bg | #000000 | Page background |
| --panel | #020a02 | Sidebar and header fill |
| --border | #00ff4133 | Semi-transparent green for all panel borders |
| --glow | triple shadow | Full neon glow effect on focus elements |
| --glow-sm | two-layer shadow | Lighter glow for hover and inline accents |
JS Constants
| Constant | Purpose |
|---|---|
| bootMessages[] | Array of { text, cls, delay } objects controlling the boot sequence log. Add, remove, or reorder entries here. |
| ambientLogs[] | Eight-entry array of [message, level] pairs cycled every 4 s. Extend with domain-specific activity. |
| max_tokens | 1000 — passed in every API call. Increase for longer responses at higher cost. |
| r.lang | "en-US" — BCP-47 language tag for voice recognition. Change for other locales (e.g. "el-GR" for Greek). |
11 Security Notes
/v1/messages calls through a backend that injects the key server-side.Recommended production hardening:
| Measure | Details |
|---|---|
| API Proxy | Deploy a lightweight proxy (Node/Express, Deno, Cloudflare Worker) that holds the API key. NEXUS points to the proxy, not directly to Anthropic. |
| Rate Limiting | Enforce per-session or per-user rate limits at the proxy layer to prevent abuse. |
| HTTPS | Required for voice recognition and any production deployment. Serve over TLS. |
| CSP Header | Restrict connect-src to your proxy domain and fonts.googleapis.com only. |
| Key Storage | Never expose raw API keys in version control or client bundles. |
12 Browser Compatibility
13 File Structure
nexus-agent.html is fully self-contained. All CSS and JS are inlined:
↓ Download NEXUS
NEXUS is a single self-contained HTML file. No installer, no package manager, no build step. Download it, drop in your API key, and open it in Chrome.
After downloading
nexus-agent.html in a text editor.callClaude() function and add your API key to the headers (see Section 08).