claude -p --max-turns exits with an error: Sume job in flight
When --max-turns ends a CI run, a Sume job may still be rendering. Keep the job id in the output, resume with jobs_wait, and never repeat the paid create.

With claude -p --max-turns N, Claude Code exits with an error when the limit is reached. If the last turn was a wait on a Sume render, the job keeps running and billing after the exit, so a CI step has to save the job id and pick the job up later, not submit again.
What does the limit do?
The CLI reference describes --max-turns as limiting agentic turns in print mode, exiting with an error when the limit is reached, with no limit by default. A turn that ends on jobs_wait counts as a turn even if the wait only returned a slice.
| Flag | Behavior |
|---|---|
| --max-turns | Print mode only; exits with an error when reached; no default limit |
How many turns does a Sume render need?
A render is a create plus waits. Each jobs_wait call holds at most 55 seconds (default 50), so a render of several minutes takes several waits. Budget for that, or have the agent call jobs_wait with up to 20 ids at once after a fan-out.
What should the CI step do on a turn-limit exit?
Make the job id durable before the limit can hit:
- Ask the agent to print each job id as soon as the create returns.
- On a non-zero exit, read the log for the id and call
jobs_getorsume jobs watch. - If the job is still queued,
jobs_cancelworks only before generation starts. After that it returns409 job_generation_already_started. - Do not rerun the whole prompt. A new paid create is a new charge.
What about retries?
If the create itself timed out, retry that request with the same idempotency_key so it returns the original job. The details are in Jobs and results.
Sources
Related posts
More in Developers
- Claude Code 2.1.288: MCP calls that ran twice, and paid Sume calls
2.1.288 fixed MCP tool calls sometimes running twice when a remote result was over 16 MB or unparsable. Why every paid Sume call needs an idempotency_key.
- claude -p --permission-prompts none: Sume tools in CI
With --permission-prompts none, prompts nobody can answer are denied. Which Sume tools still run? Read-only OAuth ones do; paid ones need mcp:write.
- Claude Code remote MCP backoff up to 30 s: retrying Sume safely
Headless Claude Code now backs off up to 30 s after remote MCP drops. A retried paid Sume call needs the same idempotency_key or you may pay twice.
- Claude Code closes ws MCP messages over 16 MiB: Sume sends URLs
Claude Code 2.1.295 closes a websocket MCP connection on a message over 16 MiB. Sume hosted MCP returns media.sume.com URLs for results, not file bytes.
Written by Sume