agentleFS
olaservoolaservo/mcp-agent-skills/skills/claude-agent-ui-ts/SKILL.md

claude-agent-ui-ts

Skill2 starsChanged 10 months agoApache-2.0View on GitHub

Add a React + WebSocket UI on top of Claude Agent SDK agents with tool approval and SQLite persistence

  • Installs packages

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 9 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Add a web UI to your Claude Agent SDK agents.

    line 8
  2. Very specific:

    Add client.tsx to your React app and open in browser

    line 31
  3. Distinctive:

    When agent wants to use a tool, server sends approval request to client

    line 48
  4. Distinctive:

    Chat messages: All user, assistant, and tool_use messages

    line 82
  5. Distinctive:

    When the server restarts, it:

    line 108
  6. Distinctive:

    Add your own CSS

    line 120
  7. Distinctive:

    Use claude-agent-terminal-ts for a styled terminal theme

    line 122
  8. Distinctive:

    Authentication: Add user auth (not included)

    line 128
  9. Distinctive:

    Backup: Add SQLite backup strategy (WAL mode already enabled for durability)

    line 131
  10. Distinctive:

    Error handling: Add retry logic and graceful degradation

    line 132

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Claude Agent UI (TypeScript)

Add a web UI to your Claude Agent SDK agents. Includes real-time WebSocket communication, interactive tool approval, and SQLite persistence for chat history.

Prerequisites

  • Node.js 18+
  • Claude Agent SDK configured (see claude-agent-sdk-ts skill for setup)

Quick Start

  1. Copy the snippets to your project:
    • client.tsx from this skill
    • websocket-server-sqlite.ts and websocket-types.ts from claude-agent-sdk-ts skill
  2. Install dependencies:
    npm install express cors ws @anthropic-ai/claude-agent-sdk better-sqlite3 react react-dom
    npm install -D @types/better-sqlite3 @types/express @types/cors @types/ws
  3. Edit the server CONFIG section (workingDirectory, model, allowedTools, dbPath)
  4. Start server: npx tsx server.ts
  5. Add client.tsx to your React app and open in browser

Architecture

React Client <--WebSocket--> Express Server <--SDK--> Claude Agent
(client.tsx)                 (server.ts)
                                   |
                                   v
                              SQLite DB
                              (chat.db)

Flow:

  1. User types message in React UI
  2. Message sent via WebSocket to server
  3. Server persists message to SQLite and forwards to Claude Agent SDK
  4. When agent wants to use a tool, server sends approval request to client
  5. User approves or rejects in UI
  6. Server continues or blocks tool based on response
  7. Agent responses persisted to SQLite and streamed back to UI

Snippets

SnippetSourceDescription
client.tsxThis skillReact chat UI with WebSocket and tool approval buttons
websocket-server-sqlite.tsclaude-agent-sdk-tsExpress + WebSocket + SQLite server with SDK integration
websocket-types.tsclaude-agent-sdk-tsShared TypeScript types for messages

Configuration

Edit the CONFIG object in the server:

const CONFIG = {
  port: 3001,
  workingDirectory: process.cwd(),  // Scope file operations
  model: "sonnet",                  // opus, sonnet, or haiku
  allowedTools: ["Bash", "Read", "Write", "Edit", "Glob", "Grep"],
  systemPrompt: "You are a helpful AI assistant.",
  dbPath: "./chat.db",              // SQLite database path
};

See claude-agent-sdk-ts skill for detailed configuration options.

Persistence

The server uses SQLite (via better-sqlite3) to persist:

  • Chat messages: All user, assistant, and tool_use messages
  • SDK session ID: Captured from system/init message for session resumption

Database schema:

-- Sessions: stores SDK session ID for multi-turn resumption
CREATE TABLE sessions (
  id TEXT PRIMARY KEY,
  sdk_session_id TEXT,
  created_at TEXT,
  updated_at TEXT
);

-- Messages: stores all chat messages
CREATE TABLE messages (
  id TEXT PRIMARY KEY,
  session_id TEXT,
  role TEXT,        -- 'user' | 'assistant' | 'tool_use'
  content TEXT,
  tool_name TEXT,   -- for tool_use messages
  tool_input TEXT,  -- JSON string for tool_use messages
  timestamp TEXT
);

Session Resumption: When the server restarts, it:

  1. Loads existing messages from SQLite
  2. Retrieves the stored SDK session ID
  3. Passes resume: sdkSessionId to the SDK query options
  4. Claude resumes with full conversation context

This follows the SDK best practice of capturing session_id from the system/init message and using resume for multi-turn conversations.

Styling

The client has no styling (functional HTML only). Options:

  • Add your own CSS
  • Use Tailwind CSS
  • Use claude-agent-terminal-ts for a styled terminal theme

Production Notes

For production deployment, consider:

  • Authentication: Add user auth (not included)
  • Multi-chat: Extend from single session to Map<chatId, Session> for multiple conversations
  • Containerization: Isolate SDK in separate container for security
  • Backup: Add SQLite backup strategy (WAL mode already enabled for durability)
  • Error handling: Add retry logic and graceful degradation

Related Skills

SkillUse When
claude-agent-sdk-tsSDK API details, tools, hooks, configuration, shared server code
claude-agent-terminal-tsTerminal-styled UI with dark theme and keyboard shortcuts

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.