Skip to content

a chat view shows a Claude session's conversation, rendered and live (chat view 1/5) - #859

Merged
Ark0N merged 1 commit into
Ark0N:masterfrom
irisitymichaelgrundberg:chat-view/1-read
Dec 3, 2026
Merged

Ark0N merged 1 commit into
Ark0N:masterfrom
irisitymichaelgrundberg:chat-view/1-read

Conversation

@irisitymichaelgrundberg

@irisitymichaelgrundberg irisitymichaelgrundberg commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The first of five PRs for the chat view from #858. This one is read-only: the conversation shows
as rendered text, and the user still types in the terminal. The message box, the / menu, the
status line and the statusline follow in four more PRs, each opened once the one before it
merges. docs/chat-view-plan.md describes the whole feature.

What it does

  • A local or Docker Claude session gets a Chat / Terminal switch at the top right, and
    Alt+Shift+C does the same. Each session remembers its choice on this device.
  • Two per-device settings control it. "Open Claude sessions in Chat view" is off by default, and
    "Show the Chat / Terminal switch" is on by default. Phones, remote SSH sessions and adopted
    sessions keep the terminal, and so do the tile grid and the second pane of a split.
  • The conversation comes from the Response Viewer's own source,
    last-response?context=full, drawn by its markdown pipeline. An answer fills in while its turn
    is still running.
  • The terminal stays attached and keeps its size underneath, so switching views never resizes the
    pane.
  • Keep-warm turns are hidden, long prompts fold, and a "Working" line shows how long the turn has
    run. While Claude waits on a permission prompt or a question, a notice offers a button that
    opens the terminal.
image

What it adds to the server

Existing callers get what they got before.

  • A new SSE event, transcript:update, fires when new lines reach a session's transcript, at most
    once per 750 ms per session. The chat view re-reads the conversation on it.
  • A full conversation read starts a transcript watcher for a session that has none, such as one
    picked up after a server restart.
  • After /clear, the server follows the new conversation from the session_id and
    transcript_path that the statusline exporter already posts. The hook route's code for this
    moved into src/web/claude-conversation-report.ts, so both reports take the same path. No hook
    is added.

How I tested it

  • I have used Chat as my default view for daily work in Firefox, on the full branch.
  • npm run typecheck, lint, format:check, check:frontend-syntax and
    check:frontend-dead pass, and so do the chat view's test files.
  • Each of the five branches went through a local review loop of several reviewer agents and a
    Codex pass, and the findings that held up are fixed.

🤖 Generated with Claude Code

@Ark0N

Ark0N commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thank you for this, @irisitymichaelgrundberg. This PR adds a read-only Chat view for local and Docker Claude sessions: the conversation renders through the Response Viewer's pipeline over the still-attached terminal, refreshes live through a new transcript:update event, and the server now follows a /clear from the statusline exporter. The plan document, the tests and the care around focus, the tile grid and per-device settings are excellent, and every check passes here and in CI.

One thing needs to change before merge:

1. The live refresh re-parses the whole transcript on the server's main thread (src/web/routes/session-routes.ts:3430, driven by src/web/public/chat-view.js:374 and :475). While Chat shows a working session, every transcript:update (up to one per 750 ms) leads to a last-response?context=full read, which reads the entire file and runs JSON.parse on every line synchronously. The watcher fires on tool calls and tool results too, which the chat view does not draw, so most of these reads return the same messages. I measured the route with your branch on two real transcripts: a 66 MB one stalls the event loop for 375 to 434 ms per read, and a 219 MB one for 1.3 to 1.6 s. With reads back to back during a turn, that freezes every terminal, SSE stream and input on the server about once a second, and each extra browser tab on Chat adds its own read. Long sessions are the ones people leave in Chat, so this is the common case, not an edge. The clean fix is to keep the parser state and the byte offset per transcript path on the server (a small LRU), parse only the bytes appended since the last read, parse from zero when the file shrank or was replaced, and share one in-flight read between clients asking for the same file. That needs no API change and makes the Response Viewer's More button and the Discord bridge cheaper as well. A size bound (above some size, refresh only at the end of a turn) would also stop the stalls, at the cost of mid-turn updates on long sessions.

Smaller points, fine in the same push:

  • Docker sessions with working hooks (src/web/claude-conversation-report.ts:88): inside the container Claude runs with HOME=/home/agent, so the hook-reported transcript_path is /home/agent/.claude/projects/..., which does not exist on the host. The watcher polls it forever, no transcript:update fires, and the read-started watcher at session-routes.ts:3414 defers to that path, so a Docker case whose hooks reach the server only refreshes at turn start and end. Mapping a reported path under CONTAINER_CLAUDE_DIR + '/projects' to the host's projects folder for Docker sessions, or letting a full read take over a watcher whose path does not exist on this host, fixes it.
  • codeman:chatViewModes (src/web/public/chat-view.js:354) drops an entry only on a session:deleted the open page sees, so ids deleted while the page was closed stay forever, and a detach (which also sends session:deleted) forgets the choice of a session that can be re-attached. Pruning ids that are not in the session list after handleInit covers both.
  • src/web/public/styles.css:24104 and :24110 are two blocks for .chat-view-dialog; one is enough.

Once the re-read no longer scales with the file, this is ready to merge from my side.

…d and live

A local or Docker Claude session can show its conversation as rendered text,
the way the Response Viewer draws it, in place of the terminal. The terminal
stays attached and sized underneath, so switching views never resizes the pane,
and the user still types in the terminal. Discussion Ark0N#858 has the background.

- A Chat / Terminal switch and Alt+Shift+C change the view, and each session
  remembers its choice on this device until the session is gone. Two per-device
  settings pick the default view and hide the switch. Phones, remote and
  adopted sessions keep the terminal.
- The server broadcasts `transcript:update`, at most one per 750 ms per session,
  and the view re-reads the conversation on it, so an answer fills in mid-turn.
- The server keeps each transcript's parse and the byte offset it reached, so a
  read parses only the bytes appended since the last one, in chunks with an await
  between them. Overlapping reads of one file share one pass. The Response
  Viewer and the Discord bridge read through it too.
- A full conversation read starts a transcript watcher for a session that has
  none, such as one picked up after a server restart.
- A Docker session's hook reports the container's transcript path, and the
  server watches the host's copy of that file.
- After `/clear`, Claude Code runs the statusline command with the new
  conversation's id and transcript path. The statusline exporter posts them, and
  the server follows the new conversation the way it follows a hook's report.
- Keep-warm turns are hidden, long prompts fold, a "Working" line shows the turn's
  running time, and a pending dialog shows a notice that opens the terminal.

The design note, docs/chat-view-plan.md, covers this and the four steps that
follow it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@irisitymichaelgrundberg

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for measuring it. I've pushed the fix you preferred, in the same
single commit.

The transcript is no longer parsed whole on every read. The server keeps each transcript's
parse and the byte offset it reached, in an LRU of 16 paths (src/web/claude-response-transcript.ts).

  • A read parses only the bytes appended since the last one. It reads them in 1 MiB chunks with an
    await between chunks, so even the first read of a large file never holds the event loop for long.
  • It parses from byte 0 again when the file shrank or was replaced by another file. It also starts
    over when the 64 bytes before the stored offset changed, which catches a file rewritten in place.
  • Reads of one file that overlap share one pass. A read asked for while another runs waits for it
    and then parses what was appended meanwhile, so it never answers from before its own request.
  • A last line without its newline yet is parsed on a copy of the state, so every answer still
    equals a parse of the whole file.
  • The API doesn't change. The Response Viewer's More button and the Discord bridge read through it
    too.

I measured it on a 48 MB transcript of my own:

Read Total time Longest event-loop stall
Whole-file parse, as before 884 ms 884 ms
First read through the reader 628 ms 21 ms
Read after one appended line 2 ms 1 ms
Read with nothing appended 1 ms 2 ms

The smaller points are in the same push:

  • A Docker session's reported transcript path under /home/agent/.claude/projects now maps to the
    host's ~/.claude/projects, the folder the case mounts there. The watcher then follows the host's
    copy and transcript:update fires. A path with a .. segment is left as reported.
  • session:deleted no longer drops a session's stored view choice, so a detached session keeps it.
    After each handleInit, the page drops the choices of sessions that are not in the session list.
  • The two .chat-view-dialog blocks are one block now.

I've rebased the four follow-up branches on this commit. The / menu in slice 3 also read the
whole transcript for its skill list, so it now reads through the same reader.

@Ark0N

Ark0N commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thank you, @irisitymichaelgrundberg. This PR is the first slice of the chat view. Local and Docker Claude sessions get an opt-in, per-device Chat / Terminal switch, and Chat draws the conversation from the transcript through the Response Viewer's pipeline. A throttled transcript:update event keeps it live, and the server follows a /clear through the statusline exporter instead of a new hook.

All four points from the earlier review are fixed. I checked the reader against real transcripts on this machine. On a 219 MB transcript the first read takes 1.3 s in total, the longest event-loop stall is 11 ms, and a second read takes 0.6 ms. I appended a 61 MB transcript in random-sized pieces (cut mid-line and mid-character) and read it 64 times along the way, and every read matched a whole-file parse. The old and new parsers give identical output on 327 transcripts. The Docker path mapping, the view-choice pruning and the single .chat-view-dialog block are in too. Typecheck, lint, format, frontend syntax, dead-code and the full test suite pass here.

Four small things remain:

  1. src/web/CLAUDE.md:61 conflicts with master. Master added historyReloadAction to the same "does not declare" list this PR extends. Keeping both lists resolves it, and the merged tree passes typecheck and the related tests.
  2. src/web/sse-events.ts:8: the header says 165 event constants, but there are 164 (163 plus transcript:update).
  3. docs/chat-view-plan.md:138: the paragraph saying a Docker case with working hooks updates only at turn start and end was written before the path mapping in hostTranscriptPath(), so it describes the old behaviour.
  4. src/web/server.ts:1551: the captureIntentPrompt comment says only hook-fed sessions have a transcript watcher. Statusline reports and full reads start them now too.

None of this needs another round trip. I'll resolve the conflict and apply these on top when I merge. Thanks for splitting the work into slices and for the tests.

@Ark0N
Ark0N merged commit 3397d11 into Ark0N:master Dec 3, 2026
Ark0N pushed a commit that referenced this pull request Dec 3, 2026
- docs/chat-view-plan.md still said a Docker case with working hooks
  updates only at the start and end of a turn; since hostTranscriptPath()
  maps the container path to the host's copy, it gets mid-turn updates.
- The captureIntentPrompt comment said only hook-fed sessions have a
  transcript watcher; statusline reports and full reads start one too.

The third item (the SSE header count) needs no change on the merged tree:
master already had 164 constants under a header that said 163, and with
transcript:update the header's 165 is right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ark0N pushed a commit that referenced this pull request Dec 3, 2026
- README.ja.md: the link under the Mac download badge pointed at the
  English anchor; it now uses the translated heading's.
- Eleven bold and italic markers GitHub printed as literal characters
  (CommonMark: '_' inside a word never opens emphasis, and '**' between
  punctuation and a letter cannot open or close bold): '*' inside words,
  <strong> where the punctuation rule bites.
- The Japanese for the rate-limit sentence the English README gained
  after the branch was cut (a request with no credentials is never
  counted).
- The chat view's Alt/Option+Shift+C row (#859, this release) in the
  Japanese and Chinese shortcut tables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ark0N pushed a commit that referenced this pull request Dec 3, 2026
Replaces the four PR changesets (claude-starts-under-root,
installer-headless-sudo, trusted-proxy-sign-in, upload-html-documents)
and names #850, #859, #860 and #866, which brought none. Patch:
#854's changeset asked for minor, which is the owner's call at COM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ark0N

Ark0N commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Merged, and shipped in Codeman 1.52.1, as the first part of the chat view.

What went on top at merge time:

  • The conflict with Open Codex file links in a docked preview (COD-152) #850, which landed in the same release, is resolved by keeping both: historyReloadAction and your two keys in the per-device list of src/web/CLAUDE.md, and the docked file preview next to your two chat layers in both Z-index lists.
  • docs/chat-view-plan.md now describes the Docker case as it works since hostTranscriptPath(), and the captureIntentPrompt comment in server.ts no longer says only hook-fed sessions have a watcher.
  • The SSE header count needed no change after the merge: master already had one more event than its header said, so 165 is right.

One decision changed the default: the Chat / Terminal switch is now off by default (showChatViewSwitch is shown only when true), so nobody sees the chat view without choosing it in Settings > Header & Panels. Alt+Shift+C still switches views with the switch hidden, and both default tests in test/chat-view.test.ts follow.

Thank you for splitting the feature into slices, and for the reader rework with its measurements. The next slice is welcome whenever it is ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants