---
name: Persistent Claude Code Sessions in Web UI
---

# Story 39: Persistent Claude Code Sessions in Web UI

## User Story

As a developer using the web UI with the claude-code-pty provider, I want my conversation context to persist across messages, so that Claude remembers what we've discussed and can build on prior work — just like a normal terminal Claude Code session.

## Background

Currently the `claude-code-pty` provider spawns a fresh `claude -p` process for every message, sending only the last user message. This means Claude has zero memory of prior conversation turns. The fix is to capture the session ID from the first `claude -p` call and pass `--resume <session-id>` on subsequent messages. Claude Code persists conversation transcripts locally as JSONL files, so resumed sessions have full context — identical to a long-running terminal session from the API's perspective.

## Acceptance Criteria

- [ ] First message in a web UI chat spawns `claude -p "<message>" --output-format stream-json --verbose` and captures the session ID from the `system` or `result` JSON event
- [ ] Subsequent messages in the same chat spawn `claude -p "<message>" --resume <session-id> --output-format stream-json --verbose`
- [ ] Conversation context carries across messages (Claude remembers what was said earlier)
- [ ] Starting a new chat in the web UI starts a fresh session (no resume)
- [ ] Session ID is held per web UI chat session (not global)
- [ ] Cancellation still works mid-message

## Out of Scope

- Multi-turn conversation history display in the frontend (already works via existing message state)
- Session persistence across server restarts
- Managing/cleaning up old Claude Code session files on disk
