Skip to content

Frequent "bun: command not found" Error in OpenCode TUI #2074

@jkiwen

Description

@jkiwen

Bug Report: Frequent "bun: command not found" Error in OpenCode TUI

Environment

  • OpenCode Version: 1.15.11
  • OS: Windows 11
  • Shell: PowerShell 5.1
  • ECC Plugin Version: 1.8.0
  • Bun Version: 1.3.14 (installed via Chocolatey)

Problem Description

When using OpenCode with ECC plugin enabled, frequent bun: command not found errors appear in the TUI interface. This occurs when:

  1. Starting OpenCode in a project directory
  2. Entering bash mode with !
  3. Executing any shell command

Error Message

bun: command not found: test

Reproduction Steps

  1. Open PowerShell terminal
  2. Navigate to project directory: cd E:\wsl\shared\workspace\kevin-project-manage
  3. Start OpenCode: opencode
  4. Press ! to enter bash mode
  5. Type any command (e.g., echo "test")
  6. Error appears in TUI

Expected Behavior

No bun-related errors should appear when using pnpm/npm projects.

Actual Behavior

bun: command not found error frequently appears in TUI, even though:

  • Project uses pnpm (has pnpm-lock.yaml)
  • No bun.lockb file exists in project
  • Bun is installed system-wide but not used in project

Investigation Results

1. ECC Plugin Analysis

The ECC plugin's shell.env hook detects package managers by checking lock files:

const lockfiles: Record<string, string> = {
  "bun.lockb": "bun",
  "pnpm-lock.yaml": "pnpm",
  "yarn.lock": "yarn",
  "package-lock.json": "npm",
}

Finding: The hook correctly detects no lock files in the project directory and sets PACKAGE_MANAGER to undefined.

2. OpenCode Process Analysis

  • OpenCode executable contains Bun runtime strings (bun:main, bun:vfs, bun:wrap)
  • Two OpenCode processes run simultaneously:
    • Main process (PID: 28112)
    • Server process with --port 24138 (PID: 42264)
  • Server process spawns PowerShell child process for shell execution

3. Log Analysis

OpenCode logs (~/.local/share/opencode/log/) show:

  • ECC plugin loads successfully
  • Package manager detection works correctly
  • No bun: command not found error is logged
  • Error only appears in TUI, not in log files

4. Environment Variables

$env:PACKAGE_MANAGER = "pnpm"  # Set by user
$env:ECC_DISABLED_HOOKS = "pre:bash:auto-tmux-dev"

Root Cause Hypothesis

The error likely originates from OpenCode's internal Bun runtime rather than ECC plugin:

  1. OpenCode appears to be built with Bun runtime (evidenced by binary strings)
  2. When executing shell commands, OpenCode's Bun runtime may attempt to use bun command
  3. The error occurs in TUI rendering layer, not in ECC hooks
  4. The error is not logged, suggesting it's a TUI/display issue

issue-attachments.zip

Suggested Fixes

For OpenCode

  1. Investigate why Bun runtime shows command not found errors in TUI
  2. Add proper error handling for shell command execution
  3. Log TUI errors to log files for debugging

For ECC Plugin

  1. Consider adding configuration to skip bun detection entirely
  2. Add option to set default package manager globally
  3. Improve error handling in shell.env hook

Additional Context

  • Project uses pnpm with pnpm-lock.yaml
  • No package.json in project root (monorepo structure)
  • Error occurs consistently across different terminal sessions
  • Error appears even when PACKAGE_MANAGER=pnpm is set

Attachments

All attachments are packaged in issue-attachments.zip:

1. Configuration Files

  • opencode-config.json - OpenCode global configuration (~/.config/opencode/opencode.json)
  • ecc-hooks.ts - ECC plugin hooks implementation (~/.opencode/plugins/ecc-hooks.ts)
  • project-opencode-config.json - Project-level OpenCode configuration (if exists)

2. Log Files

  • opencode-latest.log - Latest OpenCode log file (~/.local/share/opencode/log/)
    • Shows ECC plugin loading successfully
    • Shows package manager detection working correctly
    • No bun: command not found error is logged

3. Environment Information

  • environment-info.md - System environment details:
    • OpenCode version: 1.15.11
    • Bun version: 1.3.14
    • Node version: v22.15.1
    • PowerShell version: 5.1.26100.8521
    • Environment variables (PACKAGE_MANAGER, ECC_DISABLED_HOOKS, etc.)
    • Full PATH variable

4. Project Structure

  • project-structure.md - Project directory listing:
    • Shows monorepo structure (backend/, frontend/)
    • Shows no package.json in project root
    • Shows .opencode/ and .claude/ directories
    • Shows lock files location (frontend/pnpm-lock.yaml)

5. Key Observations from Attachments

From opencode-latest.log:

service=ecc [DEBUG] shell.env hook called - worktree=E:\wsl\shared\workspace\kevin-project-manage
checking lockfile: E:\wsl\shared\workspace\kevin-project-manage\bun.lockb -> false
checking lockfile: E:\wsl\shared\workspace\kevin-project-manage\pnpm-lock.yaml -> false
checking lockfile: E:\wsl\shared\workspace\kevin-project-manage\yarn.lock -> false
checking lockfile: E:\wsl\shared\workspace\kevin-project-manage\package-lock.json -> false
Final PACKAGE_MANAGER: not detected

From environment-info.md:

ECC_DISABLED_HOOKS=pre:bash:auto-tmux-dev
PACKAGE_MANAGER=pnpm
OPENCODE_PID=42264
OPENCODE_PROCESS_ROLE=worker

Labels: bug, bun, shell, tui, ecc-plugin
Priority: Medium
Affected Versions: OpenCode 1.15.11, ECC 1.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium prioritybugSomething isn't workingneeds-infoWaiting for more information from reporter

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions