CLAUDE LABJP
OPUS48 — Claude Opus 4.8 is generally available, improving on 4.7 across coding, agentic skills, reasoning, and knowledge workAUTO — Claude Code now defaults to auto mode on Bedrock, Vertex AI, and Foundry, and updates Bedrock to Opus 4.8GUARD — Auto mode now blocks tampering with session transcripts and asks before running rm -rf on an unresolved variableIDP — Admins can provision MCP connectors org-wide via their IdP (starting with Okta), granting access on first loginTIMEOUT — Fixed per-server request_timeout_ms being ignored, which timed out long MCP tool calls at the 60s defaultFAST — Fast mode for Opus 4.7 is deprecated and will be removed on July 24; migrate to fast mode for Opus 4.8OPUS48 — Claude Opus 4.8 is generally available, improving on 4.7 across coding, agentic skills, reasoning, and knowledge workAUTO — Claude Code now defaults to auto mode on Bedrock, Vertex AI, and Foundry, and updates Bedrock to Opus 4.8GUARD — Auto mode now blocks tampering with session transcripts and asks before running rm -rf on an unresolved variableIDP — Admins can provision MCP connectors org-wide via their IdP (starting with Okta), granting access on first loginTIMEOUT — Fixed per-server request_timeout_ms being ignored, which timed out long MCP tool calls at the 60s defaultFAST — Fast mode for Opus 4.7 is deprecated and will be removed on July 24; migrate to fast mode for Opus 4.8
Articles/API & SDK
API & SDK/2026-04-22Advanced

Building Fault-Tolerant Long-Running AI Workflows with Claude Agent SDK × Temporal.io — A Production Design Guide to Durable Execution and Saga Patterns

A complete production guide to combining Claude Agent SDK with Temporal.io to build AI workflows that survive crashes, restarts, and multi-day human approval gates. Durable Execution, retry policies, saga compensation, and signal integration patterns.

Claude Agent SDK13TemporalDurable ExecutionWorkflow OrchestrationProduction23

Premium Article

At 3 a.m., the AI agent running your invoice processing batch stops. After ten hours of work, 1,800 of 2,400 customers have been invoiced; 600 are still pending. Re-running the whole thing will double-charge 1,800 customers. Standing in front of the monitoring dashboard, your hands shake. I have lived through variations of this scene more than once on my own projects.

It is tempting to dismiss this as a problem solved by "just add an idempotency key before processing." But run AI agents in production long enough and you discover that deduplication alone is not enough. Did Claude API time out, or the downstream service? How far did we actually get? The workflow was supposed to pause for human approval — where does that pending state live if the process crashes?

For these "keep a long-running process safe no matter what happens" problems, the workflow engine Temporal.io offers a remarkably strong answer. Its Durable Execution model lets workflow code itself survive crashes and restarts and resume from where it left off. Combine that with the Claude Agent SDK and you get something that feels unreasonably robust for how little ceremony it requires.

This article walks through the design and implementation of a production-grade, long-running AI workflow built on Claude Agent SDK and Temporal, with working code. Rather than a "hello world," we use real scenarios — invoice processing, approval flows, batch processing — to explore saga compensation, external input via Signals, and memory management with Continue-As-New.

Why AI Agents Need Durable Execution

Most AI agent code assumes the process stays alive throughout. A top-level async def run_agent() keeps running until the task finishes; inside, a loop calls Claude API, invokes tools, and decides on the next action. That works fine for tasks completing in under fifteen minutes.

The moment workflows stretch to hours or days, the story changes. What if the server restarts? What if a container gets OOM-killed? What if a process sleeps for four hours waiting on human approval? Where do the retry policies for each step live? Can you reconstruct how far the workflow got from log files alone?

I tried to build all of this by hand and gave up repeatedly. Write checkpoints to Redis, create a jobs table in Postgres, hand-roll a retry decorator in Python — before long, you realize you are "reinventing a workflow engine." And not a good one.

Temporal is infrastructure purpose-built for this problem: insulating long-running processes from the instability of the machines they run on. Workflow code is persisted via event sourcing, so if a worker dies, another worker reconstructs the state and picks up where the first one stopped. Separating Claude API calls into Temporal Activities makes retries, timeouts, heartbeats, and idempotency declarative rather than hand-coded.

"This is overkill for my project," you might think. I thought so at first too. But once you put an AI workflow on Temporal, agent code actually gets simpler. Retry logic and state-persistence code disappear, leaving only business logic behind.

Understand Temporal in 15 Minutes

You only need four concepts to use Temporal effectively.

Workflow: The long-running business logic itself, written as a pure function with no side effects. Temporal persists the workflow's execution history (Event History) and can deterministically re-execute it from the same input if a process dies. Workflow code must not call APIs or use randomness directly.

Activity: Work with side effects — API calls, DB writes, external service integrations. Activities have retry policies and timeouts; when they fail and retry, the Workflow sees the work as transparently re-executed. Claude API calls belong here.

Worker: A process that executes Workflows and Activities. Horizontally scalable. When one worker dies, the Temporal server reassigns its work to another.

Signal / Query: Mechanisms to push external input into a Workflow (Signal) and to read its state (Query). These are how you integrate human approvals, external webhook notifications, and progress visualization into a workflow.

You can run Temporal yourself or use Temporal Cloud. During development, Docker is the easy path.

# Start the local Temporal dev server
# Install the temporal CLI: https://docs.temporal.io/cli
temporal server start-dev --ui-port 8080
 
# Open the web UI in another terminal
open http://localhost:8080

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Engineers frustrated by 'agents that die mid-task and cause duplicate charges on retry' will learn to build workflows on Temporal's Durable Execution that recover safely from any failure
You will acquire a systematic set of implementation patterns for wrapping Claude Agent SDK tool calls as Temporal Activities with exponential backoff, timeouts, and Heartbeat, bringing them to production grade
You will walk away with working code for four advanced patterns — Saga compensation, Signal/Query, Continue-As-New, and Child Workflow — applied to multi-day approval flows and batch processing
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

API & SDK2026-06-25
When the Previous Run Hasn't Finished and the Next One Starts: Leases and Fencing Tokens for Scheduled Agents
A scheduled agent that runs on a fixed clock can overtake itself and start twice. From the moment a naive lock breaks to leases, fencing tokens, and bounded catch-up — worked through with the implementation I actually run.
API & SDK2026-05-20
Resolving Tool Name Collisions When Bundling Multiple MCP Servers in the Claude Agent SDK
When the GitHub MCP and Linear MCP both expose create_issue, Sonnet 4.6 cannot tell them apart. This article walks through the structure of MCP tool name collisions, a TypeScript reconciler implementation, and the production failure modes I hit running six sites at once.
API & SDK2026-04-24
Giving Claude Agents Long-Term Memory in Production — Seven Pitfalls and the Patterns That Fix Them
A production playbook for Claude agents with long-term memory — seven pitfalls that break memory agents live, and the design patterns that fix each one.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →