How w17ant/claude-office works
1. What this repo is
Claude Office is a local, single-user “digital office” app: a React scene renderer plus a local event/chat backend that visualizes Claude Code agents as pixel-art coworkers in real time.
2. Top-level runtime split
There are three main runtime pieces:
- Frontend: Vite + React + TypeScript in src/
- Local server: Express + WebSocket in server/
- Automation layer: shell/Python scripts and Claude Code hooks in hooks/ and scripts/
Electron exists as an optional wrapper, not the primary runtime.
3. Frontend responsibilities
src/App.tsx orchestrates the office scene: agent lifecycle, room state, chat panel, effects, and mode selection. Supporting modules break the scene into boundaries like agent state (agentManager.ts), events, interactions, rooms, daylight, sounds, theme, and shared types. UI rendering is composed from specialized components such as Character, FurnitureRenderer, SpeechBubble, EffectBubble, and SlackChat.
4. Real-time agent event pipeline
Claude Code hooks are the source of truth for agent activity. hooks/agent-tracker.sh captures hook events like spawn/tool use/completion and forwards them to the local server. The server broadcasts those events over WebSocket, and the React app consumes them through useAgentSocket.ts to animate agents entering, moving, typing, taking breaks, and leaving.
5. Server boundary and security
server/index.js is the local control plane: it exposes HTTP endpoints plus a WS channel, and it binds to 127.0.0.1 only. The event ingestion path requires a bearer token generated at startup, which keeps external processes from injecting office events. This is a localhost-only architecture designed for one operator’s machine.
6. Chat subsystem
The office chat is separate from the visual event stream. server/chat-db.js provides SQLite-backed persistence for chat history, which survives restarts. The UI’s Slack-like panel (SlackChat.tsx) displays the conversation, slash commands, typing/read-state UI, and role-based replies.
7. AI reply generation
scripts/chat-ai-watcher.sh and related helper scripts form the asynchronous reply loop. They watch for new chat activity, gather context (branch, recent messages, active agents), call the Claude CLI (claude -p), and write replies back through the local chat path. This keeps token usage and message generation outside the browser app.
8. Simulation, video, and helper modes
The main app supports multiple operational modes via query params: live office, scripted simulation, recording/video mode, and a placement-helper mode for furniture positioning. That means the frontend can run against real hook events or against fabricated scripted data, which is important when drawing the architecture as a set of interchangeable event sources.
9. Asset and rendering pipeline
Static art lives under public/sprites/ and public/rooms/, while generated assets are produced by scripts like generate-sprites.mjs, generate-office-bg.mjs, generate-walks.mjs, and extract-boss-sprite.py. The frontend is therefore mostly a renderer over prebuilt sprite sheets and room layouts rather than a canvas game engine.
10. Office customization and state
office.config.example.json defines configurable identity data such as the boss character name, sprite, color, and emoji. The README also describes persistent UI toggles like the Dunder Mifflin mode, which is stored client-side in localStorage. So some state is durable in SQLite, some is durable in browser storage, and some is ephemeral in the live event stream.
11. Desktop packaging
electron/main.cjs is a thin optional desktop shell around the same web app. It does not appear to introduce a separate backend; instead it packages the local office experience into a desktop application when needed.
12. Operational scripts and lifecycle
scripts/start-office.sh and scripts/stop-office.sh are the main lifecycle controls, likely starting the server, frontend, and chat watcher together. The repo is therefore organized around a local orchestration model: hooks inject events, the server brokers state, the watcher generates chat, and the browser/Electron client renders the office.
Main entry points: App.tsx Office App · index.js Local Server · Character.tsx Scene UI · start-office.sh Lifecycle
Components 20
Frontend
React/Vite office renderer and UI state
- Office App · Main scene coordinator for office modes, agent lifecycle, room state, effects, and chat.
src/App.tsx - Agent State · Tracks agents, lifecycle, positions, and office-facing state transitions.
src/agentManager.ts - Event Model · Shared event definitions for the office and agent activity pipeline.
src/events.ts - Interactions · Rules for agent movement, room interactions, and office behaviors.
src/interactions.ts - Rooms · Room definitions and spatial boundaries used by the renderer.
src/rooms.ts - Theme · Shared theming and presentation settings for the office scene.
src/theme.ts - Daylight · Light and time-of-day treatment for the rendered office.
src/daylight.ts - Scene UI · Character, furniture, speech, and effect components that render the office.
src/components/Character.tsx - Chat Panel · Slack-like office chat view with commands, presence, and replies.
src/components/SlackChat.tsx - Agent Socket · Consumes live agent updates from the local server and drives animation state.
src/hooks/useAgentSocket.ts
Local server
Local HTTP, WebSocket, and chat persistence
- Local Server · Local HTTP and WebSocket server bound to localhost for office events and chat.
server/index.js - Chat DB · SQLite-backed storage for chat history across restarts.
server/chat-db.js
Automation
Hooks and scripts that feed the office
- Agent Tracker · Captures Claude Code hook events and forwards agent lifecycle updates.
hooks/agent-tracker.sh - Chat Watcher · Monitors chat activity and triggers asynchronous AI reply generation.
scripts/chat-ai-watcher.sh - Chat Tools · Helpers that gather context, poll, post, and reply through the local chat path.
scripts/chat-bridge.sh - Lifecycle · Starts and stops the office stack as a local single-user experience.
scripts/start-office.sh
Assets
Static and generated art for the scene
Desktop shell
Optional Electron wrapper
- Electron Shell · Thin desktop packaging layer around the same local web app.
electron/main.cjs
Connections 22
- Office App → Agent State: owns state · The app coordinates agent lifecycle and room state through the manager.
- Office App → Event Model: uses schema · Scene logic consumes shared event definitions.
- Office App → Interactions: drives rules · Interaction rules shape movement and office behavior.
- Office App → Rooms: loads layouts · The app renders room structure from shared layout data.
- Office App → Theme: applies theme · Presentation settings feed the scene renderer.
- Office App → Daylight: renders lighting · Time-of-day effects are layered into the office scene.
- Office App → Scene UI: composes UI · The main scene is assembled from specialized render components.
- Office App → Chat Panel: shows chat · The office app embeds the Slack-like chat panel.
- Agent Socket → Local Server: ws updates · The client listens to live agent broadcasts from the local server.
- Agent Tracker → Local Server: ingests events · Claude hook output is forwarded into the server event pipeline.
- Local Server → Agent Socket: broadcasts · Live office events are pushed to connected browser clients.
- Local Server → Chat DB: persists chat · Chat history is stored in SQLite for recovery after restarts.
- Chat Panel → Chat DB: reads history · The chat panel reflects persisted conversation state.
- Chat Watcher → Chat Tools: orchestrates · The watcher uses helper scripts to collect context and post replies.
- Chat Tools → Local Server: writes replies · Reply scripts send messages through the local chat path.
- Lifecycle → Local Server: starts server · Startup scripts bring up the local control plane.
- Lifecycle → Chat Watcher: starts watcher · The office lifecycle includes the asynchronous reply loop.
- Asset Gen → Sprites: builds art · Generated sprite sheets populate the renderer asset set.
- Asset Gen → Room Art: builds rooms · Background and room art are generated by helper scripts.
- Scene UI → Sprites: renders sprites · Scene components draw characters, furniture, and effects from sprite assets.
- Scene UI → Room Art: uses backdrops · Furniture and scene rendering rely on room art.
- Electron Shell → Office App: wraps UI · Electron packages the same front-end application as a desktop shell.