← AI WorkflowsArrows or space · F for fullscreen · Print to saveTalks

CLAUDE CODE BUILD NIGHT · PART 8

AI
Workflows

Tonight, AI that runs all week. Every night stands on its own.

Ship AI · TalksAI Workflows01/21

Who's hosting

How you do anything is how you do everything.

Santos Hernandez
Santos HernandezFounder, Ship AI
$25k+/moggbucks, built with agents
$0 to $12MARR at ZBD
EU firstMiCAR approval
THE COMMUNITY

Ship AI

Free workshops and talks in Phoenix.

shipai.club
THE STUDIO

Ship AI Studio

AI built into your business, in two weeks.

shipaistudio.com

Ship AI · TalksAI Workflows02/21

Join the room

SHIP AI DISCORD

Scan it now.
Prompts later.

Open the Discord invite

Ship AI · TalksAI Workflows03/21

Our partner

Ship AIWorkuityAI Exchange

Building Phoenix's AI community, together. Workuity hosts tonight, and we present Founder Weekend side by side.

Ship AI · TalksAI Workflows04/21

THE IDEA

A request forgets.
A workflow remembers.

Ship AI · TalksAI Workflows05/21

Make it durable

ONE BIG FUNCTION

Times out. Starts over.

A WORKFLOW

Steps that survive.
Retry, sleep, wait for a yes.

Ship AI · TalksAI Workflows06/21

Tonight

01

Spec

02

Steps

03

Wait

04

Watch

Ship AI · TalksAI Workflows07/21

Tonight's workflow

WORKFLOW.md
Job

Sunday: five dinners from saved ingredients.

Wait

Nothing is emailed until they approve.

Retries

Each step retries. Emails send exactly once.

Done when

Approve sends one email

No answer in 2 days expires

Every run visible

Ship AI · TalksAI Workflows08/21

The Sunday plan

01

Generate

Five dinners, typed output

02

Ask

Email an approval link

03

Wait

Up to two days, no compute

04

Send

The plan, exactly once

Ship AI · TalksAI Workflows09/21

Spec the steps

claude · ~/whats-for-dinner

claudeWhat happens if they never approve?

youAfter two days, expire it.

claudeWhich steps have side effects?

✓ WORKFLOW.md: 9 steps, 1 hook, 1 sleep

Copy · write the workflow spec
Interview me about the Sunday plan, then write WORKFLOW.md as numbered steps, waits and retry rules. Wait for my OK.

Full prompt

Copy this entire prompt into Claude Code.

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.

Ship AI · TalksAI Workflows10/21

Install the Workflow SDK

~/whats-for-dinner
ONE PACKAGE, ONE WRAPPERnpm i workflow
withWorkflow(nextConfig)

Nitro: modules: ["workflow/nitro"].

01

You install the skill

It reads the docs for your installed version.

02

Claude wires it

next.config, tsconfig plugin, a workflows folder.

03

Prove it

A hello workflow with one step and one sleep.

Copy · set up the Workflow SDK
I add the workflow skill. Then npm i workflow, wrap next.config, and prove it with a hello workflow I can watch in npx workflow web.

Full prompt

Copy this entire prompt into Claude Code.

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.

workflow-sdk.dev

Ship AI · TalksAI Workflows11/21

AI inside a step

claude · ~/whats-for-dinner

✓ loadPantry · 9 ingredients

✓ generateWeek · 5 dinners, schema valid

✓ savePlan · status pending

claudeRun it for your test user and open the timeline.

Copy · the AI steps
Build loadPantry, generateWeek (AI SDK with Output.object through AI Gateway) and savePlan as steps, then run it once.

Full prompt

Copy this entire prompt into Claude Code.

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.

Ship AI · TalksAI Workflows12/21

Retry the step, not the run

WITHOUT

The model times out. Everything restarts.

WITH STEPS

Only that step retries.
The email sends once.

Copy · retries and idempotency
Set retries, use RetryableError for rate limits and FatalError for bad input, make side effects idempotent, then force one failure to watch it retry.

Full prompt

Copy this entire prompt into Claude Code.

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.

Ship AI · TalksAI Workflows13/21

Wait for a human yes

claude · ~/whats-for-dinner

⏸ Waiting on hook plan:8f2c · up to 2 days

you[ taps Approve on the plans page ]

✓ sendPlan · ✓ markSent

Copy · the approval step
Pause on a hook, email an approval link, race it against sleep("2d"), resume from an authenticated route, then send the plan once.

Full prompt

Copy this entire prompt into Claude Code.

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.

Ship AI · TalksAI Workflows14/21

Start it every Sunday

claude · ~/whats-for-dinner

✓ vercel.json: 0 16 * * 0 (9am Phoenix)

✓ /api/cron/sunday-plan checks CRON_SECRET

claude12 opted in · 12 runs started · 0 duplicates

Copy · the Sunday trigger
A protected cron route starts one run per opted-in user each Sunday at 9 AM Phoenix time, skips duplicates, then deploy.

Full prompt

Copy this entire prompt into Claude Code.

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.

Ship AI · TalksAI Workflows15/21

Watch every run

npx workflow inspect runs

sundayPlan · user 41 · completed · 2 retries

sundayPlan · user 57 · waiting on hook

sundayPlan · user 63 · expired

Copy · observability
List runs locally and on Vercel, make them findable by user and week, write a short RUNBOOK.md, and check Done when.

Full prompt

Copy this entire prompt into Claude Code.

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.

Also in the series: Part 9, Lock It Down. Security before anyone gets an admin console.

Ship AI · TalksAI Workflows16/21

BONUS ROUND

Photos fail sometimes.
Retry them.

Ship AI · TalksAI Workflows17/21

A fridge-photo pipeline

workflow · fridgePhoto

✗ readPhoto · 429 rate limited · retry in 1m

✓ readPhoto · eggs, spinach, feta, onion

✓ findDinners · 3 dinners

Copy · the photo workflow
Turn Snap your fridge into a workflow: a retrying vision step, then the dinner step, with status polling and photos kept out of the run log.

Full prompt

Copy this entire prompt into Claude Code.

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.

Ship AI · TalksAI Workflows18/21

Take it home

THE TALK PAGE

Every prompt,
and this deck.

Open the talk page

Ship AI · TalksAI Workflows19/21

Founder Weekend

FEB 6‑7, 2027 · FREE

Tonight was one hour.
Take a weekend.

An Arizona AI hackathon. Teams of 1-4.

See the hackathon

Ship AI · TalksAI Workflows20/21

SHIP AI DISCORD

Free and open.
Build with us.

Scan to join

Ship AI · TalksAI Workflows21/21
01/21