JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 92
  • Score
    100M100P100Q91092F
  • License MIT

Discord bot for remote OpenCode CLI access

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.

    Gemini_Generated_Image_47d5gq47d5gq47d5

    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

    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-opencode

    Install from source

    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

    # Step 1: Run the interactive setup wizard
    remote-opencode setup
    
    # Step 2: Start the Discord bot
    remote-opencode start

    That'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

    1. Go to Discord Developer Portal
    2. Click "New Application"
    3. Enter a name (e.g., "Remote OpenCode")
    4. Copy the Application ID β€” you'll need this later
    image

    Step 2: Create Bot & Get Token

    1. Navigate to the "Bot" section in the sidebar
    2. Click "Reset Token" (or "View Token" if available)
    3. Copy the token immediately β€” it's only shown once!
    4. Keep this token secret β€” never share it publicly

    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"

    image

    Step 4: Configure Bot Permissions

    The bot needs specific permissions to function properly. You can configure permissions in two ways:

    1. Navigate to the "OAuth2" section in the sidebar

    2. Click on "URL Generator"

    3. In "Scopes", select:

      • βœ… bot
      • βœ… applications.commands
    4. 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 /opencode session
      • βœ… 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
    5. Copy the generated URL at the bottom β€” this is your bot invite link!

    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=311385214016&integration_type=0&scope=bot+applications.commands

    Important: The URL must include applications.commands scope for slash commands to work!

    Step 5: Get Your Server (Guild) ID

    1. Open Discord and go to User Settings β†’ Advanced
    2. Enable "Developer Mode"
    3. Right-click on your server name in the sidebar
    4. Click "Copy Server ID"
    스크란샷 2026-02-03 α„‹α…©α„Œα…₯ᆫ 2 34 31

    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=218900185540&scope=bot%20applications.commands
    1. Replace YOUR_CLIENT_ID with your Application ID
    2. Open the URL in your browser
    3. Select your server and authorize

    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:myapp

    After 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 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

    /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.

    /code β€” Toggle Passthrough Mode

    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 disable

    Example:

    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)

    /autowork β€” Toggle Automatic Worktree Creation

    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-1738600000000

    Example:

    You: /autowork
    Bot: βœ… Auto-worktree enabled for project myapp.
         New sessions will automatically create isolated worktrees.
    
    You: /opencode prompt:Add user authentication
    Bot: [Creates thread + auto-worktree]
         🌳 Auto-Worktree: auto/abc12345-1738600000000
         [Delete] [Create PR]
         πŸ“Œ Prompt: Add user authentication
         [streaming response...]

    Features:

    • 🌳 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

    Usage Workflow

    Basic Workflow

    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

    Mobile Workflow

    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 needed

    Pro tip: Enable passthrough mode with /code in a thread for an even smoother mobile experience β€” just type messages directly without slash commands!

    Team Collaboration Workflow

    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

    Worktree Workflow (Parallel Features)

    Work on multiple features without conflicts:

    1. Start a new feature:

      /work branch:feature/auth description:Implement OAuth2 login
    2. Work in the created thread:

      /opencode prompt:Add Google OAuth provider
    3. When done, create a PR: Click the Create PR button

    4. 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": [
        { "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

    Bot doesn't respond to commands

    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:
      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:myproject

    Commands not appearing in Discord

    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

    OpenCode server errors

    1. Verify OpenCode is installed:
      opencode --version
    2. Check if another process is using the port
    3. Ensure the project path exists and is accessible

    Session connection issues

    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

    Bot crashes on startup

    1. Check Node.js version:
      node --version  # Should be 22+
    2. Verify configuration:
      remote-opencode config
    3. Re-run setup:
      remote-opencode setup

    Development

    Run from source

    git clone https://github.com/RoundTable02/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 start

    Run tests

    npm test

    Project Structure

    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
    β”‚   β”œβ”€β”€ 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

    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)
    5. Open a Pull Request