CLI-DISCORD-BRIDGE(1)

NAME

cli-discord-bridgeCLI Discord bridge with Codex-first runtime and legacy Claude compatibility.

SYNOPSIS

$pip install -r

INFO

24 stars
1 forks
0 views
PythonAI & LLM

DESCRIPTION

CLI Discord bridge with Codex-first runtime and legacy Claude compatibility.

README

CLI Discord Bridge

Single-file Discord bridge for Codex CLI operation.

The actively maintained runtime targets Codex: one Discord channel connects to one Codex CLI process. Legacy artifacts remain only for rollback and command continuity.

Command surface remains compatible with earlier bridge flows: /new /status /connect /handoff /help.

Deployment Topology

  • Single process, single channel, single vendor (Codex)
  • One process listens to exactly one CHANNEL_ID
  • Multi-channel or multi-vendor HA is done by duplicating processes, not by mixing routes in one process

Runtime Flow

Discord message -> bridge.py -> codex exec/resume --json -> parse JSON events -> Discord reply

Bridge state:

  • State dir: ~/.cli-discord-bridge/
  • Session file: ~/.cli-discord-bridge/session.json
    • Primary key: thread_id
    • Backward-compatible read: legacy session_id
  • Handoff dir: ~/.cli-discord-bridge/handoffs/

Codex Session Protocol

  • New thread:
    • codex exec --json --skip-git-repo-check [--dangerously-bypass-approvals-and-sandbox] [-m MODEL] "<prompt>"
  • Resume thread:
    • codex exec resume --json --skip-git-repo-check [--dangerously-bypass-approvals-and-sandbox] [-m MODEL] <thread_id> "<prompt>"
  • Parser rules:
    • Parse JSON lines only, ignore non-JSON noise
    • Use thread.started.thread_id as authoritative thread ID
    • Aggregate item.completed.item.type=="agent_message" text as reply body

/connect safety:

  • Explicit /connect <thread_id> is strict.
  • If resume returns a different thread.started.thread_id, bridge treats it as failure and blocks auto-fallback.

Implicit fallback:

  • In non-explicit mode, resume failure may switch to a new thread and update local state.

Environment Variables

VariableRequiredDefaultDescription
DISCORD_TOKENYesDiscord bot token
CHANNEL_IDYesDiscord channel ID
CODEX_BINNocodexCodex CLI binary path
CODEX_MODELNoemptyOptional model override
CODEX_TIMEOUTNo300Max seconds per Codex call
CODEX_CWDNo$HOMEWorking directory for Codex call
CODEX_FULL_ACCESSNo01 enables --dangerously-bypass-approvals-and-sandbox
SELFTEST_ON_STARTNo01 runs startup selftest

Compatibility fallback (for smooth migration):

  • CLAUDE_CWD can still be used if CODEX_CWD is not set
  • CLAUDE_TIMEOUT can still be used if CODEX_TIMEOUT is not set

Commands

CommandBehavior
/newClear current thread; next message creates a new thread
/statusShow current thread, cwd, timeout, backend
/connect [thread-id]Bind explicit thread (no arg = reset)
/handoffSummarize old thread -> coldstart new thread; rollback old thread if new bootstrap fails
/helpShow command help

Local Run

python3 -m venv .venv
.venv/bin/pip install -r requirements.txt

DISCORD_TOKEN="xxx"
CHANNEL_ID="1234567890"
CODEX_FULL_ACCESS="1"
.venv/bin/python3 bridge.py

LaunchAgent (CLI)

Legacy rollback example:

  • com.claude.discord-bridge.plist.example (legacy)

Use the active CLI bridge example:

  • com.cli.discord-bridge.plist.example

Install example:

cp com.cli.discord-bridge.plist.example ~/Library/LaunchAgents/com.cli.discord-bridge.plist
# edit token/channel/paths
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.cli.discord-bridge.plist

Stop:

launchctl bootout gui/$(id -u)/com.cli.discord-bridge

Logs:

tail -f ~/.cli-discord-bridge/bridge.log
tail -f ~/.cli-discord-bridge/bridge.err.log

Gray Release and Rollback

Recommended migration sequence:

  1. Start com.cli.discord-bridge in a new Discord channel.
  2. Keep the legacy rollback service running in parallel for observation.
  3. Observe 24h for stuck process, leaks, thread loss, and command compatibility.
  4. Switch OpenClaw DR entry to the new CLI bridge channel.
  5. If needed, rollback by stopping com.cli.discord-bridge and continuing with legacy service.

Notes

  • This project does not implement dynamic multi-vendor switching in one process.
  • If you need more HA lanes, copy service instances with different CHANNEL_ID and state dirs.

SEE ALSO

clihub3/13/2026CLI-DISCORD-BRIDGE(1)