Run OpenCode from Slack threads.
This bot lets you DM or mention a Slack app and have it run opencode commands behind the scenes, then stream back:
- assistant text
- tool calls
- file edits / writes
- token usage and cost
Each Slack thread maps to one OpenCode session, so replies continue context automatically.
src/app.js- Slack Bolt app (Socket Mode), event handlers, folder picker, queueingsrc/opencode.js- spawnsopencode run --format jsonand streams JSON eventssrc/formatter.js- converts OpenCode events into Slack Block Kit outputsrc/store.js- in-memory thread -> session mappingslack-manifest.json- Slack app manifest you can import
- Node.js 20+
opencodeinstalled locally- A Slack workspace where you can create apps
npm installRecommended: use the included manifest.
- Go to
https://api.slack.com/apps - Click Create New App
- Choose From a manifest
- Select your workspace
- Paste
slack-manifest.json - Create the app
After creation, get each value for .env:
SLACK_SIGNING_SECRET- Slack app page -> Basic Information -> App Credentials -> Signing Secret
SLACK_APP_TOKEN(xapp-...)- Basic Information -> App-Level Tokens -> Generate Token and Scopes
- Name it anything (example:
socket-mode) - Add scope:
connections:write - Copy generated token (
xapp-...)
SLACK_BOT_TOKEN(xoxb-...)- OAuth & Permissions -> Install to Workspace
- Authorize app
- Copy Bot User OAuth Token (
xoxb-...)
ALLOWED_USER_ID(U...)- In Slack desktop/web: click your profile -> more options -> Copy member ID
Important settings to verify in Slack app config:
- Socket Mode: ON
- Interactivity & Shortcuts: ON (required for folder picker buttons)
- Event Subscriptions bot events include:
app_mention,message.im
If you change manifest/settings after install, reinstall the app to workspace.
cp .env.example .envEdit .env:
SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...
SLACK_SIGNING_SECRET=...
ALLOWED_USER_ID=U...
OPENCODE_DEFAULT_DIR=/absolute/path/to/default/project
# Bookmarked folders (comma-separated) — shown as quick-pick buttons
OPENCODE_PROJECTS=/path/to/project-a,/path/to/project-b
# Root for the folder browser (defaults to $HOME)
OPENCODE_BROWSE_ROOT=/Users/you
# Optional; defaults to ~/.opencode/bin/opencode
# OPENCODE_BIN=/path/to/opencodeQuick check:
SLACK_BOT_TOKENstarts withxoxb-SLACK_APP_TOKENstarts withxapp-ALLOWED_USER_IDstarts withUOPENCODE_DEFAULT_DIRis an absolute path that existsOPENCODE_PROJECTSpaths are absolute and comma-separated (no quotes needed)
npm startYou should see startup logs indicating Socket Mode is connected.
DM the bot or mention it in a channel:
hello
@OpenCode fix the failing tests
When you start a new conversation, the bot shows a folder picker:
- Bookmarks — your pre-configured project folders as quick buttons
- Browse — navigate your filesystem to pick any folder
- Use default — skip and use
OPENCODE_DEFAULT_DIR
Once you pick a folder, your message runs against it.
Example first-message flow:
- You send:
fix the failing tests - Bot asks you to choose folder (Bookmarks / Browse / Use default)
- You select folder
- Bot runs your original message in that folder
Reply in the same thread to continue the same OpenCode session.
Skip the picker by prefixing your message:
dir:/Users/you/my-repo explain this codebase
When you click Browse, you get an interactive folder navigator:
- Click folder names to enter them
- Parent goes up one level
- Use this folder selects the current directory
The browser starts at OPENCODE_BROWSE_ROOT and only shows non-hidden directories.
- Default model:
anthropic/claude-opus-4-6 - Single-user allow-list via
ALLOWED_USER_ID - Messages are queued per thread while one run is in progress
- Session state is in-memory (lost on restart)
- Ensure
opencodeworks directly in terminal:
opencode run --format json "hello"- If needed, set absolute path in
.env:
OPENCODE_BIN=/Users/<you>/.opencode/bin/opencode- Confirm app is installed to workspace
- Confirm Socket Mode is enabled
- Confirm required events are enabled (
app_mention,message.im) - Confirm interactivity is enabled (needed for folder picker buttons)
- Confirm tokens/secrets in
.envare correct - Confirm message sender matches
ALLOWED_USER_ID
- Go to your Slack app settings → Interactivity & Shortcuts
- Make sure Interactivity is turned ON
- With Socket Mode, no Request URL is needed
- Mention the bot with
@OpenCode ... - For thread replies, bot only responds in threads it already started/tracks
- This bot executes OpenCode instructions with local machine access
- Restrict with
ALLOWED_USER_ID - Run under a least-privileged local account
- The folder browser can navigate any readable directory from
OPENCODE_BROWSE_ROOT - Be careful when changing
dir:to sensitive directories