[BUG] TUI Fatal Error: Cannot read property 'name' of undefined (local.agent.current()) #8016

Open
opened 2026-02-16 18:08:56 -05:00 by yindo · 1 comment
Owner

Originally created by @barry2323 on GitHub (Jan 30, 2026).

Originally assigned to: @rekram1-node on GitHub.

Describe the bug

OpenCode TUI crashes with a fatal error when trying to access local.agent.current().name because local.agent.current() returns undefined.

Error Message

Full stack trace:

To Reproduce

  1. Open OpenCode TUI
  2. Error appears on startup or during certain operations
  3. TUI crashes with fatal error dialog showing three options: Copy issue URL, Reset TUI, Exit

Expected behavior

TUI should start and run normally without local.agent.current() returning undefined.

Screenshots

Environment

  • OpenCode Version:
  • OS:
  • Terminal:
  • Node.js:
  • Installation method:

Root Cause Analysis

The error occurs in src/cli/cmd/tui/component/prompt/index.tsx at line 857. The code attempts to access .name on the result of local.agent.current() without checking if it returns undefined.

Possible causes:

Image

  1. local.agent is not properly initialized
  2. No agent is currently selected but the code assumes one exists
  3. State management issue causing agent data to be lost

Suggested Fix

Add null-safety check before accessing the property:

// Current code (likely)
const agentName = local.agent.current().name;

// Suggested fix
const currentAgent = local.agent.current();
const agentName = currentAgent?.name ?? 'Unknown Agent';
Originally created by @barry2323 on GitHub (Jan 30, 2026). Originally assigned to: @rekram1-node on GitHub. ### Describe the bug OpenCode TUI crashes with a fatal error when trying to access `local.agent.current().name` because `local.agent.current()` returns `undefined`. ### Error Message Full stack trace: ### To Reproduce 1. Open OpenCode TUI 2. Error appears on startup or during certain operations 3. TUI crashes with fatal error dialog showing three options: Copy issue URL, Reset TUI, Exit ### Expected behavior TUI should start and run normally without `local.agent.current()` returning `undefined`. ### Screenshots <!-- Please upload your screenshot here --> ### Environment - OpenCode Version: <!-- e.g., v1.x.x --> - OS: <!-- e.g., macOS / Windows / Linux --> - Terminal: <!-- e.g., iTerm2 / Terminal --> - Node.js: <!-- run `node --version` --> - Installation method: <!-- curl / Homebrew / npm --> ### Root Cause Analysis The error occurs in `src/cli/cmd/tui/component/prompt/index.tsx` at line 857. The code attempts to access `.name` on the result of `local.agent.current()` without checking if it returns `undefined`. Possible causes: ![Image](https://github.com/user-attachments/assets/769b3fe1-43e7-453b-bd8f-f814a62b1535) 1. `local.agent` is not properly initialized 2. No agent is currently selected but the code assumes one exists 3. State management issue causing agent data to be lost ### Suggested Fix Add null-safety check before accessing the property: ```typescript // Current code (likely) const agentName = local.agent.current().name; // Suggested fix const currentAgent = local.agent.current(); const agentName = currentAgent?.name ?? 'Unknown Agent';
yindo added the opentui label 2026-02-16 18:08:56 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 30, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #11018: opentui: fatal: undefined is not an object (evaluating 'local.agent.current().name') - This is the exact same error with identical stack trace and root cause
  • #7918: Crash when local.agent.current() returns undefined during startup/auth - Documents the same issue occurring during authentication plugin initialization

Both issues describe the exact same problem where local.agent.current() returns undefined and the code attempts to access .name without null-safety checks.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 30, 2026): This issue might be a duplicate of existing issues. Please check: - #11018: opentui: fatal: undefined is not an object (evaluating 'local.agent.current().name') - This is the exact same error with identical stack trace and root cause - #7918: Crash when local.agent.current() returns undefined during startup/auth - Documents the same issue occurring during authentication plugin initialization Both issues describe the exact same problem where local.agent.current() returns undefined and the code attempts to access .name without null-safety checks. Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8016