Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (remote-opencode) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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
How It Works
βββββββββββββββββββ 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.
Table of Contents
- Installation
- Quick Start
- Discord Bot Setup
- CLI Commands
- Discord Slash Commands
- Usage Workflow
- Configuration
- Troubleshooting
- Development
- License
Installation
Prerequisites
- Node.js 22+ β Download
- OpenCode CLI β Must be installed and working on your machine
- Discord Account β With a server where you have admin permissions
Install via npm
# Global installation (recommended)
npm install -g remote-opencode
# Or run directly with npx
npx remote-opencodeInstall from source
git clone https://github.com/<your-username>/remote-opencode.git
cd remote-opencode
npm install
npm run build
npm link # Makes 'remote-opencode' available globallyQuick Start
# Step 1: Run the interactive setup wizard
remote-opencode setup
# Step 2: Start the Discord bot
remote-opencode startThat's it! Now use Discord slash commands to interact with OpenCode.
Discord Bot Setup
Before using remote-opencode, you need to create a Discord Application and Bot. The setup wizard will guide you, but here's a visual walkthrough:
Step 1: Create Discord Application
- Go to Discord Developer Portal
- Click "New Application"
- Enter a name (e.g., "Remote OpenCode")
- Copy the Application ID β you'll need this later
Screenshot placeholder: Discord Developer Portal showing "New Application" button
Step 2: Create Bot & Get Token
- Navigate to the "Bot" section in the sidebar
- Click "Reset Token" (or "View Token" if available)
- Copy the token immediately β it's only shown once!
- Keep this token secret β never share it publicly
Screenshot placeholder: Bot settings page with token section highlighted
Step 3: Enable Required Intents
Still in the "Bot" section, scroll down to "Privileged Gateway Intents" and enable:
- β SERVER MEMBERS INTENT
- β MESSAGE CONTENT INTENT
Click "Save Changes"
Screenshot placeholder: Intents section with required toggles enabled
Step 4: Configure Bot Permissions
The bot needs specific permissions to function properly. You can configure permissions in two ways:
Option A: Using OAuth2 URL Generator (Recommended)
Navigate to the "OAuth2" section in the sidebar
Click on "URL Generator"
In "Scopes", select:
- β
bot - β
applications.commands
- β
In "Bot Permissions", select only these essential permissions:
General Permissions:
- β View Channels β Required to access channels
Text Permissions:
- β Send Messages β Send responses to channels
- β
Create Public Threads β Create threads for each
/opencodesession - β Send Messages in Threads β Reply within threads
- β Embed Links β Send formatted embed messages
- β Read Message History β Access context for conversations
- β Add Reactions β Add buttons (uses emoji reactions internally)
- β Use Slash Commands β Register and use slash commands
Copy the generated URL at the bottom β this is your bot invite link!
Screenshot placeholder: OAuth2 URL Generator with bot permissions selected
Option B: Manual Permission Calculation
If you're building the URL manually, use this permission value:
https://discord.com/api/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=343932274624&scope=bot%20applications.commandsPermission Breakdown (343932274624):
| Permission | Value | Purpose |
|---|---|---|
| View Channels | 1024 | Access channels and read messages |
| Send Messages | 2048 | Send messages to channels |
| Create Public Threads | 68719476736 | Create threads for each /opencode command |
| Send Messages in Threads | 274877906944 | Reply within created threads |
| Embed Links | 16384 | Send rich embed messages with formatting |
| Read Message History | 65536 | Access previous messages for context |
| Add Reactions | 64 | Add button components (uses emoji reactions) |
| Use Slash Commands | 2147483648 | Register and respond to slash commands |
Optional Permissions (not required):
- Attach Files (32768) β Only if you want to upload files
- Mention @everyone (131072) β Only if bot needs to ping everyone
Important: The URL must include applications.commands scope for slash commands to work!
Step 5: Get Your Server (Guild) ID
- Open Discord and go to User Settings β Advanced
- Enable "Developer Mode"
- Right-click on your server name in the sidebar
- Click "Copy Server ID"
Screenshot placeholder: Right-click menu showing "Copy Server ID" option
Step 6: Invite Bot to Your Server
Use the URL generated in Step 4 (OAuth2 URL Generator), or construct it manually:
https://discord.com/api/oauth2/authorize?client_id=YOUR_CLIENT_ID&permissions=343932274624&scope=bot%20applications.commands- Replace
YOUR_CLIENT_IDwith your Application ID - Open the URL in your browser
- Select your server and authorize
Screenshot placeholder: Discord OAuth2 authorization page
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:
/setpath β Register a Project
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 |
/projects β List Registered Projects
View all registered project paths and their aliases.
/projects/use β Bind Project to Channel
Set which project a Discord channel should interact with.
/use alias:myappAfter binding, all /opencode commands in that channel will work on the specified project.
/opencode β Send Command to AI
The main command β sends a prompt to OpenCode and streams the response.
/opencode prompt:Add a dark mode toggle to the settings pageFeatures:
- π§΅ 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
/work β Create a Git Worktree
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.
Usage Workflow
Basic Workflow
Register your project:
/setpath alias:webapp path:/home/user/my-webappBind to a channel:
/use alias:webappStart coding remotely:
/opencode prompt:Refactor the authentication module to use JWTContinue the conversation in the created thread:
/opencode prompt:Now add refresh token support
Mobile Workflow
Perfect for when you're away from your desk:
- π± Open Discord on your phone
- Navigate to your bound channel
- Use
/opencodeto send tasks - Watch real-time progress
- Use the Interrupt button if needed
Team Collaboration Workflow
Share AI coding sessions with your team:
- Create a dedicated Discord channel for your project
- Bind the project:
/use alias:team-project - Team members can watch sessions in real-time
- Discuss in threads while AI works
Worktree Workflow (Parallel Features)
Work on multiple features without conflicts:
Start a new feature:
/work branch:feature/auth description:Implement OAuth2 loginWork in the created thread:
/opencode prompt:Add Google OAuth providerWhen done, create a PR: Click the Create PR button
Clean up: Click Delete to remove the worktree
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 |
config.json Structure
{
"discordToken": "your-bot-token",
"clientId": "your-application-id",
"guildId": "your-server-id"
}data.json Structure
{
"projects": {
"myapp": "/Users/you/projects/my-app"
},
"bindings": {
"channel-id": "myapp"
},
"threadSessions": { ... },
"worktreeMappings": { ... }
}Troubleshooting
Bot doesn't respond to commands
- Check bot is online: Look for the bot in your server's member list
- Verify permissions: Bot needs these permissions:
- Send Messages
- Create Public Threads
- Send Messages in Threads
- Embed Links
- Read Message History
- Redeploy commands:
remote-opencode deploy
"No project set for this channel"
You need to bind a project to the channel:
/setpath alias:myproject path:/path/to/project
/use alias:myprojectCommands not appearing in Discord
Slash commands can take up to an hour to propagate globally. For faster updates:
- Kick the bot from your server
- Re-invite it
- Run
remote-opencode deploy
OpenCode server errors
- Verify OpenCode is installed:
opencode --version - Check if another process is using the port
- Ensure the project path exists and is accessible
Session connection issues
The bot maintains persistent sessions. If you encounter issues:
- Start a new thread with
/opencodeinstead of continuing in an old one - Restart the bot:
remote-opencode start
Bot crashes on startup
- Check Node.js version:
node --version # Should be 22+
- Verify configuration:
remote-opencode config
- Re-run setup:
remote-opencode setup
Development
Run from source
git clone https://github.com/<your-username>/remote-opencode.git
cd remote-opencode
npm install
# Development mode (with ts-node)
npm run dev setup # Run setup
npm run dev start # Start bot
# Build and run production
npm run build
npm startRun tests
npm testProject Structure
src/
βββ cli.ts # CLI entry point
βββ bot.ts # Discord client initialization
βββ commands/ # Slash command definitions
β βββ opencode.ts # Main AI interaction command
β βββ work.ts # Worktree management
β βββ setpath.ts # Project registration
β βββ projects.ts # List projects
β βββ use.ts # Channel binding
βββ handlers/ # Interaction handlers
β βββ interactionHandler.ts
β βββ buttonHandler.ts
βββ services/ # Core business logic
β βββ serveManager.ts # OpenCode process management
β βββ sessionManager.ts # Session state management
β βββ 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.tsLicense
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request