@stand-e/opencode-slackcode
v0.3.45
Published
OpenCode plugin that streams session and agent activity into Slack.
Downloads
5,968
Maintainers
Readme
SlackIDE
SlackCode is an OpenCode plugin that streams session and agent activity to Slack.
Requirements
- OpenCode
>= 1.2.25 - Node.js
>= 18(CI uses Node 24) - Slack app credentials (
xoxb-...bot token)
Quick Start (Recommended)
Install the plugin with OpenCode:
opencode plugin add @stand-e/opencode-slackcodeThen configure either environment variables or .slackcode.
Option A: Environment Variables (fastest)
export SLACK_CHANNEL=C123456
export SLACK_BOT_TOKEN=xoxb-xxx
# Only needed for bidirectional mode (/opencode slash command):
export SLACK_APP_TOKEN=xapp-xxxOption B: .slackcode file
Create .slackcode in project root:
channel: C123456
bot_token: xoxb-xxx
app_token: xapp-xxx
flush_interval_sec: 1.5
message_chunk_limit: 2000
state_path: .opencode/slack_state.json
log_level: infoConfig precedence is: .slackcode first, then environment variables.
Usage
Start OpenCode normally. SlackCode will:
- Post a single startup status message when the plugin comes online
- Create one Slack root message per OpenCode session
- Post the triggering user prompt into that session's thread
- Stream session context and final agent output into that session's thread
- In bidirectional mode, let
/opencodecreate a session shell and let thread buttons choosePlanorBuild - Post
Session finishedonsession.idleorsession.deleted
Modes
One-way streaming (default)
OpenCode events -> Slack.
Bidirectional (slash command)
Use createBidirectionalPlugin() and enable Socket Mode:
import { createBidirectionalPlugin } from "@stand-e/opencode-slackcode/bidirectional";
const plugin = await createBidirectionalPlugin({
projectRoot: ".",
opencodeVersion: "1.2.25",
enableSocketMode: true,
});For this mode, set SLACK_APP_TOKEN (xapp-...).
@slack/socket-mode is already bundled as a transitive dependency of the plugin.
Current Slack control model:
/opencode <task>creates the Slack session threadPlanandBuildbuttons inside that thread choose how OpenCode should run the taskCancelstops the session- Slack thread replies are routed back into the matching OpenCode session through
client.session.prompt(...) - Custom Slack slash commands cannot be invoked inside Slack threads, so mode switching lives on buttons instead of nested
/opencodecalls
Log levels: debug, info, warn, error (default info, configured via .slackcode only).
When the plugin needs to refer back to the running OpenCode instance, it should prefer the serverUrl provided by OpenCode at plugin startup. OpenCode does not default to a fixed port. An explicit port like 4096 is only useful for manual debugging when you choose to launch OpenCode with --port.
Slack App Checklist
- Invite bot user to target channel
- Scopes:
chat:write(andfiles:writefor long-output uploads) - For private channels, invite bot explicitly
Troubleshooting
If no messages appear in Slack:
- Verify channel ID and bot membership
- Verify token values (
SLACK_BOT_TOKEN, optionalSLACK_APP_TOKEN) - Ensure config is loaded from the project root (env or
.slackcode)
Development
Build:
npm run buildPublish package:
npm publish --access publicNotes
- State is persisted to
.opencode/slack_state.jsonby default. - Long output is uploaded as a file when it exceeds
message_chunk_limit. - A startup dedupe marker is written to
.opencode/slackcode-startup.jsonto suppress duplicate startup notifications during rapid reinitialization.
Compatibility Layers We Keep
These are still in the code on purpose:
slackcode.cjsandbidirectional.cjsCommonJS shims: OpenCode package loading is still sensitive to entry-point shape, so we keep explicit CJS bridges for hosts that do not consume the ESM exports cleanly.- Legacy event field extraction:
Older one-way event payloads still use fields like
session.id,sessionId,session_id,message.text, andmessage.delta. We keep those readers so the plugin still works across older OpenCode event shapes while the modern structuredproperties.*events drive the new assistant-only aggregation path. - Startup dedupe marker:
OpenCode may initialize the plugin more than once during startup. The short-lived
.opencode/slackcode-startup.jsonmarker prevents duplicate "plugin started" notices in Slack.
Compatibility layers we intentionally are not keeping:
- TUI-only session targeting: We do not depend on undocumented TUI session-selection methods. Slack thread replies are sent to the mapped OpenCode session through the supported session API instead of trying to impersonate a foreground TUI keystroke.
- Token-by-token Slack streaming: Intermediate reasoning and partial text updates are suppressed. Slack receives the user prompt, session context, and final assistant output instead.
