Claude Code Build Night · Part 8 · Coming soon

AI Workflows

AI that keeps working after the request ends.

How the night runs.

A short AI news briefing, then we build What's for Dinner's Sunday plan live with the Workflow SDK, then five-minute demos from the room.

  1. 01

    Spec

    One workflow, written as steps in WORKFLOW.md.

  2. 02

    Steps

    AI SDK calls inside retryable steps.

  3. 03

    Wait

    Sleep for days and pause for a human yes.

  4. 04

    Watch

    Every run, step and retry on screen.

The deck.

Every slide from the night, free to share. Open it full size to step through.

AI Workflows · slidesOpen full size →

Tonight's workflow.

The workflow spec we build from on the night: a Sunday plan that generates a week of dinners, waits for approval, then emails it. Copy it and swap in your own job.

WORKFLOW.mdWhat's for Dinner

What's for Dinner

Type what's in your fridge. Get three dinners you can make tonight.

The workflowEvery Sunday, five dinners from your saved ingredients, emailed only after you approve.

  • Workflow SDK
  • AI SDK
  • AI Gateway
  • Next.js
  • Resend
  • Vercel
Done when
  • A manual run creates a pending plan and asks for approval
  • Approving sends the plan email exactly once
  • No approval in time marks the plan expired
  • A forced failure retries, visible in the run timeline
  • The Sunday cron is protected and live
The full workflow spec
# WORKFLOW.md · Sunday plan

## Job
Every Sunday morning, each opted-in user gets five dinners for the week, built from their saved ingredients. Nothing is emailed until they approve it.

## Stack
- Next.js App Router, already deployed on Vercel
- Workflow SDK (`npm i workflow`), with `withWorkflow` from `workflow/next` in next.config
- AI SDK (`ai`) through Vercel AI Gateway, model as a "provider/model" string from the AI Gateway model list
- Resend for email, Neon for data, Better Auth for the approval page
- Nitro works too: add `modules: ["workflow/nitro"]` to nitro.config.ts

## Trigger
- A Vercel cron calls `GET /api/cron/sunday-plan` at `0 16 * * 0` (9:00 AM in Phoenix, which stays on UTC-7)
- The route checks `Authorization: Bearer $CRON_SECRET`, finds users with `sunday_plan_opt_in = true`, and calls `start(sundayPlan, [userId, weekOf])` from `workflow/api` for each
- It skips any user who already has a plan for that `weekOf`, because cron can deliver twice

## Workflow: sundayPlan(userId, weekOf)  "use workflow"
1. **loadPantry** (step): read the user's `saved_ingredients`. If empty, use the ingredients from their five most recent `dinners`. If there are still none, throw `FatalError` and stop
2. **generateWeek** (step): `generateText` with `Output.object` and a Zod schema: exactly five dinners, each with name, minutes, ingredients used, five steps. Only saved ingredients plus salt, oil and pepper
3. **savePlan** (step): insert the plan with status `pending`
4. **Approval hook** (workflow level): `createHook({ token: "plan:" + planId })`
5. **askForApproval** (step): email a link to `/plans/[planId]` with Resend
6. **Wait**: `Promise.race([hook, sleep("2d")])`. On timeout, mark the plan `expired` and stop
7. If the user asked for swaps, run **generateWeek** once more with their notes and save the new version
8. **sendPlan** (step): email the approved plan with Resend, using an idempotency key of `sunday-plan/${planId}`
9. **markSent** (step): set status `sent`

## Approval route
`POST /api/plans/[planId]/approve` with `{ approved, swaps? }`. Require a Better Auth session, check the plan belongs to that user, then call `resumeHook("plan:" + planId, payload)` from `workflow/api`.

## Retries and errors
- Steps retry on thrown errors (3 retries by default); generateWeek sets `maxRetries = 5`
- AI Gateway rate limit (429): throw `RetryableError` with `retryAfter: "1m"`
- Bad input (no ingredients, plan not found): throw `FatalError`, no retries
- Every step with a side effect is idempotent: inserts check for an existing row, emails use an idempotency key

## Observability
- Local: `npx workflow web`, or `npx workflow inspect runs`
- Production: workflow runs in the Vercel dashboard
- Each run is named by user and week, so support can find it

## Data
`plans`: id, user_id, week_of, dinners (JSON), status (pending, approved, expired, sent), created_at. Unique on (user_id, week_of).
`users`: add `sunday_plan_opt_in` (boolean, default false) and `saved_ingredients` (text array).
`saved_ingredients` is seeded from the distinct ingredients in each user's five most recent `dinners` rows, and the user can edit it in a field next to the opt-in toggle.

## Done when
- [ ] Starting the workflow by hand for a test user creates a pending plan and sends the approval email
- [ ] Approving on the plans page sends the plan email exactly once
- [ ] Not approving within the wait (shortened to 2 minutes for testing) marks the plan expired
- [ ] A forced failure in generateWeek retries and then succeeds, visible in the run's timeline
- [ ] The cron route is protected, skips users who already have a plan, and is live on Vercel

The prompts.

Every prompt from the deck, in order. Open one, copy it, paste it into Claude Code, Codex or any coding agent.

  1. 01
    Spec the steps
    Read SPEC.md and GROWTH.md. We're adding a weekly "Sunday plan": every Sunday, each opted-in user gets five dinners from their saved ingredients, and nothing is emailed until they approve.
    
    Interview me one question at a time and wait for each answer: what starts it, what each step does, what needs a human, how long to wait, what happens on failure, and which steps have side effects that must happen only once.
    
    Then write WORKFLOW.md with these sections: Job, Stack, Trigger, Workflow (numbered steps, marking which are steps and which are workflow-level waits), Approval route, Retries and errors, Observability, Data, Done when.
    
    Don't write code yet. Stop and wait for my OK.
  2. 02
    Install the Workflow SDK
    Read WORKFLOW.md.
    
    1. In my own terminal I'll run:
    npx skills add https://github.com/vercel/workflow --skill workflow
    Wait until I tell you it's done, and tell me to restart Claude Code if you can't see the skill.
    2. Run npm i workflow. Then read the Next.js getting-started guide in node_modules/workflow/docs and follow it: wrap next.config with withWorkflow from workflow/next and add the TypeScript plugin if it says to.
    3. Create workflows/hello.ts with one "use workflow" function that calls one "use step" function, sleeps for 10 seconds with sleep from workflow, then calls the step again. Add a route that starts it with start from workflow/api.
    4. Tell me to run npm run dev, hit the route, and open npx workflow web to watch the run. Stop there.
  3. 03
    AI inside a step
    Read WORKFLOW.md. Build steps 1 to 3 of the workflow in workflows/sunday-plan.ts.
    
    1. Add the plans table and the users columns from the Data section with a migration. In the same migration, fill saved_ingredients for every existing user with the distinct ingredients from their five most recent dinners rows (the dinners table from Part 3 already stores ingredients as a text array). Show me the count of users who got at least one ingredient.
    2. loadPantry: a "use step" function that reads saved_ingredients, falls back to the ingredients from the user's five most recent dinners if it's empty, and throws FatalError from workflow if there are still none.
    3. generateWeek: a "use step" function that calls generateText from ai with output: Output.object and a Zod schema for exactly five dinners. Use AI Gateway with a "provider/model" string; check the AI Gateway model list for the current model ID instead of guessing. AI_GATEWAY_API_KEY is already in .env.local.
    4. savePlan: insert the plan as pending, and return the existing plan if one exists for that user and week.
    5. sundayPlan(userId, weekOf): a "use workflow" function that runs the three steps in order. Keep fetch, database and AI calls inside steps only.
    
    Start it for my test user and tell me what to look for in npx workflow web. Stop there.
  4. 04
    Retry the step, not the run
    Read WORKFLOW.md, section Retries and errors, and the Workflow SDK errors and idempotency docs in node_modules/workflow/docs.
    
    1. Set generateWeek.maxRetries = 5.
    2. When AI Gateway returns a rate limit, throw RetryableError with retryAfter: "1m". For input that can never succeed, throw FatalError.
    3. Check every step with a side effect: database writes must check for an existing row, and emails must use Resend's idempotency key option with a key built from the plan id.
    4. Add a temporary flag that makes generateWeek fail on its first attempt. Run the workflow, and tell me where to see the failed attempt and the retry in npx workflow web. Then remove the flag.
  5. 05
    Wait for a human yes
    Read WORKFLOW.md, steps 4 to 9 and Approval route, and the hooks docs in node_modules/workflow/docs.
    
    1. In the workflow, create a hook with createHook and the token "plan:" plus the plan id. Follow the docs on registering a hook before a step hands out its link.
    2. askForApproval: a step that emails a link to /plans/[planId] with Resend. RESEND_API_KEY is already in .env.local.
    3. Wait with Promise.race between the hook and sleep("2d"). On timeout, mark the plan expired and return. Make the wait 2 minutes when an env flag is set for testing.
    4. Build /plans/[planId]: the five dinners, Approve, and a short "swap something" note. Its POST route requires a Better Auth session, checks the plan belongs to that user, then calls resumeHook from workflow/api.
    5. If there are swaps, run generateWeek once more. Then sendPlan and markSent.
    
    Tell me to approve one test plan and let another expire, and check both in npx workflow web. Stop there.
  6. 06
    Start it every Sunday
    Read WORKFLOW.md, section Trigger.
    
    1. Build GET /api/cron/sunday-plan. Return 401 unless the Authorization header is "Bearer " plus CRON_SECRET. Find opted-in users, skip anyone who already has a plan for this week, and call start(sundayPlan, [userId, weekOf]) for the rest.
    2. Add the cron to vercel.json with the schedule 0 16 * * 0, which is 9 AM in Phoenix. Check Vercel's current cron docs first.
    3. Add an opt-in toggle for the Sunday plan on the account page, with a "Your ingredients" field next to it that shows saved_ingredients and lets the user edit them. When someone opts in with an empty list, fill it from their five most recent dinners first.
    4. Tell me to add CRON_SECRET to .env.local and to the Vercel project's environment variables myself, and to make sure system environment variables are enabled for the project, as the Workflow SDK deploy docs say. Wait until I tell you it's done.
    5. Call the route locally twice with the secret, show me that the second call starts nothing, then deploy.
  7. 07
    Watch every run
    Read WORKFLOW.md, section Observability, and the observability docs in node_modules/workflow/docs.
    
    1. Show me how to list this week's runs locally with npx workflow inspect runs and in npx workflow web, and how to see the same runs for production in the Vercel dashboard.
    2. Make runs easy to find by user and week, using whatever the docs offer for naming or attributes.
    3. Write a short RUNBOOK.md: how to find one user's run, what each status means, how to cancel a stuck run, and how to start a run by hand for one user.
    
    Check every Done when item in WORKFLOW.md, tell me which pass, and stop.
  8. 08
    A fridge-photo pipeline
    Bonus round. Read WORKFLOW.md and the Snap your fridge section of SPEC.md if it exists.
    
    Move photo reading into a workflow, workflows/fridge-photo.ts:
    1. readPhoto: a step that sends the uploaded image to a vision-capable model through AI Gateway (check the model list for the ID) and returns ingredients as structured output. On a rate limit throw RetryableError with retryAfter: "1m"; if there's no food in the photo, throw FatalError with a friendly message.
    2. findDinners: a step that reuses our existing three-dinner logic.
    3. The upload route starts the workflow and returns the run id. The page polls a status route until it finishes or fails, and shows "Couldn't read that photo" on failure.
    4. Workflow inputs and step results are saved in the run's event log. Before building, read the serialization and data retention docs in node_modules/workflow/docs and tell me how to keep the photo bytes out of the log (for example, a short-lived upload the step reads and deletes). Wait for my pick.
    5. Show me one success and one forced failure in npx workflow web.

The toolkit.

The pieces of a durable workflow, one job each: the SDK, the model call, the email and the Sunday trigger.

Write the steps. Let it run all week.

Date to be announced. Dates go out in the Discord first.

Harbor at dusk · Phoenix, Arizona