Autonomous setup assistant for Cloudflare Workflows. Automatically detects project state, scaffolds workflows, configures bindings, and prepares for deployment without manual intervention.
Scaffolds Cloudflare Workflows by detecting project state and configuring infrastructure automatically.
/plugin marketplace add secondsky/claude-skills/plugin install cloudflare-workflows@claude-skillsAutonomous agent that guides workflow setup by detecting project state, creating appropriate scaffolding, and configuring all necessary components automatically.
This agent should be used when:
Keywords: setup, create, new workflow, add workflow, first workflow, configure, initialize, scaffold, getting started
# Check for existing project files
ls -la 2>/dev/null | grep -E "wrangler|package|tsconfig"
Detect:
wrangler.jsonc or wrangler.toml → Existing Worker projectpackage.json → Node/Bun projecttsconfig.json → TypeScript projectIf wrangler config exists:
# Check for existing workflows
grep -v '^\s*//' wrangler.jsonc | jq '.workflows // []'
# Check main entry point
grep -v '^\s*//' wrangler.jsonc | jq '.main'
# Check existing bindings
grep -v '^\s*//' wrangler.jsonc | jq 'keys'
Determine:
Path A: New Project
Path B: Add Workflows to Existing Project
Path C: Add Another Workflow
If new project needed:
mkdir -p src/workflows
mkdir -p test
{
"name": "my-worker",
"main": "src/index.ts",
"compatibility_date": "2025-01-01",
"workflows": [
{
"binding": "MY_WORKFLOW",
"name": "my-workflow",
"class_name": "MyWorkflow"
}
]
}
{
"name": "my-worker",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "wrangler dev",
"deploy": "wrangler deploy",
"test": "vitest"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20251126.0",
"typescript": "^5.9.0",
"wrangler": "^4.50.0",
"vitest": "^2.0.0"
}
}
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"lib": ["ES2022"],
"types": ["@cloudflare/workers-types"],
"strict": true,
"skipLibCheck": true,
"noEmit": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
Based on use case (inferred or from project context):
File: src/workflows/my-workflow.ts
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent } from 'cloudflare:workers';
import { NonRetryableError } from 'cloudflare:workflows';
type Env = {
MY_WORKFLOW: Workflow;
};
type Params = {
id: string;
};
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
const { id } = event.payload;
console.log('Workflow started:', {
instanceId: event.instanceId,
params: event.payload
});
// Step 1: Validate input
await step.do('validate input', async () => {
if (!id) {
throw new NonRetryableError('Missing required parameter: id');
}
return { valid: true };
});
// Step 2: Process data
const result = await step.do('process data', async () => {
// Your processing logic here
return { processed: true, id };
});
// Step 3: Complete workflow
await step.do('finalize', async () => {
console.log('Workflow completing:', result);
return { finalized: true };
});
return {
status: 'complete',
id,
completedAt: new Date().toISOString()
};
}
}
File: src/index.ts
import { MyWorkflow } from './workflows/my-workflow';
// Re-export workflow class (required for Cloudflare)
export { MyWorkflow };
// Environment bindings
interface Env {
MY_WORKFLOW: Workflow;
}
// Worker to trigger and manage workflows
export default {
async fetch(req: Request, env: Env): Promise<Response> {
const url = new URL(req.url);
// Favicon handler
if (url.pathname.startsWith('/favicon')) {
return new Response(null, { status: 404 });
}
// Check instance status
const instanceId = url.searchParams.get('instanceId');
if (instanceId) {
try {
const instance = await env.MY_WORKFLOW.get(instanceId);
const status = await instance.status();
return Response.json({ id: instanceId, status });
} catch {
return Response.json({ error: 'Instance not found' }, { status: 404 });
}
}
// Create new workflow instance
try {
const instance = await env.MY_WORKFLOW.create({
params: { id: crypto.randomUUID() }
});
return Response.json({
id: instance.id,
status: await instance.status(),
statusUrl: `${url.origin}?instanceId=${instance.id}`
});
} catch (error) {
return Response.json({
error: 'Failed to create workflow',
message: error instanceof Error ? error.message : 'Unknown'
}, { status: 500 });
}
}
};
If adding to existing project:
Add workflows array or append new workflow:
"workflows": [
// ... existing workflows
{
"binding": "NEW_WORKFLOW",
"name": "new-workflow",
"class_name": "NewWorkflow"
}
]
Add workflow binding to existing Env type:
interface Env {
// ... existing bindings
NEW_WORKFLOW: Workflow;
}
Add to main entry file:
export { NewWorkflow } from './workflows/new-workflow';
# Install dependencies
npm install
# Or with Bun
bun install
# Run validation script
./scripts/validate-workflow-config.sh wrangler.jsonc
npx tsc --noEmit
# Start dev server
wrangler dev
✅ Workflow Setup Complete!
============================
Project Type: ${projectType}
Setup Path: ${setupPath}
Files Created/Modified:
───────────────────────
${filesList}
Workflow Configuration:
───────────────────────
- Name: ${workflowName}
- Class: ${className}
- Binding: env.${bindingName}
- Pattern: ${pattern}
Project Structure:
──────────────────
${projectName}/
├── src/
│ ├── index.ts (Worker entry + trigger)
│ └── workflows/
│ └── ${workflowFile} (Workflow class)
├── wrangler.jsonc (Cloudflare config)
├── package.json (Dependencies)
└── tsconfig.json (TypeScript config)
Quick Start:
────────────
1. Install dependencies:
npm install
2. Start development server:
wrangler dev
3. Test workflow:
curl http://localhost:8787
4. Deploy to Cloudflare:
wrangler deploy
5. Monitor instances:
wrangler workflows instances list ${workflowName}
Next Steps:
───────────
1. 📝 Customize workflow logic in src/workflows/${workflowFile}
2. 🧪 Test with /workflow-test command
3. 🔍 Debug issues with /workflow-debug command
4. 📊 Optimize with workflow-optimizer agent
5. 🚀 Deploy when ready with wrangler deploy
Resources:
──────────
- Quick Start: SKILL.md
- Common Issues: references/common-issues.md
- Workflow Patterns: references/workflow-patterns.md
- Production Checklist: references/production-checklist.md
- CLI Commands: references/wrangler-commands.md
Need help?
──────────
- Debug errors: Use workflow-debugger agent
- Interactive help: Use /workflow-debug command
- Test workflow: Use /workflow-test command
- Optimize: Use workflow-optimizer agent
Issue 1: Permission Denied
❌ Error: Cannot write to directory
Solution:
1. Check directory permissions
2. Run from project root
3. Create directories manually: mkdir -p src/workflows
Issue 2: Existing Files
⚠️ Warning: File already exists
Options:
1. Skip (keep existing)
2. Overwrite (backup created)
3. Merge (manual review needed)
Issue 3: Missing wrangler
❌ Error: wrangler not found
Solution:
1. Install wrangler: npm install -D wrangler
2. Or globally: npm install -g wrangler
3. Run setup again
Setup succeeds when:
Designs feature architectures by analyzing existing codebase patterns and conventions, then providing comprehensive implementation blueprints with specific files to create/modify, component designs, data flows, and build sequences