Codehooks Backend Skill
Give your OpenClaw agent a serverless backend for REST APIs, webhooks, data storage, scheduled jobs, queue workers, and autonomous workflows.
Your agent can deploy code
With this skill, your agent can write JavaScript/TypeScript code and deploy it to a live serverless backend in 5 seconds. No human intervention required — the agent iterates autonomously.
Codehooks has a free tier to get started, and paid plans have no extra charges for traffic or API calls — let your agent deploy without worrying about usage costs.
⚠️ Warning: This gives your agent the ability to deploy and run code on a live server. Review your agent's actions, set appropriate permissions, and monitor usage. You are responsible for any code your agent deploys.
What this skill enables
- - REST APIs with automatic OpenAPI/Swagger documentation
- Instant CRUD APIs using
crudlify() with schema validation - Webhook endpoints that external services can call (Stripe, GitHub, Shopify, etc.)
- Persistent storage beyond local memory (NoSQL + key-value)
- Background jobs and scheduled tasks that run 24/7
- Queue workers for async processing
- Autonomous workflows with retries, branching, and state management
Setup
Human does once:
CODEBLOCK0
Give the admin token to your agent.
Agent uses:
CODEBLOCK1
The agent can now deploy code, query data, and manage the backend.
Essential: Load the development context
Before building anything, run:
CODEBLOCK2
This outputs the complete Codehooks development prompt — routing, database, queues, jobs, workflows, and the full codehooks-js API. Copy it into your context to build any backend feature correctly.
macOS shortcut:
CODEBLOCK3
Understand existing projects
Before modifying an existing project, get the full picture:
CODEBLOCK4
INLINECODE1 is the most powerful diagnostic command — it returns structured JSON covering database collections with document counts, deployment history, queue and worker status, and recent error logs. Always run it when joining an existing project or debugging issues.
INLINECODE2 complements doctor by showing the structural overview: what collections exist, their schemas, registered queues, and deployed files.
Commands your agent can use
All commands accept --admintoken $CODEHOOKS_ADMIN_TOKEN for non-interactive use. Full CLI reference: https://codehooks.io/docs/cli
| Command | What it does |
|---|
| INLINECODE4 | Get the full development context |
| INLINECODE5 |
Diagnose project state — collections, stats, deploys, error logs |
|
coho describe | Describe app structure — collections, schemas, queues, files |
|
coho deploy | Deploy code (5 seconds to live) |
|
coho info --examples | Get endpoint URLs with cURL examples |
|
coho log -f | Stream logs in real-time |
|
coho query -c <collection> -q 'field=value' | Query the database |
|
coho queue-status | Check queue status |
|
coho workflow-status | Check workflow status |
|
coho import -c <collection> --file data.json | Import data |
|
coho export -c <collection> | Export data |
Code examples
Instant CRUD API with validation
CODEBLOCK5
Webhook that stores incoming data
CODEBLOCK6
Scheduled job (runs daily at 9am)
CODEBLOCK7
Queue worker for async processing
CODEBLOCK8
Autonomous workflow (multi-step with retries)
CODEBLOCK9
Important patterns
- -
getMany() returns a stream — use .toArray() when you need to manipulate data (sort, filter, map) - Webhook signatures: Use
req.rawBody for signature verification, not INLINECODE18 - No filesystem access:
fs, path, os are not available — this is a serverless environment - Secrets: Use
process.env.VARIABLE_NAME for API keys and secrets - Static files:
app.static({ route: '/app', directory: '/public' }) serves static sites from deployed source - File storage:
app.storage({ route: '/docs', directory: '/uploads' }) serves uploaded files
Development workflow: Let your agent build new endpoints
- 1. Agent runs
coho prompt and loads the development context - For existing projects, agent runs
coho doctor and coho describe to understand what's deployed - Agent writes code using codehooks-js patterns
- Agent runs
coho deploy (5 seconds to live) - Agent verifies with
coho log -f or tests endpoints with INLINECODE30 - Agent iterates — the fast deploy loop enables rapid development
When to use this skill
- - You need a reliable webhook URL for Stripe, GitHub, Shopify, etc.
- You want persistent storage outside your local machine
- You need scheduled jobs that run even when your device is off
- You want to offload sensitive API integrations to a sandboxed environment
- You need queues for async processing
- You want autonomous multi-step workflows that run independently with retries
Resources
- - Documentation: https://codehooks.io/docs
- CLI reference: https://codehooks.io/docs/cli
- AI prompt: Run
coho prompt or visit https://codehooks.io/llms.txt - Templates: https://github.com/RestDB/codehooks-io-templates
- MCP Server: https://github.com/RestDB/codehooks-mcp-server
Codehooks 后端技能
为您的 OpenClaw 智能体提供无服务器后端,支持 REST API、Webhook、数据存储、定时任务、队列工作器和自主工作流。
您的智能体可以部署代码
借助此技能,您的智能体可以编写 JavaScript/TypeScript 代码,并在 5 秒内将其部署到实时无服务器后端。无需人工干预——智能体可自主迭代。
Codehooks 提供免费套餐供您入门,付费计划不会对流量或 API 调用额外收费——让您的智能体无需担心使用成本即可部署。
⚠️ 警告: 这使您的智能体能够在实时服务器上部署和运行代码。请审查智能体的操作,设置适当的权限,并监控使用情况。您对智能体部署的任何代码负责。
此技能支持的功能
- - REST API,附带自动生成的 OpenAPI/Swagger 文档
- 即时 CRUD API,使用 crudlify() 并支持模式验证
- Webhook 端点,可供外部服务调用(Stripe、GitHub、Shopify 等)
- 持久化存储,超越本地内存(NoSQL + 键值存储)
- 后台任务和定时任务,全天候运行
- 队列工作器,用于异步处理
- 自主工作流,支持重试、分支和状态管理
设置
人类一次性操作:
bash
npm install -g codehooks
coho login
coho create openclaw-backend
coho add-admintoken
将管理员令牌提供给您的智能体。
智能体使用:
bash
export CODEHOOKSADMINTOKEN=your-token-here
coho deploy --admintoken $CODEHOOKSADMINTOKEN
智能体现在可以部署代码、查询数据和管理后端。
必要:加载开发上下文
在构建任何内容之前,请运行:
bash
coho prompt
这将输出完整的 Codehooks 开发提示——路由、数据库、队列、任务、工作流以及完整的 codehooks-js API。将其复制到您的上下文中,以正确构建任何后端功能。
macOS 快捷方式:
bash
coho prompt | pbcopy
了解现有项目
在修改现有项目之前,请获取完整信息:
bash
返回包含集合、统计信息、最近部署和错误日志的 JSON
coho doctor
描述应用结构——集合、模式、队列、文件
coho describe
coho doctor 是最强大的诊断命令——它返回结构化的 JSON,涵盖数据库集合(含文档计数)、部署历史、队列和工作器状态以及最近的错误日志。在加入现有项目或调试问题时,始终运行此命令。
coho describe 通过显示结构概览来补充 doctor:存在哪些集合、它们的模式、已注册的队列以及已部署的文件。
您的智能体可以使用的命令
所有命令都接受 --admintoken $CODEHOOKSADMINTOKEN 以进行非交互式使用。完整 CLI 参考:https://codehooks.io/docs/cli
| 命令 | 功能 |
|---|
| coho prompt | 获取完整的开发上下文 |
| coho doctor |
诊断项目状态——集合、统计信息、部署、错误日志 |
| coho describe | 描述应用结构——集合、模式、队列、文件 |
| coho deploy | 部署代码(5 秒上线) |
| coho info --examples | 获取端点 URL 及 cURL 示例 |
| coho log -f | 实时流式传输日志 |
| coho query -c
-q field=value | 查询数据库 |
| coho queue-status | 检查队列状态 |
| coho workflow-status | 检查工作流状态 |
| coho import -c --file data.json | 导入数据 |
| coho export -c | 导出数据 |
代码示例
带验证的即时 CRUD API
javascript
import { app } from codehooks-js;
import * as Yup from yup;
const productSchema = Yup.object({
name: Yup.string().required(),
price: Yup.number().positive().required(),
category: Yup.string().required()
});
// 自动创建 GET、POST、PUT、DELETE 端点
// OpenAPI 文档可在 /.well-known/openapi 获取
app.crudlify({ product: productSchema });
export default app.init();
存储传入数据的 Webhook
javascript
import { app, Datastore } from codehooks-js;
// 允许 webhook 端点无需 JWT 认证
app.auth(/webhook, (req, res, next) => {
next();
});
app.post(/webhook, async (req, res) => {
const conn = await Datastore.open();
await conn.insertOne(events, {
...req.body,
receivedAt: new Date().toISOString()
});
res.json({ ok: true });
});
export default app.init();
定时任务(每天上午 9 点运行)
javascript
import { app, Datastore } from codehooks-js;
app.job(0 9 *, async (_, { jobId }) => {
console.log(Running job: ${jobId});
const conn = await Datastore.open();
const events = await conn.getMany(events, {}).toArray();
console.log(Daily summary:, events.length, events);
});
export default app.init();
用于异步处理的队列工作器
javascript
import { app, Datastore } from codehooks-js;
app.worker(processTask, async (req, res) => {
const { task } = req.body.payload;
const conn = await Datastore.open();
await conn.updateOne(tasks, { _id: task.id }, { $set: { status: completed } });
res.end();
});
export default app.init();
自主工作流(多步骤带重试)
javascript
import { app } from codehooks-js;
const workflow = app.createWorkflow(myTask, Process tasks autonomously, {
begin: async function (state, goto) {
console.log(Starting task:, state.taskId);
goto(process, state);
},
process: async function (state, goto) {
// 在此处执行工作——工作流处理重试和状态
state = { ...state, result: processed };
goto(complete, state);
},
complete: function (state, goto) {
console.log(Done:, state.result);
goto(null, state); // 结束工作流
}
});
// 智能体通过 API 启动工作流
app.post(/start, async (req, res) => {
const result = await workflow.start(req.body);
res.json(result);
});
export default app.init();
重要模式
- - getMany() 返回流——当您需要操作数据(排序、过滤、映射)时,使用 .toArray()
- Webhook 签名: 使用 req.rawBody 进行签名验证,而不是 req.body
- 无文件系统访问: fs、path、os 不可用——这是一个无服务器环境
- 密钥: 使用 process.env.VARIABLE_NAME 存储 API 密钥和机密
- 静态文件: app.static({ route: /app, directory: /public }) 从已部署的源代码提供静态站点
- 文件存储: app.storage({ route: /docs, directory: /uploads }) 提供上传的文件
开发工作流:让您的智能体构建新端点
- 1. 智能体运行 coho prompt 并加载开发上下文
- 对于现有项目,智能体运行 coho doctor 和 coho describe 以了解已部署的内容
- 智能体使用 codehooks-js 模式编写代码
- 智能体运行 coho deploy(5 秒上线)
- 智能体使用 coho log -f 验证或使用 coho info --examples 测试端点
- 智能体迭代——快速部署循环支持快速开发
何时使用此技能
- - 您需要为 Stripe、GitHub、Shopify 等提供可靠的 webhook URL
- 您希望在本地机器之外拥有持久化存储
- 您需要即使在设备关闭时也能运行的定时任务
- 您希望将敏感的 API 集成卸载到沙盒环境中
- 您需要用于异步处理的队列
- 您希望拥有独立运行并支持重试的自主多步骤工作流
资源
- - 文档: https://codehooks.io/docs
- CLI 参考: https://codehooks.io/docs/cli
- AI 提示: 运行 coho prompt 或访问 https://code