New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ha-opencode

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ha-opencode

OpenCode plugin for Home Assistant integration via native WebSocket API

latest
Source
npmnpm
Version
0.3.2
Version published
Weekly downloads
17
183.33%
Maintainers
1
Weekly downloads
 
Created
Source

OpenCode Home Assistant Plugin

OpenCode

Unofficial Home Assistant Plugin for OpenCode

Documentation GitHub Release License: MIT

Note: This is an unofficial community project and is not affiliated with, endorsed by, or supported by OpenCode or Anomaly. OpenCode branding is used in accordance with their brand guidelines.

OpenCode plugin that enables real-time integration with Home Assistant via native WebSocket connection.

Monitor and control your OpenCode sessions directly from Home Assistant - get notified when tasks complete, approve permissions from your phone, and even send prompts remotely.

Full Documentation | Home Assistant Integration

Features

  • Native WebSocket: Direct connection to Home Assistant - no MQTT broker required
  • Secure Pairing: Simple one-time pairing flow with secure token authentication
  • Real-time Updates: Instant session state, model, tool, token, and cost updates
  • Permission Handling: Approve/reject tool permissions from Home Assistant or mobile notifications
  • Session History: Retrieve full conversation history on demand
  • Multi-session Support: Each session gets its own device in Home Assistant
  • Auto-reconnect: Persistent connection with automatic reconnection

Requirements

Installation

1. Install the Plugin

# From npm (when published)
npm install --prefix ~/.config/opencode ha-opencode

# Or from local path
npm install --prefix ~/.config/opencode /path/to/opencode-homeassistant

2. Add to OpenCode Config

Add "ha-opencode" to the plugins array in ~/.config/opencode/opencode.json:

{
  "plugins": ["ha-opencode"]
}

3. Install the Home Assistant Integration

The plugin requires the companion Home Assistant integration. See ha-opencode for installation instructions.

4. Pair with Home Assistant

  • In Home Assistant, go to Settings > Devices & Services
  • Add the "OpenCode" integration
  • A pairing code will be displayed (e.g., ABC12DEF)
  • In OpenCode, use the ha_pair tool with:

Once paired, the plugin will automatically reconnect on subsequent OpenCode sessions.

Configuration

The plugin stores connection configuration in ~/.config/opencode/ha-config.json after pairing:

{
  "url": "ws://homeassistant.local:8123/api/websocket",
  "accessToken": "your-access-token",
  "instanceToken": "generated-during-pairing",
  "instanceId": "instance_abc123"
}

You can also set the Home Assistant URL and access token via environment variables:

export OPENCODE_HA_URL=http://homeassistant.local:8123
export OPENCODE_HA_ACCESS_TOKEN=your-access-token

How It Works

┌─────────────────┐    WebSocket     ┌──────────────────┐
│                 │◄────────────────►│                  │
│    OpenCode     │                  │  Home Assistant  │
│    + Plugin     │                  │  + Integration   │
│                 │                  │                  │
└─────────────────┘                  └──────────────────┘
                                            │
                                            ▼
                                    ┌──────────────────┐
                                    │  Lovelace Card   │
                                    │  Mobile App      │
                                    │  Automations     │
                                    └──────────────────┘
  • Plugin connects to Home Assistant via WebSocket
  • Session updates are sent in real-time (state, model, tokens, cost, permissions)
  • Commands flow back from HA (send prompt, respond to permission, get history)
  • Events are fired in HA for automations (state changes, permission requests)

Commands from Home Assistant

The plugin responds to these commands sent via the Home Assistant integration:

CommandDescription
send_promptSend a text prompt to the current session
respond_permissionApprove (once/always) or reject a permission request
get_historyRetrieve session conversation history
get_agentsGet list of available agents

Session Data

Each OpenCode session reports the following to Home Assistant:

DataDescription
stateSession state: idle, working, waiting_permission, error
titleSession/conversation title
modelAI model being used (e.g., anthropic/claude-sonnet-4-20250514)
current_toolCurrently executing tool
tokens_inputTotal input tokens used
tokens_outputTotal output tokens used
costTotal session cost in USD
last_activityTimestamp of last activity
agentPrimary agent selected
current_agentSub-agent currently executing
hostnameMachine hostname
permissionPending permission details (if any)

Development

# Install dependencies
npm install

# Build TypeScript
npm run build

# Watch mode
npm run dev

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

Project Structure

src/
  index.ts        Plugin entry point
  websocket.ts    Home Assistant WebSocket client
  state.ts        Session state tracking
  commands.ts     Command handler (prompts, permissions, history)
  ha-config.ts    Configuration storage
  notify.ts       Terminal notifications (Kitty OSC 99)

tests/
  *.test.ts       Unit tests

Troubleshooting

Plugin not connecting

  • Verify the Home Assistant integration is installed and configured
  • Check that your access token is valid (test in Developer Tools > API)
  • Look for connection errors in OpenCode output
  • Try re-pairing: delete ~/.config/opencode/ha-config.json and pair again

Permission responses not working

  • Ensure the session is still active (not disconnected)
  • Check Home Assistant logs for errors
  • Verify the permission ID matches the pending permission

Notifications not appearing

This plugin uses Kitty terminal notifications (OSC 99). Supported terminals:

  • Kitty
  • iTerm2 (with notifications enabled)

If your terminal doesn't support OSC 99, notifications will be silent.

Documentation

Full documentation is available at stephengolub.github.io/opencode-homeassistant

License

MIT

Keywords

opencode

FAQs

Package last updated on 26 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts