Skip to content

tui: closing a session repeatedly opens an empty "New session" tab #64236

Closed

Description

@uriva

Summary

In the TUI (v2.3.0), closing open sessions frequently opens/leaves an empty New session tab active, requiring the user to repeatedly close empty new-session tabs. No empty session rows are persisted in opencode.db (session_v2), so this is client-side TUI tab/route behavior (home / New session slot).

Environment

  • opencode version: 2.3.0
  • OS: Linux 7.0.0-43-generic The scoll position doesn't reset in the permission modal #43-Ubuntu SMP PREEMPT_DYNAMIC x86_64 GNU/Linux
  • Terminal: TERM_PROGRAM=tmux, TERM=tmux-256color, COLORTERM=truecolor
  • Shell: /bin/bash
  • Install/channel: latest
  • Active plugins: ~/.config/opencode/plugins/alice-and-bot/index.js (verified it does not call TUI tab/route navigation)

Reproduction

  1. Run opencode TUI inside tmux with multiple open session tabs (default horizontal tab strip, cwd scope, ~15 open tabs).
  2. Close open session tabs.
  3. Observe an empty New session tab opening in the tab strip / switching view to an empty session.

Expected Behavior

Closing a session tab when other session tabs remain open should focus an existing neighboring/previous session tab without opening an empty New session tab.

Actual Behavior

Empty New session tabs open repeatedly and have to be manually closed.

Additional Context

  • Verified against ~/.local/share/opencode/opencode.db (session_v2 table): zero 0-message sessions are created on the server, confirming this is the TUI New session (home route) tab state.
  • TUI config (~/.config/opencode/cli.json) uses default tabs settings (animations: true, session.sidebar: "auto").

Activity

  1. added
    area/tui
    type/bug
    version/v2
    on Nov 16, 2026
  2. opencodejr commented on Nov 16, 2026

    @opencodejr
    Contributor

    Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.

    Thanks for the detailed report. I reproduced this on 2.3.0 in one specific setup: two TUIs open in the same directory. It still happens on the latest dev (e460646).

    With the default tabs.scope: "cwd", the tab list is shared by every TUI in that directory. What I did:

    1. In TUI A, create several sessions.
    2. In TUI B (same directory), switch to one of them.
    3. In TUI A, close that same session's tab. B keeps showing the session, but its tab is gone from the strip.
    4. In TUI B, press ctrl+x w. B lands on the empty + New session screen even though 4 session tabs are still open. Closing that empty tab then moves to a real session.

    With a single TUI I could not reproduce it: closing tabs with ctrl+x w or by clicking the ✕ always focused a neighbouring tab. If you usually have more than one opencode TUI open in the same project (for example in several tmux panes), this is very likely what you're hitting. If you see it with only one TUI open, please describe the steps.

    The recording and screenshots below show TUI B during the reproduction. A simulated model supplied the chat replies, which have no effect on how tabs close. The script below reproduces it.

    recording.mp4

    Screenshot

    Screenshot

    Reproduction script (drive.ts)
    import { Effect, Stream } from "effect"
    import { Llm, OpenCodeDriver } from "opencode-drive"
    
    const N = 5
    const row = (f: any, r: number) => f.lines[r].spans.map((s: any) => s.text).join("")
    
    export default OpenCodeDriver.use(
      {
        ...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
        tui: { recording: true, keypressOverlay: true },
        tuiConfig: { tabs: { layout: "horizontal", scope: "cwd" } } as any,
        project: { git: true, files: { "README.md": "hi\n" } },
      },
      (oc) =>
        Effect.gen(function* () {
          const { ui, llm } = oc
          yield* llm.serve((_req, i) => Stream.make(Llm.text(`Reply ${i + 1}`)))
          for (let i = 1; i <= N; i++) {
            if (i > 1) {
              yield* ui.press("x", { ctrl: true })
              yield* ui.press("n")
              yield* Effect.sleep(500)
            }
            yield* ui.submit(`Task number ${i}`)
            yield* ui.waitFor(`Task number ${i}`)
            yield* Effect.sleep(1200)
          }
          const b = yield* oc.tuis.launch({ recording: true, keypressOverlay: true } as any)
          yield* Effect.sleep(2500)
          yield* Effect.log(`B start: [${row(yield* b.ui.capture(), 0)}] ${row(yield* b.ui.capture(), 3).trim()}`)
          yield* b.ui.press("x", { ctrl: true })
          yield* b.ui.press("2")
          yield* Effect.sleep(1000)
          yield* Effect.log(`B on 2: [${row(yield* b.ui.capture(), 0)}] ${row(yield* b.ui.capture(), 3).trim()}`)
          yield* b.ui.screenshot("B-on-2")
          // TUI A: switch to the same session (tab 2) and close its tab there.
          yield* ui.press("x", { ctrl: true })
          yield* ui.press("2")
          yield* Effect.sleep(1000)
          yield* ui.press("x", { ctrl: true })
          yield* ui.press("w")
          yield* Effect.sleep(1500)
          const fa = yield* ui.capture()
          const fb0 = yield* b.ui.capture()
          yield* Effect.log(`A closed tab 2: A=[${row(fa, 0)}] ${row(fa, 3).trim()} || B=[${row(fb0, 0)}] ${row(fb0, 3).trim()}`)
          yield* ui.screenshot("A-closed-tab-2")
          yield* b.ui.screenshot("B-after-A-closed-tab-2")
          // TUI B: close its current tab while 4 other tabs are still open.
          for (let i = 0; i < 3; i++) {
            yield* b.ui.press("x", { ctrl: true })
            yield* b.ui.press("w")
            yield* Effect.sleep(1500)
            const fb = yield* b.ui.capture()
            yield* Effect.log(`B close ${i + 1}: B=[${row(fb, 0)}] ${row(fb, 3).trim()} | ${row(fb, 20).trim()}`)
            yield* b.ui.screenshot(`B-close-${i + 1}`)
          }
        }),
    )

    Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.

  3. added
    status/repro-simulated
    on Nov 16, 2026
  4. ccclucky commented on Nov 16, 2026

    @ccclucky

    I'll take this one.

    The tab strip is shared per cwd, so when another TUI closes the tab, this client's route still points at the session but its tab is gone. Closing it then finds no tab index to move from — closeSessionTab returns no next, and the navigation history has no earlier open tab — so the route falls back to home, which is the empty "New session" screen.

    I'll send a fix that picks a remaining tab in that case instead of home.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/tuiplatform/linuxstatus/repro-simulatedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions