wrangler.jsonc
Thewrangler.jsonc file configures your Cloudflare Worker and its bindings. Here’s a complete example for an agents project:
wrangler.jsonc
Key Fields
compatibility_flags
Thenodejs_compat flag is required for agents:
durable_objects.bindings
Each agent class needs a binding:
When name and class_name differ:
COUNTER_DO) but more descriptive class names (CounterAgent).
migrations
Migrations tell Cloudflare how to set up storage for your Durable Objects:assets
For serving static files (HTML, CSS, JS):ai
For Workers AI integration:Generating Types
Wrangler can generate TypeScript types for your bindings.Automatic Generation
Run the types command:worker-configuration.d.ts with your Env type.
Custom Output Path
Specify a custom path:Without Runtime Types
For cleaner output (recommended for agents):Example Generated Output
env.d.ts
Adding to package.json
Add a script for easy regeneration:package.json
Environment Variables and Secrets
Local Development (.env)
Create a.env file for local secrets (add to .gitignore):
.env
Production Secrets
Usewrangler secret for production:
Non-Secret Variables
For non-sensitive configuration, usevars in wrangler.jsonc:
All values must be strings. Parse numbers/booleans in code:
Environment-Specific Variables
Useenv sections for different environments (e.g. staging, production):
Local Development
Starting the Dev Server
With Vite (recommended for full stack apps):Local State Persistence
Durable Object state is persisted locally in.wrangler/state/:
Clearing Local State
To reset all local Durable Object state:Inspecting Local SQLite
You can inspect agent state directly:Dashboard Setup
Automatic Resources
When you deploy, Cloudflare automatically creates:- Worker - Your deployed code
- Durable Object namespaces - One per agent class
- SQLite storage - Attached to each namespace
Viewing Durable Objects
1
Go to Cloudflare Dashboard
Visit dash.cloudflare.com
2
Select Workers and Pages
Select your account → Workers & Pages
3
Click your Worker
Click your Worker name
4
View Durable Objects
Go to Durable Objects tab
- See all Durable Object namespaces
- View individual object instances
- Inspect storage (keys and values)
- Delete objects
Real-time Logs
View live logs from your agents:- Go to your Worker
- Click Logs tab
- Enable real-time logs
- Status (success, error)
- Search text
- Sampling rate
Analytics
The dashboard shows:- Request count
- Error rate
- CPU time
- Duration percentiles
- Durable Object metrics
Production Deployment
Basic Deploy
- Bundles your code
- Uploads to Cloudflare
- Applies migrations
- Makes it live on
*.workers.dev
Custom Domain
Add a route in wrangler.jsonc:Preview Deployments
Deploy without affecting production:Rollbacks
Roll back to a previous version:Multi-Environment Setup
Environment Configuration
Define environments in wrangler.jsonc:Deploying to Environments
Separate Durable Objects
Each environment gets its own Durable Objects. Staging agents don’t share state with production agents.Migrations
Migrations manage Durable Object storage schema changes.Adding a New Agent
Add tonew_sqlite_classes in a new migration:
Renaming an Agent Class
Userenamed_classes:
Deleting an Agent Class
Usedeleted_classes:
Migration Best Practices
- Never modify existing migrations - Always add new ones
- Use sequential tags - v1, v2, v3 (or use dates: 2025-01-15)
- Test locally first - Migrations run on deploy
- Back up production data - Before renaming or deleting
Troubleshooting
”No such Durable Object class”
The class isn’t in migrations:“Cannot find module” in types
Regenerate types:Secrets not loading locally
Check that.env exists and contains the variable: