moltworker
AGENTS.md10k starsChanged 10 months agoApache-2.0View on GitHub
Guidelines for AI agents working on this codebase. This is a Cloudflare Worker that runs OpenClaw (formerly Moltbot/Clawdbot) in a Cloudflare Sandbox container. It provides: - Proxying to the OpenClaw gateway (web UI + WebSocket) - Admin UI at /_admin/ for device management - API endpoints at /api/* for device pairing - Debug endpoints at /debug/* for troubleshooting Note: The CLI tool and npm package are now named openclaw. Config files use .openclaw/openclaw.json. Legacy .clawdbot paths are supported for backward…
- Reads credentials
- Deletes or force-pushes
- Installs packages
Trending
Quiet since September.thin dataabout the whole repository
Who's talking about cloudflare/moltworker
- @sungkim.bsky.social“Run OpenClaw (formerly Moltbot, formerly Clawdbot) on Cloudflare Workers for $5 / month. …”Bluesky · Jan 30, 2026 · 6 likes
- A Hacker News story“OpenClaw on Cloudflare Workers”Hacker News · Feb 2, 2026 · 3 points
- @bmannconsulting.com“https://github.com/cloudflare/moltworker bmann (/bmann) starred cloudflare/moltworker …”Bluesky · Jan 30, 2026 · 3 likes
- A Hacker News story“Run Moltbot (Formely Clawdbot) on Cloudflare Workers”Hacker News · Jan 29, 2026 · 3 points
- @dcuthbert.bsky.social“github.com/cloudflare/m... well played @cloudflare.social well played”Bluesky · Feb 3, 2026 · 2 likes
The biggest 5 of 13 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 13
Talked about on GitHub, Bluesky and Hacker News (13 times).
On GitHub · 7
- Feb 6, 2026Support Workers AI model selection during onboard — openclaw/openclaw1 reaction · 4 comments
- Sep 26, 2026agent-skills.github.cloudflare.moltworker: init at 0-unstable-2026-02-06 — sudosubin/agents.nix0 reactions
- Sep 26, 2026[Candidate] cloudflare/moltworker/skills/cloudflare-browser - cloudflare-browser — ProSkillsMD/proskills0 reactions · 1 comment
- Feb 8, 2026Container deployment fails with "Unauthorized" error despite correct OAuth scopes — cloudflare/workers-sdk0 reactions · 8 comments
- Feb 6, 2026/model command cannot parse model names containing @ character — openclaw/openclaw0 reactions · 8 comments
2 more on GitHub
- Feb 2, 2026(PB) channels.telegram: Unrecognized key: "dm" — CrocSwap/clawdbot-docker0 reactions
- Nov 15, 2025Deploy on Cloudflare button — hybrid-npm/hybrid0 reactions · 1 comment
On Bluesky · 4
- Jan 30, 2026Run OpenClaw (formerly Moltbot, formerly Clawdbot) on Cloudflare Workers for $5 / month. github.com/cloudflare/m... — @sungkim.bsky.social6 likes and reposts · 1 reply
- Jan 30, 2026https://github.com/cloudflare/moltworker bmann (/bmann) starred cloudflare/moltworker (/cloudflare/moltworker) · January 30, 2026 05:07… — @bmannconsulting.com3 likes and reposts
- Feb 3, 2026github.com/cloudflare/m... well played @cloudflare.social well played — @dcuthbert.bsky.social2 likes and reposts
- Feb 14, 2026Cloudflare brings OpenClaw to edge computing - major infrastructure backing for the hottest AI agent platform!… — @u11g.com1 likes and repost
On Hacker News · 2
- Feb 2, 2026OpenClaw on Cloudflare Workers3 points · 1 comment
- Jan 29, 2026Run Moltbot (Formely Clawdbot) on Cloudflare Workers3 points · 1 comment
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- cloudflare-browserSkill
The file
Show its rules and text
We split this AGENTS.md into the rules it gives an agent
15 rules. About 1 is common, 4 are distinctive, and 10 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 52
When calling the OpenClaw CLI from the worker, always include --url ws://localhost:18789:
- Distinctive: line 91
When adding new functionality, add corresponding tests.
- Distinctive: line 95
Use TypeScript strict mode
- Distinctive: line 96
Prefer explicit types over inference for function signatures
- Distinctive: line 97
Keep route handlers thin - extract logic to separate modules
- Very specific: line 98
Use Hono's context methods (c.json(), c.html()) for responses
- Very specific: line 179
If no config exists, openclaw onboard --non-interactive creates one based on env vars
- Very specific: line 225
Add route handler in src/routes/api.ts
- Very specific: line 226
Add types if needed in src/types.ts
- Very specific: line 227
Update client API in src/client/api.ts if frontend needs it
- Very specific: line 232
Add to MoltbotEnv interface in src/types.ts
- Very specific: line 233
If passed to container, add to buildEnvVars() in src/gateway/env.ts
- Common: line 235
Document in README.md secrets table
- Very specific: line 253
rsync compatibility: Use rsync -r --no-times instead of rsync -a.
- Very specific: line 255
Mount checking: Don't rely on sandbox.mountBucket() error messages to detect "already mounted" state.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md 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.
Files
Agent Instructions
Guidelines for AI agents working on this codebase.
Project Overview
This is a Cloudflare Worker that runs OpenClaw (formerly Moltbot/Clawdbot) in a Cloudflare Sandbox container. It provides:
- Proxying to the OpenClaw gateway (web UI + WebSocket)
- Admin UI at
/_admin/for device management - API endpoints at
/api/*for device pairing - Debug endpoints at
/debug/*for troubleshooting
Note: The CLI tool and npm package are now named openclaw. Config files use .openclaw/openclaw.json. Legacy .clawdbot paths are supported for backward compatibility during transition.
Project Structure
src/
├── index.ts # Main Hono app, route mounting
├── types.ts # TypeScript type definitions
├── config.ts # Constants (ports, timeouts, paths)
├── auth/ # Cloudflare Access authentication
│ ├── jwt.ts # JWT verification
│ ├── jwks.ts # JWKS fetching and caching
│ └── middleware.ts # Hono middleware for auth
├── gateway/ # OpenClaw gateway management
│ ├── process.ts # Process lifecycle (find, start)
│ ├── env.ts # Environment variable building
│ ├── r2.ts # R2 bucket mounting
│ ├── sync.ts # R2 backup sync logic
│ └── utils.ts # Shared utilities (waitForProcess)
├── routes/ # API route handlers
│ ├── api.ts # /api/* endpoints (devices, gateway)
│ ├── admin.ts # /_admin/* static file serving
│ └── debug.ts # /debug/* endpoints
└── client/ # React admin UI (Vite)
├── App.tsx
├── api.ts # API client
└── pages/Key Patterns
Environment Variables
DEV_MODE- Skips CF Access auth AND bypasses device pairing (maps toOPENCLAW_DEV_MODEfor container)DEBUG_ROUTES- Enables/debug/*routes (disabled by default)- See
src/types.tsfor fullMoltbotEnvinterface
CLI Commands
When calling the OpenClaw CLI from the worker, always include --url ws://localhost:18789:
sandbox.startProcess('openclaw devices list --json --url ws://localhost:18789')CLI commands take 10-15 seconds due to WebSocket connection overhead. Use waitForProcess() helper in src/routes/api.ts.
Success Detection
The CLI outputs "Approved" (capital A). Use case-insensitive checks:
stdout.toLowerCase().includes('approved')Commands
npm test # Run tests (vitest)
npm run test:watch # Run tests in watch mode
npm run build # Build worker + client
npm run deploy # Build and deploy to Cloudflare
npm run dev # Vite dev server
npm run start # wrangler dev (local worker)
npm run typecheck # TypeScript checkTesting
Tests use Vitest. Test files are colocated with source files (*.test.ts).
Current test coverage:
auth/jwt.test.ts- JWT decoding and validationauth/jwks.test.ts- JWKS fetching and cachingauth/middleware.test.ts- Auth middleware behaviorgateway/env.test.ts- Environment variable buildinggateway/process.test.ts- Process finding logicgateway/r2.test.ts- R2 mounting logicgateway/sync.test.ts- R2 backup sync logic
When adding new functionality, add corresponding tests.
Code Style
- Use TypeScript strict mode
- Prefer explicit types over inference for function signatures
- Keep route handlers thin - extract logic to separate modules
- Use Hono's context methods (
c.json(),c.html()) for responses
Documentation
README.md- User-facing documentation (setup, configuration, usage)AGENTS.md- This file, for AI agents
Development documentation goes in AGENTS.md, not README.md.
Architecture
Browser
│
▼
┌─────────────────────────────────────┐
│ Cloudflare Worker (index.ts) │
│ - Starts OpenClaw in sandbox │
│ - Proxies HTTP/WebSocket requests │
│ - Passes secrets as env vars │
└──────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────┐
│ Cloudflare Sandbox Container │
│ ┌───────────────────────────────┐ │
│ │ OpenClaw Gateway │ │
│ │ - Control UI on port 18789 │ │
│ │ - WebSocket RPC protocol │ │
│ │ - Agent runtime │ │
│ └───────────────────────────────┘ │
└─────────────────────────────────────┘Key Files
| File | Purpose |
src/index.ts | Worker that manages sandbox lifecycle and proxies requests |
Dockerfile | Container image based on cloudflare/sandbox with Node 22 + OpenClaw |
start-openclaw.sh | Startup script: R2 restore → onboard → config patch → launch gateway |
wrangler.jsonc | Cloudflare Worker + Container configuration |
Local Development
npm install
cp .dev.vars.example .dev.vars
# Edit .dev.vars with your ANTHROPIC_API_KEY
npm run startEnvironment Variables
For local development, create .dev.vars:
ANTHROPIC_API_KEY=sk-ant-...
DEV_MODE=true # Skips CF Access auth + device pairing
DEBUG_ROUTES=true # Enables /debug/* routesWebSocket Limitations
Local development with wrangler dev has issues proxying WebSocket connections through the sandbox. HTTP requests work but WebSocket connections may fail. Deploy to Cloudflare for full functionality.
Docker Image Caching
The Dockerfile includes a cache bust comment. When changing start-openclaw.sh, bump the version:
# Build cache bust: 2026-02-06-v28-openclaw-upgradeGateway Configuration
OpenClaw configuration is built at container startup:
- R2 backup is restored if available (with migration from legacy
.clawdbotpaths) - If no config exists,
openclaw onboard --non-interactivecreates one based on env vars start-openclaw.shpatches the config for channels, gateway auth, and trusted proxies- Gateway starts with
openclaw gateway --allow-unconfigured --bind lan
AI Provider Priority
The startup script selects the auth choice based on which env vars are set:
- Cloudflare AI Gateway (native):
CLOUDFLARE_AI_GATEWAY_API_KEY+CF_AI_GATEWAY_ACCOUNT_ID+CF_AI_GATEWAY_GATEWAY_ID - Direct Anthropic:
ANTHROPIC_API_KEY(optionally withANTHROPIC_BASE_URL) - Direct OpenAI:
OPENAI_API_KEY - Legacy AI Gateway:
AI_GATEWAY_API_KEY+AI_GATEWAY_BASE_URL(routes through Anthropic base URL)
Container Environment Variables
These are the env vars passed TO the container (internal names):
| Variable | Config Path | Notes |
ANTHROPIC_API_KEY | (env var) | OpenClaw reads directly from env |
OPENAI_API_KEY | (env var) | OpenClaw reads directly from env |
CLOUDFLARE_AI_GATEWAY_API_KEY | (env var) | Native AI Gateway key |
CF_AI_GATEWAY_ACCOUNT_ID | (env var) | Account ID for AI Gateway |
CF_AI_GATEWAY_GATEWAY_ID | (env var) | Gateway ID for AI Gateway |
OPENCLAW_GATEWAY_TOKEN | --token flag | Mapped from MOLTBOT_GATEWAY_TOKEN |
OPENCLAW_DEV_MODE | controlUi.allowInsecureAuth | Mapped from DEV_MODE |
TELEGRAM_BOT_TOKEN | channels.telegram.botToken | |
DISCORD_BOT_TOKEN | channels.discord.token | |
SLACK_BOT_TOKEN | channels.slack.botToken | |
SLACK_APP_TOKEN | channels.slack.appToken |
OpenClaw Config Schema
OpenClaw has strict config validation. Common gotchas:
agents.defaults.modelmust be{ "primary": "model/name" }not a stringgateway.modemust be"local"for headless operation- No
webchatchannel - the Control UI is served automatically gateway.bindis not a config option - use--bindCLI flag
See OpenClaw docs for full schema.
Common Tasks
Adding a New API Endpoint
- Add route handler in
src/routes/api.ts - Add types if needed in
src/types.ts - Update client API in
src/client/api.tsif frontend needs it - Add tests
Adding a New Environment Variable
- Add to
MoltbotEnvinterface insrc/types.ts - If passed to container, add to
buildEnvVars()insrc/gateway/env.ts - Update
.dev.vars.example - Document in README.md secrets table
Debugging
# View live logs
npx wrangler tail
# Check secrets
npx wrangler secret listEnable debug routes with DEBUG_ROUTES=true and check /debug/processes.
R2 Storage Notes
R2 is mounted via s3fs at /data/moltbot. Important gotchas:
- rsync compatibility: Use
rsync -r --no-timesinstead ofrsync -a. s3fs doesn't support setting timestamps, which causes rsync to fail with "Input/output error". - Mount checking: Don't rely on
sandbox.mountBucket()error messages to detect "already mounted" state. Instead, checkmount | grep s3fsto verify the mount status. - Never delete R2 data: The mount directory
/data/moltbotIS the R2 bucket. Runningrm -rf /data/moltbot/*will DELETE your backup data. Always check mount status before any destructive operations. - Process status: The sandbox API's
proc.statusmay not update immediately after a process completes. Instead of checkingproc.status === 'completed', verify success by checking for expected output (e.g., timestamp file exists after sync). - R2 prefix migration: Backups are now stored under
openclaw/prefix in R2 (wasclawdbot/). The startup script handles restoring from both old and new prefixes with automatic migration.
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
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.

