Build with a Coding Agent
Give a coding agent the runtime adapter library, these pages, and a brief that keeps it inside the managed Worker contract.
A coding agent, such as Claude Code, can write, package, and deploy a managed Worker. Give it the adapter library and documentation for your exact version so it can check the available methods and types.
Prepare the Project
- Copy the adapter library into the project, or for TypeScript save
src/worker-types.ts. See Get the Runtime Adapters. - Give the agent links to, or copies of, these pages:
- Build Your First Managed Worker
- Templates and Options
- Platform Capabilities
- Call Platform Services, if the Worker calls other platform APIs
- Raw Platform Calls
- Coordinate Worker Deployments and Service Releases, when deploying to another tenant or changing shared components
Brief the Agent
Adapt this brief. Replace the values in angle brackets:
Build a managed Contextual Worker in <language> that <what it should do>.
Trigger: <event | http | cron>, using the managed-<event|http|scheduled>-worker
template, version <0.10.0>. Target tenant <tenant-id> with CLI configuration
<config-id> and Worker ID <worker-id>.
For promotion, target tenant <target-tenant-id> with CLI configuration
<target-config-id>.
Use only the runtime adapter API in <path to the copied library, or for
TypeScript src/worker-types.ts and the Platform Capabilities page> and the
operations listed on the Raw Platform Calls page. Do not invent methods. Use
the typed methods and helpers. Use the raw platform call (platform.call in
TypeScript, platform_call in Rust and Python, PlatformCall in Go) only for an
operation the typed API does not cover, and explain why.
Rules:
- Workers deploy independently of Services; deployment through a Service release
is not supported. List the process that manages each prerequisite, required
Service releases, and existing target-tenant components. Plan prerequisite
changes before Worker deployment. Reference resources owned by another process;
do not maintain competing definitions of them. Confirm the destination tenant
separately from any selected development or production configuration values.
Do not add the Worker record or its platform-created Agent (same ID as the
Worker) to a Service. Follow the Coordinate Worker Deployments and Service
Releases guide for target-tenant configuration, verification, cutover, and
recovery.
- Platform credentials never appear in the app. Third-party APIs go through a
declared connection alias bound with CONNECTION_BINDINGS. Other platform APIs
go through services.request, only to services listed in the Worker's
PLATFORM_SERVICES option; list the services you need. Prefer a typed method
when one exists.
- Secrets are Worker environment variables set in the admin console, never in the
image, CONFIG, source, shell arguments, or chat.
- Writes to existing records use the hash of the version that was read.
Handle a null patch result as a conflict.
- Event handlers can run more than once for the same event. Make side
effects safe to repeat, using the event's id as an idempotency key. Catch
failures that retrying cannot fix, log them, and return successfully, so a
bad event does not restart the Worker repeatedly.
- Return or raise PlatformError failures, or errors caused by them. Check
effectMayHaveOccurred before retrying a write. Only the TypeScript adapter
checks CONFIG against configSchema; in other languages, check the values
you read.
- Await every log call and capability call. Stop starting work once the
invocation is cancelled.
- Build for linux/amd64 and package with the adapter image's package command,
using the same adapter version as the copied library.
- Use the template version released with that adapter version. When you
upgrade the adapter, pass --managed <template>:<version> in the same
ctxl workers update as --build. A --build update alone keeps the old template.
Deliver: worker.json, the source, the build and package commands, config.json,
the ctxl workers create command, and a release checklist with required Service
releases, target-tenant IDs, Connection bindings, and any Service installation
or update steps. Deploy only after I approve the complete plan, including any
Service changes. Then verify the Worker URL or a test event, and report the
Worker version, image reference, and the log entries you read.
Check the Agent's Work
Before you deploy, check that:
- Every adapter method the code calls exists in the copied library at that version or, for TypeScript, on the Platform Capabilities page.
worker.jsonnames each handler and the triggers it accepts. ItsworkerIdandversionmatch the code. ItsconfigSchemaaccepts yourconfig.json.- The code has no URLs or tokens for platform services, and no hard-coded tenant or record IDs that belong in
CONFIG. - Each
connectionsalias is bound inCONNECTION_BINDINGS. - Each service the code passes to
services.requestis listed inPLATFORM_SERVICES, and no other. - An event handler that writes data is safe to run twice.
- The
packagecommand runs without errors, and theFROMversion matches the copied library. - The template version is the one released with that adapter version. See Release Versions.
After you deploy, read the platform-routed logs with ctxl logs <worker-id>, and the logger entries and console lines in the host's container output with ctxl workers logs <worker-id> -c host. The app container's output has only what your code prints itself. Then test the behavior yourself. A Running deployment does not prove that the handler works.