Grok Bot hands coding tasks to a local OpenCode model and gets a webhook ping when done
Overview
The author connects Grok Bot to a local OpenCode model over Tailscale, with a webhook plugin that pings when a coding task finishes.
Workflow
Trigger: Let Grok Bot hand coding tasks to a local model, then get a PR and a summary when the work is done. The author says the local model was a cool demo that never got real work done. Readers already using Grok Bot can skip to the prompt at the end and let the bot set this up.
By hand: Understand the problem this stack is meant to solve. The author runs Inkling 2 Mini on a Mac Studio (M5 Max, 64 GB). It is free and private, but it lived in a separate harness from Codex and Cursor, and the author had to babysit it. Meanwhile, handing every task to a Cursor Cloud Agent eats into weekly Grok Bot usage. Now Grok Bot writes a detailed prompt, and the local model does the work.
By hand: Know how the pieces fit. One computer runs OpenCode, Tailscale, and Docker. That is where the model edits files, runs tests, and pushes to GitHub. It can be a spare PC, a Raspberry Pi, or a cloud VPS. OpenCode runs on the author's Ubuntu PC in a Docker container that can only touch ~/code. systemd starts it at boot. Tailscale keeps it private. Grok Bot reaches it through the Tailscale connector. Grok Bot starts OpenCode sessions and sends tasks. opencode-webhook, a tiny plugin the author made, pings a Grok Bot routine when a task finishes. No polling. Docker locks the model into a strict container that only sees the folders given to it, so it never has full access to the computer running OpenCode. Optionally, T3 Code adds a web UI and an easy way to use local models directly. Each bot tags its sessions (like Grok Bot [Chief of Staff]: add tests) so the ping goes back to whoever started it.
- By hand: Configure the model. Any OpenAI-compatible server works (MLX, llama.cpp, vLLM, LM Studio). Docker must be installed, with the user in the docker group. Create the OpenCode config directory, open the config file, and paste this configuration:
mkdir -p ~/.config/opencode nano ~/.config/opencode/opencode.json { "$schema": "https://opencode.ai/config.json", "provider": { "local": { "npm": "@ai-sdk/openai-compatible", "name": "My Local Model", "options": { "baseURL": "https://your-model-server/v1", "apiKey": "{env:LOCAL_API_KEY}" }, "models": { "your-model-id": { "name": "Your Model" } } } }, "model": "local/your-model-id", "permission": { "external_directory": "allow", "doom_loop": "deny" } }
The author says your-model-id must match the ID the server reports. The permission line matters: nobody is there to click allow when a bot drives OpenCode, so without it a session can sit busy forever. The container is the real boundary.
- By hand: Install the OpenCode plugin. Create the plugins directory and download webhook-notify.js:
mkdir -p ~/.config/opencode/plugins curl -fsSL https://raw.githubusercontent.com/araysuter/opencode-webhook/main/webhook-notify.js -o ~/.config/opencode/plugins/webhook-notify.js
This plugin lets OpenCode ping Grok Bot when a task finishes, fails, gets blocked on a prompt, hits model errors, or stalls for 10 minutes (OPENCODE_NOTIFY_STALL_MINUTES changes that).
- Bot: Create the Grok Bot routine. Ask one Grok Bot for a webhook routine called OpenCode task finished. Nothing polls: OpenCode hits the routine's URL when a task finishes. Other bots name their sessions after themselves, so that bot knows who to forward each ping to. Save the webhook URL and secret it gives.
- By hand: Add secrets. Create an environment file for OpenCode and open it in the terminal, paste the values with the owner's own secrets, then lock it down so only the owner can read it. The LOCAL_API_KEY name must match the {env:...} name in the Step 1 opencode.json.
nano ~/.config/opencode/env LOCAL_API_KEY=your-model-api-key OPENCODE_SERVER_PASSWORD=your-opencode-password OPENCODE_NOTIFY_WEBHOOK_URL=https://your-webhook-url OPENCODE_NOTIFY_SECRET=your-webhook-secret OPENCODE_NOTIFY_TITLE_PREFIX=Grok Bot chmod 600 ~/.config/opencode/env
- By hand: Build the container. Create the Docker directory, open the Dockerfile, paste the image definition, and build it:
mkdir -p ~/.config/opencode/docker nano ~/.config/opencode/docker/Dockerfile FROM debian:bookworm-slim ARG USER=opencode ARG UID=1000 ARG GID=1000 ARG HOME=/home/opencode ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates curl git jq python3 python3-pip python3-venv \ build-essential pkg-config libssl-dev ripgrep unzip gnupg \ && curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \ -o /usr/share/keyrings/githubcli-archive-keyring.gpg \ && chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
/etc/apt/sources.list.d/github-cli.list \
&& apt-get update && apt-get install -y --no-install-recommends gh \ && rm -rf /var/lib/apt/lists/* RUN groupadd --gid "$GID" "$USER" \ && useradd --uid "$UID" --gid "$GID" --create-home --home-dir "$HOME" "$USER" USER $UID:$GID ENV HOME=$HOME \ PATH="$HOME/.opencode/bin:$HOME/.cargo/bin:$HOME/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" RUN curl -fsSL https://opencode.ai/install | bash WORKDIR $HOME EXPOSE 4096 CMD ["opencode", "web", "--hostname", "0.0.0.0", "--port", "4096"] docker build --network=host --build-arg USER="$USER" --build-arg UID="$(id -u)" --build-arg GID="$(id -g)" --build-arg HOME="$HOME" -t opencode-sandbox:local ~/.config/opencode/docker
Now the start script. It mounts only the project folders and OpenCode's own data, never the home folder, SSH keys, or the Docker socket. The gh and .gitconfig mounts are optional and let it push PRs as the owner. Open the start script, paste it, make it executable, then reload the user systemd daemon:
nano ~/.config/opencode/docker/run.sh #!/bin/bash set -euo pipefail IMAGE="${OPENCODE_DOCKER_IMAGE:-opencode-sandbox:local}" exec /usr/bin/docker run --rm --name opencode \ --env-file "${HOME}/.config/opencode/env" \ --user "$(id -u):$(id -g)" \ --init \ -p 127.0.0.1:4096:4096 \ -v "${HOME}/code:${HOME}/code" \ -v "${HOME}/.t3/worktrees:${HOME}/.t3/worktrees" \ -v "${HOME}/.config/opencode:${HOME}/.config/opencode:ro" \ -v "${HOME}/.local/share/opencode:${HOME}/.local/share/opencode" \ -v "${HOME}/.local/state:${HOME}/.local/state" \ -v "${HOME}/.cache/opencode:${HOME}/.cache/opencode" \ -v "${HOME}/.config/gh:${HOME}/.config/gh:ro" \ -v "${HOME}/.gitconfig:${HOME}/.gitconfig:ro" \ -e "HOME=${HOME}" \ "${IMAGE}" \ opencode web --hostname 0.0.0.0 --port 4096 chmod 755 ~/.config/opencode/docker/run.sh systemctl --user daemon-reload
- By hand: Start it at boot with systemd. Create the user systemd directory, write the OpenCode service, enable lingering so it can run after logout, reload systemd, start the service, and publish it on Tailscale. Log in as opencode with the password. Restart anytime with systemctl --user restart opencode.
mkdir -p ~/.config/systemd/user nano ~/.config/systemd/user/opencode.service [Unit] Description=OpenCode web (Docker sandbox) After=docker.socket network-online.target Wants=network-online.target
[Service] Type=simple WorkingDirectory=%h ExecStartPre=-/usr/bin/docker rm -f opencode ExecStart=%h/.config/opencode/docker/run.sh ExecStop=/usr/bin/docker stop opencode Restart=on-failure RestartSec=5 TimeoutStopSec=30
[Install] WantedBy=default.target sudo loginctl enable-linger $USER systemctl --user daemon-reload systemctl --user enable --now opencode sudo tailscale serve --bg --https=8443 http://127.0.0.1:4096
- By hand: Connect Grok Bot. Connect the Tailscale connector in Grok Bot and save the OpenCode password as the secret OPENCODE_SERVER_PASSWORD. Then ask, for example, to have the local model add tests to my-repo and open a PR. The author says the owner will hear back when it is done.
By hand: Optionally add T3 Code for a browser or phone UI. T3 Code adds a UI for the browser or phone. Run it on the host, not in the container. It needs gh 2.81+. Create the directories, write the T3 service, start it, and publish it on Tailscale. If pushes fail with terminal prompts disabled, run gh auth setup-git.
mkdir -p ~/code ~/.t3/worktrees ~/.local/share/opencode ~/.local/state ~/.cache/opencode nano ~/.config/systemd/user/t3code.service [Unit] Description=T3 Code After=network-online.target Wants=network-online.target
[Service] Type=simple WorkingDirectory=%h/code EnvironmentFile=-%h/.config/opencode/env Environment=PATH=%h/.local/bin:%h/.opencode/bin:%h/.cargo/bin:/usr/local/bin:/usr/bin:/bin ExecStart=%h/.local/bin/t3 serve Restart=on-failure RestartSec=5
[Install] WantedBy=default.target systemctl --user enable --now t3code sudo tailscale serve --bg --https=8444 http://127.0.0.1:3773 gh auth setup-git
Bot: Or skip the manual steps and paste this setup prompt. The author says readers already using Grok Bot can skip to this prompt and let the bot set it up:
I want my local model to do coding work that you can steer. Follow this guide: [https://x.com/araysuter/status/2126417376769929259]. My model runs on an OpenAI-compatible server, and I'll give you its URL, model ID, and API key when you ask. Walk me through each step, give me one command at a time, and wait for me to confirm before moving on.
- Configure OpenCode in
~/.config/opencode/opencode.json to use my model as the default. - Install the plugin from https://github.com/araysuter/opencode-webhook so OpenCode pings you when a task finishes.
- Create a webhook routine called "OpenCode task finished." When another bot hands off a task, it names the session "Grok Bot [Bot Name]: …", and you forward the result to that bot. If no bot is named, tell me directly.
- Run OpenCode in a Docker container that can only see my
~/code folder. Start it at boot with a systemd user service, keep secrets in ~/.config/opencode/env (mode 600), and publish it with tailscale serve on port 8443. - Connect the Tailscale connector so you can reach my computer, and save my OpenCode password as the secret
OPENCODE_SERVER_PASSWORD.
Then test it. Create a session titled "Grok Bot: ping test", send "reply with pong" via prompt_async, and confirm both the reply and the done-ping arrive. Once it works, save how to hand off coding tasks so you remember next time. Never show my password, API key, or webhook secret in chat.
Check: The author reports a first-hand result: the local model finally does real work, and Grok Bot now hands it coding tasks and sends a PR and a summary when it is done (author's claim, not reproduced). The plugin is open source and works with any webhook: https://github.com/araysuter/opencode-webhook
Key points and results
- Grok Bot writes a detailed prompt; the local model does the work on a machine the owner controls. The author was babysitting Inkling 2 Mini in a separate harness from Codex and Cursor, and sending every task to a Cursor Cloud Agent was eating weekly Grok Bot usage. The new path is: Grok Bot starts an OpenCode session, a custom plugin pings a routine when the task finishes, and the owner gets a PR and a summary (author's claim, not reproduced).
- The container is the real security boundary. The start script mounts only project folders and OpenCode's own data, never the home folder, SSH keys, or the Docker socket. The permission line in opencode.json matters because nobody is there to click allow when a bot drives OpenCode.
- A webhook routine replaces polling. Ask one Grok Bot for a routine named OpenCode task finished, then put the webhook URL and secret into the env file. Each bot tags its sessions so the ping goes back to whoever started it.
- Readers already using Grok Bot can paste the setup prompt at the end and let the bot walk through the steps. The plugin is open source at https://github.com/araysuter/opencode-webhook and works with any webhook.
Source
- Platform
- X
- Author
- Asher Suter
- Published
- Categories
- Code and repos
What this evidence label means
Source read in full
We read the source (post, article or transcript). That only means the original was read. It does not mean this site reproduced the author's results.