Duyetbot Agent
Guides

Claude Code Agent

Deploy long-running agent server with Claude Code/Agent SDK. Docker deployment, WebSocket streaming, extended sessions.

Claude Code Agent

Back to: Cloudflare Deploy

Deploy a long-running agent server for tasks that exceed Cloudflare Workers' 30-second timeout.

Overview

The Claude Code Agent (Tier 2) is designed for:

  • Long-running sessions - No 30s timeout limit
  • WebSocket streaming - Real-time response streaming
  • Code execution - Filesystem access, shell tools
  • Extended context - Multi-turn complex conversations

When to Use

Use CaseAgent TypeWhy
Quick Q&A, greetingsCloudflare AgentFast, serverless
Webhook handlersCloudflare AgentFire-and-forget pattern
Complex researchClaude Code AgentNeeds extended time
Code generation + testingClaude Code AgentFilesystem access
Multi-step workflowsClaude Code AgentSession persistence

Comparison

AspectCloudflare AgentClaude Code Agent
RuntimeCloudflare Workers + DODocker container
Timeout30 secondsUnlimited
StateDurable ObjectsIn-memory/filesystem
LatencyUltra-low (edge)Higher (single region)
ScalingAutomatic, globalManual, container-based
ToolsMCP servers onlyShell, filesystem, git

Prerequisites

  1. Docker installed
  2. Server with persistent storage (or Fly.io, Railway, etc.)

Environment Variables

# LLM Provider
ANTHROPIC_API_KEY=xxx
ANTHROPIC_BASE_URL=https://api.anthropic.com
 
# Server
PORT=3003
NODE_ENV=production
 
# Optional: Connect to Memory MCP
MCP_SERVER_URL=https://memory.duyetbot.workers.dev
MCP_AUTH_TOKEN=xxx

Deploy with Docker

cd apps/agent-server
 
# Build
docker build -t duyetbot-server .
 
# Run
docker run -d \
  -e ANTHROPIC_API_KEY=xxx \
  -p 3003:3003 \
  duyetbot-server

Docker Compose

version: '3.8'
 
services:
  agent-server:
    build:
      context: .
      dockerfile: apps/agent-server/Dockerfile
    ports:
      - "3003:3003"
    environment:
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - MCP_SERVER_URL=${MCP_SERVER_URL}
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3003/health"]
      interval: 30s
      timeout: 10s
      retries: 3

Health Check

curl http://localhost:3003/health

Architecture

┌─────────────────────────────────────────────────────────┐
│                    Tier 1 (Edge)                        │
│  Cloudflare Workers + Durable Objects                   │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐     │
│  │ Telegram    │  │ GitHub      │  │ Router      │     │
│  │ Webhook     │  │ Webhook     │  │ Agent       │     │
│  └──────┬──────┘  └──────┬──────┘  └──────┬──────┘     │
│         │                │                │             │
│         └────────────────┴────────────────┘             │
│                          │                              │
│         Simple queries handled here                     │
└──────────────────────────┼──────────────────────────────┘

              Complex/long-running tasks


┌─────────────────────────────────────────────────────────┐
│                    Tier 2 (Container)                   │
│  ┌─────────────────────────────────────────────────┐   │
│  │              Claude Code Agent                   │   │
│  │  • Claude Agent SDK                             │   │
│  │  • Filesystem access                            │   │
│  │  • Shell tools (git, bash)                      │   │
│  │  • WebSocket streaming                          │   │
│  └─────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────┘

Future: Integration with Cloudflare Agent

Note: This is a planned feature for future implementation (Tier 2 integration).

The CloudflareChatAgent could escalate to Tier 2 (Claude Code Agent) when:

  • Task requires filesystem access
  • Task needs extended execution time
  • Complex code operations are needed
  • User explicitly requests long-running mode

Next Steps

On this page