dzhng/claude-agent-server is one of the AI-powered repositories TopGit tracks, currently at 590 stars, written primarily in TypeScript. Run Claude Agent (Claude Code) in a sandbox, control it via websocket
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
A WebSocket server that wraps the Claude Agent SDK, allowing real-time bidirectional communication with Claude through WebSockets. Deploy it as an E2B sandbox and connect via the TypeScript client library.
Launch tweet / discussion
Overview
Typical Workflow:
Build Your E2B Image - Deploy the server as an E2B sandbox template using bun run build:e2b
Use the Client Library - Install @dzhng/claude-agent in your project and connect to your E2B sandbox
Modify the Server (Optional) - If you need custom behavior, edit the server code in packages/server/
Test Locally - Use bun run start:server and bun run test:local to test your changes before rebuilding
This creates a sandbox template named claude-agent-server on E2B. The build process:
Creates a sandbox based on Bun 1.3
Installs git and clones this repository
Installs dependencies
Configures the server to start automatically on port 3000
The build may take a few minutes. Once complete, your template is ready to use.
3. Use the Client Library
Install the client library in your project:
npm install @dzhng/claude-agent
# or
bun add @dzhng/claude-agent
Connect to your E2B sandbox:
import { ClaudeAgentClient } from '@dzhng/claude-agent'
const client = new ClaudeAgentClient({
e2bApiKey: process.env.E2B_API_KEY,
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
template: 'claude-agent-server', // Your E2B template name
debug: true,
})
// Start the client (creates E2B sandbox and connects)
await client.start()
// Listen for messages from Claude
client.onMessage(message => {
if (message.type === 'sdk_message') {
console.log('Claude:', message.data)
}
})
// Send a message to Claude
client.send({
type: 'user_message',
data: {
type: 'user',
session_id: 'my-session',
message: {
role: 'user',
content: 'Hello, Claude!',
},
},
})
// Clean up when done
await client.stop()
That's it! The client library handles:
Creating and managing E2B sandboxes
WebSocket connection
Message serialization
Cleanup and resource management
Modifying the Server
If you want to customize the server behavior:
1. Edit Server Code
The server code is in packages/server/:
index.ts - Main server and WebSocket handling
message-handler.ts - Message processing logic
const.ts - Configuration constants
2. Test Locally
Start the server locally:
bun run start:server
In another terminal, run the test client against localhost:
bun run test:local
This runs packages/client/example-client.ts connected to localhost:3000 instead of E2B.
3. Rebuild E2B Image
Once you're satisfied with your changes, rebuild the E2B template:
bun run build:e2b
Your updated server will be deployed to E2B with the same template name.
Available Scripts
bun run build:e2b
Builds and deploys the server as an E2B template. This is the main way to deploy your server to the cloud.
bun run test:client
Runs the example client (packages/client/example-client.ts) connected to an E2B sandbox. Requires both E2B_API_KEY and ANTHROPIC_API_KEY in your .env file.
bun run start:server
Starts the server locally on http://localhost:3000. Use this for local development and testing.
bun run test:local
Runs the example client connected to localhost:3000. Use this to test your local server changes before rebuilding the E2B image.
Client Library API
Installation
npm install @dzhng/claude-agent
# or
bun add @dzhng/claude-agent
Constructor Options
interface ClientOptions {
// Required (unless using environment variables)
anthropicApiKey?: string
// E2B Configuration (optional if using connectionUrl)
e2bApiKey?: string
template?: string // E2B template name, defaults to 'claude-agent-server'
timeoutMs?: number // Sandbox timeout, defaults to 5 minutes
// Connection Configuration
connectionUrl?: string // Use this to connect to local/custom server instead of E2B
// Other Options
debug?: boolean // Enable debug logging
// Query Configuration (passed to server)
agents?: Record<string, AgentDefinition>
allowedTools?: string[]
systemPrompt?:
| string
| { type: 'preset'; preset: 'claude_code'; append?: string }
model?: string
}
Methods
async start() - Initialize the client and connect to the server
send(message: WSInputMessage) - Send a message to the agent
Note: If you're using the @dzhng/claude-agent library, you don't need to interact with these endpoints directly. The client handles configuration and WebSocket connections for you. This section is for advanced users who want to connect to the server directly or build their own client.
The server runs on http://localhost:3000 (or your E2B sandbox URL) with:
Config endpoint: http://localhost:3000/config
WebSocket endpoint: ws://localhost:3000/ws
Configuration API
POST /config
Set the configuration for the Claude Agent SDK query:
curl -X POST http://localhost:3000/config \
-H "Content-Type: application/json" \
-d '{
"systemPrompt": "You are a helpful assistant.",
"allowedTools": ["read_file", "write_file"],
"anthropicApiKey": "sk-ant-...",
"model": "claude-3-5-sonnet-20241022",
"agents": {
"myAgent": {
"name": "My Custom Agent",
"description": "A custom agent"
}
}
}'
Response:
{
"success": true,
"config": {
"systemPrompt": "You are a helpful assistant.",
"allowedTools": ["read_file", "write_file"],
"agents": { ... }
}
}
GET /config
Get the current configuration:
curl http://localhost:3000/config
Response:
{
"config": {
"systemPrompt": "You are a helpful assistant.",
"allowedTools": ["read_file", "write_file"]
}
}
WebSocket API
Connecting
Connect to the WebSocket endpoint:
const ws = new WebSocket('ws://localhost:3000/ws')
Note: The server only accepts one active connection at a time. If another client is already connected, new connection attempts will be rejected with an error message.
Open http://localhost:3000/ in your browser to access the built-in test client. You can:
Send messages to Claude
See real-time responses
View the full JSON structure of SDK messages
Command Line Test Client
Run the example client script:
bun run test:client
This will connect to the server (or E2B sandbox), send a few test messages, and display the responses.
E2B Deployment Details
This section provides additional details about E2B deployment. For the basic setup, see the Quick Start section.
Customizing the Template Name
By default, bun run build:e2b creates a template named claude-agent-server. To use a different name, you can modify packages/e2b-build/build.prod.ts or specify it when using the client:
import { ClaudeAgentClient } from '@dzhng/claude-agent'
const client = new ClaudeAgentClient({
template: 'my-custom-template', // Use your custom template name
e2bApiKey: process.env.E2B_API_KEY,
anthropicApiKey: process.env.ANTHROPIC_API_KEY,
})
await client.start()
How E2B Sandboxes Work
When you use the client library with E2B:
Sandbox Creation: A fresh sandbox is created from your built template (claude-agent-server by default)
Automatic Startup: The server starts automatically in the sandbox on port 3000 (configured via setStartCmd in build.prod.ts)
Secure Endpoints: E2B provides HTTPS and WSS endpoints for your sandbox
Isolation: Each sandbox runs in complete isolation with its own filesystem and resources
Automatic Cleanup: Sandboxes are terminated when the client disconnects
To test with E2B, simply run:
bun run test:client
This runs packages/client/example-client.ts which creates an E2B sandbox, connects to it, runs test commands, and cleans up.
E2B Template Configuration
The template is defined in packages/e2b-build/build.prod.ts:
const template = Template()
.fromBunImage('1.3') // Use Bun 1.3 base image
.runCmd('sudo apt install -y git') // Install git
.gitClone('https://github.com/...', ...) // Clone repository
.setWorkdir('/home/user/app') // Set working directory
.runCmd('bun install') // Install dependencies
.setStartCmd('bun packages/server/index.ts', waitForPort(3000)) // Start server
You can customize this template to:
Install additional system packages
Pre-configure environment variables
Change resource limits (CPU, memory)
Modify the startup command
E2B vs Local Development
Local Development (localhost):
Faster iteration
Direct access to local filesystem
No sandbox overhead
Good for development and testing
E2B Deployment:
Isolated execution environment
Secure cloud sandboxes
Scalable infrastructure
Production-ready
No local setup required
Configuration
The server uses port 3000 by default. You can modify this in packages/server/index.ts:
const server = Bun.serve<SessionData>({
port: 3000, // Change this
// ...
})
Environment Variables
Environment variables are loaded from the root .env file. See Quick Start for setup instructions.
API Key Priority:
If you set anthropicApiKey via the Configuration API (/config endpoint), it will override the ANTHROPIC_API_KEY environment variable.
When using the client library, you can pass anthropicApiKey in the constructor options.
How does dzhng/claude-agent-server compare to other AI Tools projects?
dzhng/claude-agent-server is tracked by TopGit in the AI Tools category, with 590 GitHub stars and written in TypeScript. Browse the AI Tools topic page on TopGit to compare it against similar projects by stars and activity.
How many stars does dzhng/claude-agent-server have?
dzhng/claude-agent-server has 590 GitHub stars — refresh the page for the live number, or check github.com/dzhng/claude-agent-server. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is dzhng/claude-agent-server open source?
TopGit's metadata for dzhng/claude-agent-server does not record a license. Most public repositories on GitHub ARE open source, but the exact terms vary — verify by opening the LICENSE file directly.
What else is in the AI Tools space?
dzhng/claude-agent-server is tracked by TopGit under the AI Tools category, alongside 6 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What is dzhng/claude-agent-server?
dzhng/claude-agent-server (dzhng/claude-agent-server) is a TypeScript project on GitHub. From the project's own README: Run Claude Agent (Claude Code) in a sandbox, control it via websocket
Where can I see dzhng/claude-agent-server in action?
The project maintains a homepage at https://x.com/dzhng/status/1991154972558581889?s=20. The README tab on this page also usually contains screenshots and a quickstart.
Where do I read more about dzhng/claude-agent-server?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/dzhng/claude-agent-server is the definitive source.
Read full README in the tab above.
Is claude-agent-server worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of claude-agent-server.