Skip to content

save-session.sh fails with error_max_turns on Claude Code 2.1.x (--max-turns 1 broken) #98

Closed

Description

@davidomisi

Summary

save-session.sh silently fails at line 179 with exit 1 on Claude Code 2.1.x. The trap ERR fires and logs FAILED at line 179 (exit 1) but no further detail because set -e pre-empts the error-specific logging at line 183.

Root cause

Claude Code 2.1.x changed turn counting:

  • Before (1.x): --max-turns 1 = 1 complete response cycle (human prompt → model reply)
  • After (2.x): turn 1 = prompt delivery, turn 2 = model reply

With --max-turns 1, claude -p now exits 1 before the model can reply:

{
  "type": "result",
  "subtype": "error_max_turns",
  "is_error": true,
  "num_turns": 2,
  "errors": ["Reached maximum number of turns (1)"]
}

This affects both the main Haiku call (line 176) and the NDC compression call (line 242).

Environment

  • Claude Code: 2.1.177
  • Plugin: v0.7.3
  • OS: macOS 15 (Darwin 25.5.0)

Reproduction

echo "Hello, reply with just OK" > /tmp/test.txt
cd /tmp && env -u CLAUDECODE claude -p \
    --model haiku --allowedTools "" --max-turns 1 \
    --output-format json \
    --mcp-config '{"mcpServers":{}}' --strict-mcp-config \
    < /tmp/test.txt
echo "Exit: $?"  # → 1

Fix

Change both --max-turns 1 → --max-turns 2 in scripts/save-session.sh:

  • Line 176 (main Haiku call)
  • Line 242 (NDC compression call)
# Before
--model haiku --allowedTools "" --max-turns 1 \
# After
--model haiku --allowedTools "" --max-turns 2 \

With --max-turns 2, claude -p exits 0 and subtype: success.

Notes

  • The is_error: true JSON response still contains full token usage — the model ran successfully, but the CLI exit code was 1
  • set -e at line 53 causes the trap to fire at the assignment line (HAIKU_JSON=$(...)) before the if [ "$HAIKU_EXIT" -ne 0 ] block can log the stderr — making this hard to diagnose from logs alone
  • Applied as a local cache patch for now; will be overwritten on plugin update

Activity

  1. fdaviddpt commented on Jun 18, 2026

    @fdaviddpt
    Contributor

    Fixed in #101 — thank you for the precise diagnosis! 🙏 Your CC-2.x turn-counting writeup (turn 1 = prompt delivery, turn 2 = the reply) plus the clean repro made the root cause unambiguous. --max-turns is now configurable via REMEMBER_MAX_TURNS (default 4, validated to a sane range); the headless summarizer no longer dies before the model replies.

  2. added a commit that references this issue on Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions