Skip to content

Thread sessions

By default (BOT_MODE=bridge) the container runs a small Node service, bridge/, instead of the Discord channel plugin. It uses discord.js and the Claude Agent SDK and gives every Discord thread its own Claude Code session.

  1. @mention the bot in a listened channel (DISCORD_CHANNELS). The bot creates a thread from your message and starts a new session in it.
    • Forums work too: add the forum’s ID to DISCORD_CHANNELS, and a new post that @mentions the bot (or any post, with DISCORD_REQUIRE_MENTION=false) becomes a session.
    • Any channel: with DISCORD_MENTION_EVERYWHERE=true, an @mention in any text channel the bot can see starts a thread there too (outside DISCORD_CHANNELS a mention is always needed). An @mention inside an existing thread or forum post brings Claude into that thread; since people keep talking there, Claude only answers messages that @mention it. Mentioning the bot’s role counts as mentioning the bot.
  2. Write in the thread to continue that session. No @mention is needed in the thread.
  3. Start another thread for another task. Each thread has its own context, and threads run in parallel.

Reactions on your message show what happened:

Reaction Meaning
👀 A new turn started.
➕ Claude was already working in this thread; your message joined the running turn.
⏳ All slots are busy (BRIDGE_MAX_CONCURRENT); the turn starts when one frees up.
⏸️ Claude’s usage limit is reached; the message is sent automatically when it resets.

Reactions you can add to any message in a session thread:

Reaction Effect
🛑 Stops the running turn (like !stop).
🔁 Sends your last message to Claude again.

When Claude reports that the plan’s usage limit is reached (a rejected rate-limit event or a rate_limit error), the bot stops sending instead of failing:

  • The turn that hit the limit ends with “⏸️ Claude’s usage limit is reached. I’ll continue here automatically in 2 hours”, and the thread name gets ⏸️.
  • New messages, in any thread or a new thread, get a ⏸️ reaction and wait.
  • A minute after the reset time Claude gave (or, if it gave none, the reset of the full plan window), every thread continues: an interrupted turn first gets “continue where the limit stopped you”, then the waiting messages go out in order.
  • Waiting messages and the reset time are saved, so a restart loses nothing.
  • !limit shows the state and which threads wait, !limit now sends right away (if the limit is still on, they wait again), !limit clear drops this thread’s waiting messages. The status message and the bot’s status show the limit too.

While Claude works, a small line at the bottom of the thread shows that it is busy and what it is doing, e.g. ✻ Combobulating… · 1m 12s · editing index.html. The word changes now and then (picked locally), the activity comes from the tools Claude calls, so it uses no tokens. The line moves below each new reply and disappears when the turn ends. BRIDGE_SPINNER=false turns it off.

The words come from a theme. By default that is Claude Code’s own 185 verbs; !spinner switches a thread to one of ~150 community themes (Breaking Bad, Kaomoji, Git Commit Messages…) or to random, a different theme every turn. The themes are downloaded from wynandw87/claude-code-spinner-verbs at startup and once a day, not copied into this repo; the last good download is kept in spinner-verbs.json in the state dir. If nothing was ever downloaded, the bridge falls back to its own short list.

While a session works, the thread name starts with its state: ⏳ working, ❓ Claude asked a question or waits for an Allow/Deny, ✅ done, ⚠️ error, ⏹️ stopped. In a forum the bot also sets a status tag (In progress, Waiting, Done); it reuses tags with those names or creates them. Discord allows only 2 renames per 10 minutes per thread, so in a quick back-and-forth the name catches up a little later. BRIDGE_THREAD_STATUS=false turns this off.

Archiving a thread stops its running turn, and the bot stays quiet there until someone writes again. Thread renames, pins and other Discord system messages are never sent to Claude.

Every command works as !name and as a Discord slash command (/status, /model…) with autocomplete. Slash commands are registered on startup (BRIDGE_SLASH_COMMANDS=false turns that off).

Command Effect
!status In a thread: state, model / effort / mode, session, context fill, tasks, git branch and changed files, plan usage. In the channel: the same overview as the pinned status message.
!usage Work in this thread, today (per person) and the last 7 days, plus plan usage.
!model / !effort Shows the thread’s model and effort.
!model sonnet Uses another model in this thread: opus, fable, sonnet, haiku or a full ID like claude-sonnet-5-5. A running turn switches right away.
!effort medium Effort for this thread from the next message: low, medium, high, xhigh, max.
!model reset / !effort reset Back to the server default.
!model default sonnet / !effort default medium Changes the default for every thread without its own setting. … default reset goes back to CLAUDE_MODEL / CLAUDE_EFFORT.
!spinner Shows the thread’s spinner theme. !spinner breaking bad sets it (any spelling, or a unique part of the name), !spinner random picks a new theme every turn, !spinner reset goes back to the default.
!spinner list / !spinner preview <theme> All themes with their word counts / a few sample words. !spinner refresh downloads the list again.
!spinner default kaomoji Spinner theme of every thread without its own. !spinner default reset goes back to BRIDGE_SPINNER_THEME.
!mode plan Permission mode of this thread: plan (read and plan only), auto, acceptEdits, default (asks for everything), dontAsk; reset goes back to CLAUDE_PERMISSION_MODE. A running turn switches right away. bypassPermissions is only offered when the container already runs in it.
!context What fills the context window (system prompt, tools, memory, messages…) and how full it is.
!compact [focus] Summarizes the conversation to free context. Uses tokens for the summary.
!new / !clear Forgets the conversation; the next message starts a new session. Model, effort, mode and spinner settings stay.
!rewind Undoes Claude’s file changes since your last message, after showing the files and asking for confirmation. Reply to an earlier message with !rewind to go back further. Only files change; the conversation stays, so tell Claude what you reverted.
!todo Claude’s task list in this thread.
!diff git status and a change summary of the working directory.
!mcp MCP servers and whether they are connected.
!stop Interrupts the running turn.
!session Shows the thread’s Claude session ID.
!limit Usage limit state and waiting messages. !limit now sends them now, !limit clear drops this thread’s.
!version Bot version (release tag), commit, build time, Claude Code version and uptime. Also in the status message footer.
!help Lists the commands.

!status, !usage, !help and the default forms also work directly in a listened channel and in the status channel, without starting a session.

Claude Code slash commands: a message in a session thread that starts with / is passed to Claude Code as typed, so its commands and skills work from Discord, e.g. /code-review or /security-review. Their output is posted to the thread.

Cost of commands: none of the ! commands use tokens except !compact. !context, !mcp and !rewind between turns start a short Claude process that resumes the session without sending a prompt (about a second). Passed-through / commands that make Claude work use tokens like any message.

Each thread runs on the server default model and effort (CLAUDE_MODEL / CLAUDE_EFFORT, or what !model default / !effort default set) unless the thread has its own (!model … in it). Defaults changed from Discord are stored in settings.json in the state dir and survive restarts.

Usage is shown in four places:

  • Footer: after each answer the bot posts a small grey line such as Opus 5.5 · high · 14 steps · 3m 12s · ~$0.38 · 5h 42%: model, effort, tool steps, time, estimated cost of that turn and the 5-hour plan window. BRIDGE_FOOTER=false turns it off.
  • !usage: a reply with this thread’s total, today’s total per person, the last 7 days and the plan windows with their reset times.
  • Pinned status message: set BRIDGE_STATUS_CHANNEL to a channel ID. The bot posts one message there, pins it, and edits it when a turn starts or ends and every 5 minutes: default model, plan usage bars, which threads are working, and today’s / this week’s spend. The message ID is kept in status.json; delete the message and the bot posts a new one.
  • Bot status: the bot’s Discord status shows e.g. Opus 5.5 · 5h 42% · 1 working. BRIDGE_PRESENCE=false turns it off.

Where the numbers come from:

  • Cost is the Agent SDK’s total_cost_usd for each turn, at API list prices. With an API key it matches the bill, so dollar amounts are shown. With a Claude subscription nobody is billed per token, so by default (BRIDGE_SHOW_COST=auto) the dollars are hidden: the footer leaves them out and !usage / the status message show turns plus each person’s share of the day’s work in %, still computed from the cost. Totals are kept for 90 days in usage.json in the state dir. A turn’s cost is counted for the person whose message started it.
  • Plan usage (5-hour and 7-day windows) is only available with a subscription login. It comes from the rate-limit info Claude Code receives with each answer, and from the SDK’s experimental /usage data when the login allows it. It updates whenever the bot answers, so between answers it shows the last known value; a window whose reset time has passed is shown as 0 %. The limits are stored with a fingerprint of the Claude login (a hash, not the token); when the container starts with a different token, they are cleared and fetched again with the next answer.
#channel ── @bot msg ──► new thread ──► new session (UUID stored for the thread)
thread A ── msg ───────► session A ┐
thread B ── msg ───────► session B ├─ run in parallel, up to BRIDGE_MAX_CONCURRENT
thread C ── msg ───────► waits ⏳ ┘
  • Sessions: the thread ID → session ID map is stored in ~/.claude/discord-bridge/sessions.json (the claude-home volume). The first turn creates the session with that ID; later turns resume it, also after a restart.
  • Turns: within one thread, turns run one at a time. A message sent while Claude is working is passed into the running turn.
  • Replies: Claude’s text is posted to the thread, split into 2000-character messages. Claude can attach files with its send_files tool.
  • Attachments you post are saved to /workspace/.discord-inbox/<thread id>/ and their paths are given to Claude.
  • Permissions: sessions use CLAUDE_PERMISSION_MODE (default auto). When a tool call needs approval, the bot posts Allow / Deny buttons in the thread. Only allowed users can press them; no answer within BRIDGE_APPROVAL_TIMEOUT_S means deny.
  • Settings: sessions load user, project and local settings, CLAUDE.md files and memory like the CLI does. The Discord plugin is switched off inside sessions.
  • Shared workspace: all sessions work in /workspace. Parallel threads editing the same files can conflict, so give separate tasks to separate repos or branches.
  • Users in DISCORD_CHANNEL_USERS (or DISCORD_ALLOWED_USERS when empty) and members with a role in DISCORD_ALLOWED_ROLES can start sessions, talk in session threads, use slash commands, react with 🛑/🔁 and press approval and rewind buttons. Everyone else is ignored. Giving someone the Dev role is enough; no user ID list to maintain.
  • The channel limits (DISCORD_CHANNELS) and the mention rule still apply to everyone.
  • Only threads the bridge created under a listened channel are sessions. Other threads are ignored.
  • DMs are ignored in bridge mode.

Each running session is a Claude Code process using roughly 250 MB of memory or more. With the default 4 GB container limit, keep BRIDGE_MAX_CONCURRENT at 3–4. Parallel sessions also use Claude quota or API credits at the same time.

Set BOT_MODE=plugin and restart to get the original single-session plugin setup. Both modes use the same bot, so never run both at once.