Skip to content

[Bug] New story creates separate terminal session — should reuse the Untitled session #162

@realproject7

Description

@realproject7

Problem

When a user clicks "+ New Story" and starts chatting with Claude, the AI creates a new story folder (e.g., `paper-chair`). But instead of the Untitled session becoming the `paper-chair` session, a new separate terminal session is spawned for `paper-chair`. The original Untitled session is left orphaned with a separate Claude instance.

This means:

  • Two Claude sessions running (wasted resources)
  • The context from the Untitled session (where the user discussed the story idea) is lost in the new session
  • The new `paper-chair` session starts fresh without the brainstorming context

Expected Flow

  1. + New Story → launches Untitled terminal session (Claude CLI in `~/.plotlink-ows/stories/`)
  2. User chats with Claude, brainstorms ideas
  3. Claude creates the story folder (e.g., `mkdir stories/paper-chair` + creates `structure.md`)
  4. The Untitled session seamlessly becomes the `paper-chair` session — same terminal, same Claude instance, same conversation context
  5. Sidebar updates: "Untitled" → "Paper Chair" (from structure.md title)
  6. Terminal tab updates: "Untitled" → "paper-chair"

Current Behavior

  • Step 3 happens: Claude creates the folder
  • The polling detects the new folder → creates a NEW terminal session for `paper-chair`
  • The Untitled session remains as a separate orphaned session
  • User now has two tabs: "Untitled" (old) + "paper-chair" (new, no context)

Fix

When the polling in `StoriesPage.tsx` detects a new story folder:

  1. Don't spawn a new terminal session for it
  2. Instead, rename the oldest Untitled session to the new story name
  3. Update the PTY session key in the `ptySessions` Map (backend) from `_new_XXX` to `paper-chair`
  4. Update the terminal tab display name
  5. The Claude CLI process continues running — same PID, same conversation

Backend change needed

Add an endpoint to rename a session key:
`POST /api/terminal/rename` — body: `{ oldName: "_new_1234", newName: "paper-chair" }`

This moves the PTY entry in the sessions Map without killing/restarting the process.

Frontend change needed

In the polling effect (`StoriesPage.tsx`), when a new story is detected:

  • Call the rename endpoint instead of letting a new session auto-create
  • Update the session key in the local Map
  • Remove the Untitled entry from `untitledSessions` state

Files

  • `app/web/components/StoriesPage.tsx` — polling logic for new story detection
  • `app/web/components/TerminalPanel.tsx` — session key management
  • `app/routes/terminal.ts` — add rename endpoint, update session Map

Acceptance Criteria

  • New story creation reuses the Untitled terminal session
  • Claude conversation context preserved (no restart)
  • Sidebar updates from "Untitled" to story title
  • Terminal tab updates from "Untitled" to story name
  • No orphaned Untitled sessions after story creation
  • Only one Claude process running per story

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions