Feature request: Simplified multi-turn conversation API for headless mode
Resolved 💬 1 comment Opened Jun 4, 2026 by nitrotap Closed Jun 4, 2026
Problem
When using claude --bare -p for programmatic/scripted workflows, multi-turn conversations require manual session management:
- Parse the session ID from the first invocation's output
- Pass
--resume <session_id>on subsequent calls - Handle the 15-minute session timeout
- Sessions are limited to 200k tokens with no easy way to detect approaching limits
This creates friction for building evaluation harnesses, CI pipelines, and agent orchestration systems that need conversational context.
Current Workaround
# First turn
SESSION_ID=$(claude --bare -p "question 1" --output-format json | jq -r '.session_id')
# Subsequent turns
claude --bare -p "follow-up" --resume "$SESSION_ID"
This works but requires:
- JSON parsing to extract session IDs
- External state management for session IDs
- No built-in way to know when context is nearly full
Proposed Solution
Consider one or more of:
--session-file <path>- Automatically persist/restore session state to a file, eliminating manual ID tracking--stdin-turns- Read multiple prompts from stdin (newline or JSON-delimited), executing as a single multi-turn session- Context usage in output - Include
tokens_used/tokens_remainingin the JSON output so callers can detect when to start a fresh session - Longer default timeout - 15 minutes is short for CI jobs that may queue; consider 1 hour or configurable via
--session-timeout
Use Cases
- Eval harnesses: Run multi-step question sets where later questions reference earlier answers
- CI pipelines: Multi-stage code review where context from earlier stages informs later ones
- Agent orchestration: External systems driving multi-turn Claude interactions programmatically
Environment
- Claude Code CLI
- Headless mode (
-p/--bare)
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗