Skip to content

Plugin console.log/warn/error output corrupts TUI display #19108

@RaviTharuma

Description

@RaviTharuma

Bug

Plugins loaded via opencode.json "plugin" array run in the same Bun process as OpenCode. When plugins (or their dependencies) call console.log, console.warn, or console.error, the output goes directly to stdout/stderr, corrupting the TUI display.

The logLevel config option only controls OpenCode's own slog-based logging — it has no effect on plugin console output.

Affected plugins (examples)

  • @rehydra/opencode — its dependency rehydra calls console.warn("Validation warnings:", ...) on every anonymization pass (upstream issue)
  • Custom .opencode/plugins/*.js — any plugin using console.log for debugging spams the TUI

Screenshot

Plugin console spam

Raw { c, Validation warnings:, and [memorix] hook fired: lines mixed into the TUI output, making it unreadable.

Expected behavior

Plugin console.* output should either:

  1. Be intercepted and routed through OpenCode's structured Log system (respecting logLevel)
  2. Be suppressed by default with an opt-in pluginLogLevel config
  3. Be redirected to a log file rather than stdout

Root cause

In packages/opencode/src/plugin/index.ts, plugins are loaded via import(plugin) and their init functions are called directly. There's no console interception — plugins share the global console object with the TUI process.

Suggested fix

Wrap plugin initialization and hook execution with a console override that routes through the Log system:

function withPluginConsole<T>(pluginName: string, fn: () => T): T {
  const original = { ...console }
  const pluginLog = Log.create({ service: `plugin:${pluginName}` })
  console.log = (...args) => pluginLog.info(args.map(String).join(" "))
  console.warn = (...args) => pluginLog.warn(args.map(String).join(" "))
  console.error = (...args) => pluginLog.error(args.map(String).join(" "))
  try {
    return fn()
  } finally {
    Object.assign(console, original)
  }
}

This keeps plugin logging visible in OpenCode's log system while preventing stdout corruption.

Environment

  • OpenCode 1.3.0
  • macOS 15.5
  • Bun 1.2.x

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions