Skip to content

save-session.sh aborts (exit 1) under --max-turns 1 when user has Stop hooks #100

Closed

Description

@NORSAIN-AI

Summary

The autonomous save pipeline (scripts/save-session.sh) never writes memory in my setup. The Haiku extraction step exits 1 every run, so the pipeline aborts before writing now.md / handoff.

Root cause

save-session.sh invokes the nested summarizer as claude -p --model haiku --allowedTools "" --max-turns 1 ... (hardcoded on lines 176 and 242 in v0.7.3). The nested claude -p invocation inherits the user's configured Stop hooks (in my case a memory-review gate). That hook forces an additional turn, so the run uses 2 turns, hits the --max-turns 1 cap, and returns:

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

Exit code is 1, and save-session.sh:179 treats any non-zero exit as fatal (exit 1), so no memory is ever written. This is not auth/rate-limit — the API call succeeds and bills normally.

Reproduction

With any Stop hook configured in ~/.claude (e.g. a Stop hook that prints output), run:

echo "Reply with: ok" | env -u CLAUDECODE claude -p --model haiku \
  --allowedTools "" --max-turns 1 --output-format json \
  --mcp-config '{"mcpServers":{}}' --strict-mcp-config

Result: subtype: error_max_turns, num_turns: 2, exit 1.

The same call with --max-turns 4 returns subtype: success, exit 0 — confirming the cap is the cause (the hook consumes the extra turn).

Environment

  • remember plugin v0.7.3
  • Claude Code with user-level Stop hooks configured (memory-review gate)

Suggested fix

Raise --max-turns to at least 2 (ideally 3-4 for margin) on both lines 176 and 242, or make it configurable via an env var (e.g. REMEMBER_MAX_TURNS) so users with hooks can adjust it. A nested invocation that inherits user Stop hooks cannot reliably complete in a single turn.

Activity

  1. fdaviddpt commented on Jun 18, 2026

    @fdaviddpt
    Contributor

    Fixed in #101 — thank you! 🙏 The Stop-hook angle was the key extra insight: a user Stop hook consumes another turn, so even 2 can be too tight. The default is now 4 (clears the 2.x prompt-delivery turn plus a Stop-hook turn, with margin) and is overridable via REMEMBER_MAX_TURNS.

  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