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.

4 min readSume
All posts

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.

Claude Code CLI reference (read 2026-10-09)
FlagBehavior
--max-turnsPrint 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_get or sume jobs watch.
  • If the job is still queued, jobs_cancel works only before generation starts. After that it returns 409 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

All Developers posts

Written by Sume