Learn to cap Claude Code headless runs with --max-turns, detect limit errors in JSON, and decide when to review, retry, or resume.