anomalyco / anomalyco/opencode

The TUI cuts the end of a code block while it streams

Open
#43,688 1 comment 0 reactions 1 assignee View on GitHub

@simonklee is already working on this.

Since Aug 20, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

The problem

The TUI does not show the end of a code block while the model writes it. The end of the block appears only after you reload the session.
The saved data is complete. So the problem is only in the streaming display of the TUI.

The cause

The content setter in Code.ts (package @opentui/core) does not update the text buffer when a code block streams

set content(value) {
  if (this._content !== value) {
    this._content = value;
    this._highlightsDirty = true;
    this._highlightSnapshotId++;
    if (this._streaming && this._filetype && !this._drawUnstyledText) {
      this.requestRender();
      return; // The buffer stays old until the async highlight is ready.
    }
    // ...
  }
}

During streaming, each new token cancels the last highlight result. The buffer never receives the new text. So the display stays short.

The proposed fix

Use the last highlight again for the stable part. Draw the new part without a highlight.

set content(value) {
  if (this._content !== value) {
    this._content = value;
    this._highlightsDirty = true;
    this._highlightSnapshotId++;
    if (this._streaming && this._filetype && !this._drawUnstyledText) {
      if (this._shouldRenderTextBuffer) {
        if (this._lastHighlights.length > 0) {
          const styledText = new StyledText(
            treeSitterToTextChunks(value, this._lastHighlights, this._syntaxStyle, {
              enabled: this._conceal,
              baseHighlight: this._baseHighlight,
            }),
          );
          this.textBuffer.setStyledText(styledText);
        } else {
          this.textBuffer.setText(value);
        }
        this.setRenderedLineSources(undefined);
        this.updateTextInfo();
      }
      this.requestRender();
      return;
    }
    // ...
  }
}
This keeps the highlighted part and shows the new part at once. It does not flash unhighlighted code
Plugins

default

OpenCode version

1.18.15

Steps to reproduce
  1. Start the TUI
  2. Ask the model to write a long code block
  3. Watch the block while it streams. The text stops early
  4. Reload the session. The full block appears
Screenshot and/or share link

No response

Operating System

macos 26.5.2

Terminal

Terminal

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.