Skip to content

fix(notify): cross-platform TTY write — /dev/tty unavailable in OpenCode plugin context on Windows #15

@MoerAI

Description

@MoerAI

Bug Description

warpNotify() in notify.ts writes OSC 777 escape sequences via writeFileSync("/dev/tty", ...). This fails silently on Windows because /dev/tty is a Unix-only device. The catch block swallows the error, so no notifications ever reach Warp on Windows (and possibly other platforms where the plugin subprocess lacks a controlling terminal).

This causes:

  • Setup chip never disappears (Warp never receives session_start)
  • No notifications for task completion, permission requests, or tool use
  • Plugin appears non-functional despite being correctly installed

Root Cause

OpenCode plugins run as JavaScript modules inside a Bun/Node.js subprocess managed by OpenCode's plugin loader. Unlike Claude Code's shell-based hooks (which execute printf ... > /dev/tty in bash with direct terminal access), the OpenCode plugin's writeFileSync("/dev/tty") fails because:

  1. Windows: /dev/tty doesn't exist in the Windows filesystem — Node.js uses native Win32 file APIs
  2. Plugin subprocess: Even on Unix, the plugin process may not have /dev/tty accessible if OpenCode spawns it with redirected stdio

Why PR #12's process.stdout.write() fallback doesn't work

PR #12 falls back to process.stdout.write(sequence) on failure. Users confirmed this still doesn't work because process.stdout in the plugin subprocess is piped to OpenCode's plugin loader for RPC communication — it doesn't reach the terminal.

Proposed Fix

Replace the single /dev/tty write with a platform-aware cascade:

  1. Unix: Try writeFileSync("/dev/tty") (existing behavior, works when controlling terminal is available)
  2. Windows: Try writeFileSync("CONOUT$") then writeFileSync("CON") — Windows console output devices that bypass stdio redirection
  3. Fallback: Try process.stderr.write() (stderr is less commonly redirected than stdout)

Additionally, port the WARP_CLIENT_VERSION validation from claude-code-warp's should-use-structured.sh to avoid sending notifications to known-broken Warp builds that set WARP_CLI_AGENT_PROTOCOL_VERSION but can't render structured notifications.

Environment

  • Affected OS: Windows 11 (confirmed), possibly macOS
  • Warp: Latest stable
  • OpenCode: 1.4.5+
  • Plugin version: 0.1.5

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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