Discord bot for remote OpenCode CLI access
npm install remote-opencode> Control your AI coding assistant from anywhere β your phone, tablet, or another computer.
remote-opencode is a Discord bot that bridges your local OpenCode CLI to Discord, enabling you to interact with your AI coding assistant remotely. Perfect for developers who want to:
- π± Code from mobile β Send coding tasks from your phone while away from your desk
- π» Access from any device β Use your powerful dev machine from a laptop or tablet
- π Work remotely β Control your home/office workstation from anywhere
- π₯ Collaborate β Share AI coding sessions with team members in Discord
- π€ Automated Workflows β Queue up multiple tasks and let the bot process them sequentially
```
βββββββββββββββββββ Discord API βββββββββββββββββββ
β Your Phone / β ββββββββββββββββΊ β Discord Bot β
β Other Device β β (this project) β
βββββββββββββββββββ ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β OpenCode CLI β
β (your machine) β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Your Codebase β
βββββββββββββββββββ
The bot runs on your development machine alongside OpenCode. When you send a command via Discord, it's forwarded to OpenCode, and the output streams back to you in real-time.
---
- Installation
- Quick Start
- Discord Bot Setup
- CLI Commands
- Discord Slash Commands
- Usage Workflow
- Configuration
- Troubleshooting
- Development
- Changelog
- License
---
- Node.js 22+ β Download
- OpenCode CLI β Must be installed and working on your machine
- Discord Account β With a server where you have admin permissions
`bashGlobal installation (recommended)
npm install -g remote-opencode
$3
`bash
git clone https://github.com/RoundTable02/remote-opencode.git
cd remote-opencode
npm install
npm run build
npm link # Makes 'remote-opencode' available globally
`---
Quick Start
`bash
Step 1: Run the interactive setup wizard
remote-opencode setupStep 2: Start the Discord bot
remote-opencode start
`That's it! Now use Discord slash commands to interact with OpenCode.
---
Discord Bot Setup
The setup wizard (
remote-opencode setup) guides you through the entire process interactively:1. Opens Discord Developer Portal in your browser
2. Walks you through creating an application, enabling intents, and getting your bot token
3. Generates the invite link automatically and opens it in your browser
4. Deploys slash commands to your server
Just run
remote-opencode setup and follow the prompts β no manual URL copying needed!
π Manual setup reference (click to expand)
If you prefer manual setup or need to troubleshoot:
1. Create Application: Go to Discord Developer Portal, create a new application
2. Enable Intents: In "Bot" section, enable SERVER MEMBERS INTENT and MESSAGE CONTENT INTENT
3. Get Bot Token: In "Bot" section, reset/view token and copy it
4. Get Guild ID: Enable Developer Mode in Discord settings, right-click your server β Copy Server ID
5. Invite Bot: Use this URL format:
`
https://discord.com/api/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=2147534848&scope=bot+applications.commands
`---
CLI Commands
| Command | Description |
|---------|-------------|
|
remote-opencode | Start the bot (shows setup guide if not configured) |
| remote-opencode setup | Interactive setup wizard β configures bot token, IDs |
| remote-opencode start | Start the Discord bot |
| remote-opencode deploy | Deploy/update slash commands to Discord |
| remote-opencode config | Display current configuration info |---
Discord Slash Commands
Once the bot is running, use these commands in your Discord server:
$3
Register a local project path with an alias for easy reference.
`
/setpath alias:myapp path:/Users/you/projects/my-app
`| Parameter | Description |
|-----------|-------------|
|
alias | Short name for the project (e.g., myapp, backend) |
| path | Absolute path to the project on your machine |$3
View all registered project paths and their aliases.
`
/projects
`$3
Set which project a Discord channel should interact with.
`
/use alias:myapp
`After binding, all
/opencode commands in that channel will work on the specified project.$3
The main command β sends a prompt to OpenCode and streams the response.
`
/opencode prompt:Add a dark mode toggle to the settings page
`Features:
- π§΅ Auto-creates a thread for each conversation
- β‘ Real-time streaming β see output as it's generated (1-second updates)
- βΈοΈ Interrupt button β stop the current task if needed
- π Session persistence β continue conversations in the same thread
$3
Start isolated work on a new branch with its own worktree.
`
/work branch:feature/dark-mode description:Implement dark mode toggle
`| Parameter | Description |
|-----------|-------------|
|
branch | Git branch name (will be sanitized) |
| description | Brief description of the work |Features:
- π³ Creates a new git worktree for isolated work
- π§΅ Opens a dedicated thread for the task
- ποΈ Delete button β removes worktree and archives thread
- π Create PR button β automatically creates a pull request
This is perfect for working on multiple features simultaneously without branch switching.
$3
Enable passthrough mode in a thread to send messages directly to OpenCode without slash commands.
`
/code
`How it works:
1. Run
/code in any thread to enable passthrough mode
2. Type messages naturally β they're sent directly to OpenCode
3. Run /code again to disableExample:
`
You: /code
Bot: β
Passthrough mode enabled for this thread.
Your messages will be sent directly to OpenCode.You: Add a dark mode toggle to settings
Bot: π Prompt: Add a dark mode toggle to settings
[streaming response...]
You: Now add a keyboard shortcut for it
Bot: π Prompt: Now add a keyboard shortcut for it
[streaming response...]
You: /code
Bot: β Passthrough mode disabled.
`Features:
- π± Mobile-friendly β no more typing slash commands on phone
- π§΅ Thread-scoped β only affects the specific thread, not the whole channel
- β³ Busy indicator β shows β³ reaction if previous task is still running
- π Safe β ignores bot messages (no infinite loops)
$3
Enable automatic worktree creation for a project. When enabled, new
/opencode sessions will automatically create isolated git worktrees.`
/autowork
`How it works:
1. Run
/autowork in a channel bound to a project
2. The setting toggles on/off for that project
3. When enabled, new sessions automatically create worktrees with branch names like auto/abc12345-1738600000000Features:
- π³ Automatic isolation β each session gets its own branch and worktree
- π± Mobile-friendly β no need to type
/work with branch names
- ποΈ Delete button β removes worktree when done
- π Create PR button β easily create pull requests from worktree
- β‘ Per-project setting β enable/disable independently for each project$3
Control the automated job queue for the current thread.
`
/queue list
/queue clear
/queue pause
/queue resume
/queue settings continue_on_failure:True fresh_context:True
`How it works:
1. Send multiple messages to a thread (or use
/opencode multiple times)
2. If the bot is busy, it reacts with π₯ and adds the task to the queue
3. Once the current job is done, the bot automatically picks up the next oneSettings:
-
continue_on_failure: If True, the bot moves to the next task even if the current one fails.
- fresh_context: If True (default), the AI forgets previous chat history for each new queued task to improve performance, while maintaining the same code state.---
Usage Workflow
$3
1. Register your project:
`
/setpath alias:webapp path:/home/user/my-webapp
`2. Bind to a channel:
`
/use alias:webapp
`3. Start coding remotely:
`
/opencode prompt:Refactor the authentication module to use JWT
`4. Continue the conversation in the created thread:
`
/opencode prompt:Now add refresh token support
`$3
Perfect for when you're away from your desk:
1. π± Open Discord on your phone
2. Navigate to your bound channel
3. Use
/opencode to send tasks
4. Watch real-time progress
5. Use the Interrupt button if neededPro tip: Enable passthrough mode with
/code in a thread for an even smoother mobile experience β just type messages directly without slash commands!$3
Share AI coding sessions with your team:
1. Create a dedicated Discord channel for your project
2. Bind the project:
/use alias:team-project
3. Team members can watch sessions in real-time
4. Discuss in threads while AI works$3
Perfect for "setting and forgetting" several tasks:
1. Send multiple instructions:
`
You: Refactor the API
Bot: [Starts working]
You: Add documentation to the new methods
Bot: π₯ [Queued]
You: Run tests and fix any issues
Bot: π₯ [Queued]
`2. The bot will finish the API refactor, then automatically start the documentation task, then run the tests.
3. Monitor progress: Use
/queue list to see pending tasks.---
Configuration
All configuration is stored in
~/.remote-opencode/:| File | Purpose |
|------|---------|
|
config.json | Bot credentials (token, client ID, guild ID) |
| data.json | Project paths, channel bindings, session data |$3
`json
{
"discordToken": "your-bot-token",
"clientId": "your-application-id",
"guildId": "your-server-id"
}
`$3
`json
{
"projects": [
{ "alias": "myapp", "path": "/Users/you/projects/my-app", "autoWorktree": true }
],
"bindings": [
{ "channelId": "channel-id", "projectAlias": "myapp" }
],
"threadSessions": [ ... ],
"worktreeMappings": [ ... ]
}
`| Field | Description |
|-------|-------------|
|
projects[].autoWorktree | Optional. When true, new sessions auto-create worktrees |---
Troubleshooting
$3
1. Check bot is online: Look for the bot in your server's member list
2. Verify permissions: Bot needs these permissions:
- Send Messages
- Create Public Threads
- Send Messages in Threads
- Embed Links
- Read Message History
3. Redeploy commands:
`bash
remote-opencode deploy
`$3
You need to bind a project to the channel:
`
/setpath alias:myproject path:/path/to/project
/use alias:myproject
`$3
Slash commands can take up to an hour to propagate globally. For faster updates:
1. Kick the bot from your server
2. Re-invite it
3. Run
remote-opencode deploy$3
1. Verify OpenCode is installed:
`bash
opencode --version
`
2. Check if another process is using the port
3. Ensure the project path exists and is accessible$3
The bot maintains persistent sessions. If you encounter issues:
1. Start a new thread with
/opencode instead of continuing in an old one
2. Restart the bot: remote-opencode start$3
1. Check Node.js version:
`bash
node --version # Should be 22+
`
2. Verify configuration:
`bash
remote-opencode config
`
3. Re-run setup:
`bash
remote-opencode setup
`---
Development
$3
`bash
git clone https://github.com/RoundTable02/remote-opencode.git
cd remote-opencode
npm installDevelopment mode (with ts-node)
npm run dev setup # Run setup
npm run dev start # Start botBuild and run production
npm run build
npm start
`$3
`bash
npm test
`$3
`
src/
βββ cli.ts # CLI entry point
βββ bot.ts # Discord client initialization
βββ commands/ # Slash command definitions
β βββ opencode.ts # Main AI interaction command
β βββ code.ts # Passthrough mode toggle
β βββ work.ts # Worktree management
β βββ setpath.ts # Project registration
β βββ projects.ts # List projects
β βββ use.ts # Channel binding
βββ handlers/ # Interaction handlers
β βββ interactionHandler.ts
β βββ buttonHandler.ts
β βββ messageHandler.ts # Passthrough message handling
βββ services/ # Core business logic
β βββ serveManager.ts # OpenCode process management
β βββ sessionManager.ts # Session state management
β βββ queueManager.ts # Automated job queuing
β βββ executionService.ts # Core prompt execution logic
β βββ sseClient.ts # Real-time event streamingβ βββ dataStore.ts # Persistent storage
β βββ configStore.ts # Bot configuration
β βββ worktreeManager.ts # Git worktree operations
βββ setup/ # Setup wizard
β βββ wizard.ts # Interactive setup
β βββ deploy.ts # Command deployment
βββ utils/ # Utilities
βββ messageFormatter.ts
βββ threadHelper.ts
`---
Changelog
See CHANGELOG.md for a full history of changes.
$3
#### Added
- Automated Message Queuing: Added a new system to queue multiple prompts in a thread. If the bot is busy, new messages are automatically queued and processed sequentially.
- Queue Management: New
/queue slash command suite to list, clear, pause, resume, and configure queue settings.$3
#### Added
- New
/setports slash command to configure the port range for OpenCode server instances.#### Fixed
- Fixed Windows-specific spawning issue (targeting
opencode.cmd).
- Resolved spawn EINVAL errors on Windows.
- Improved server reliability and suppressed DEP0190 security warnings.$3
#### Added
- New
/model slash command to set AI models per channel.
- Support for --model flag in OpenCode server instances.#### Fixed
- Fixed connection timeout issues.
- Standardized internal communication to use
127.0.0.1.---
License
MIT
---
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (
git checkout -b feature/amazing-feature)
3. Commit your changes (git commit -m 'Add some amazing feature')
4. Push to the branch (git push origin feature/amazing-feature`)