跳到正文
DEV Community· Shashank Chakraborty·· 2 小時前AI 評分64

如何用 agent-bridge 透過 Discord 回覆 Claude Code 的待答問題

Claude is stuck on a question. Answer it from Discord.

AI 導讀

agent-bridge 會透過 Discord 私訊通知用戶 Claude Code、Codex 或其他 CLI 智能體正在等待,並將手機回覆輸入本機 tmux 即時終端工作階段。

正文

Claude Code will happily work for twenty minutes and then stop on a question you could have answered in one line. The terminal is on a desk. You are not.

A few people have already solved the "I'm not at the keyboard" half of this. jagafarm shows that a tmux session is what keeps the agent alive when the laptop lid closes, and that attaching from a phone is the whole trick: Stop losing Claude Code sessions: a tmux primer for mobile devs. coa00 and yuu1ch13 go further and put Allow and Deny on the lock screen, by blocking inside a PermissionRequest hook until ntfy.sh comes back with a decision: a mobile approval system and Approve Claude Code permission requests from your phone. pederaa uses the Notification hook so you at least find out the agent is waiting: How to know when a Claude Code agent needs your approval.

Those are the right shapes for yes and no. They are a bad shape for the message Claude actually sends, which is often three questions with descriptions, or a sentence you still have to type.

agent-bridge takes the tmux half from the primer and the notification half from the hook posts, and then does something they deliberately do not: it types your reply into the live pane. The hook does not wait, and it does not return allow.

Code

GitHub logo Shashank0701-byte / agent-bridge

Get a Discord DM when your coding agent is blocked, reply from your phone, and have it typed straight back into the session. Works with Claude Code, Codex, or anything with a CLI.

agent-bridge

CI Install License: MIT

Get a Discord DM when your coding agent (Claude Code, Codex, etc.) is blocked waiting on you, reply from your phone, and have that reply typed straight back into the session -- no need to be at your keyboard.

It types what you send into a live terminal on your machine, so one Discord account is all that stands between a stranger and your shell. Two minutes on Security before you install is time well spent.

How it works

The whole thing hinges on one idea: run the agent inside tmux, then treat the terminal itself as the integration point instead of hooking into each tool's internals differently. That's what makes it work the same way for Claude Code, Codex, or anything else you run in a terminal.

 you AFK                         tmux session "myproject"
   |                                    |
   |  Discord DM  <----- notify.sh <----+  Notification hook fires
   |                                       (Claude Code is

…

What shows up on the phone

A decision is the whole card, not a buzz that says "something needs you."

A Discord DM titled PromptWall needs a decision, with three numbered questions and an option under each

You answer with the codes it printed. 1:1 2:1 3:1 means the first option of each question. The bridge turns those numbers back into the labels Claude is waiting for, then confirms what it sent.

The same DM, with the reply 1:1 2:1 3:1 and the bot answering sent to PromptWall, answered the pending question

Two projects are two tmux sessions. Each message is tagged with the one it came from. A reply to PromptWall never lands in CodePulse.

PromptWall and CodePulse both asking for permission, each answered with yes, each confirmed separately

A permission prompt is the same idea in one line. pick 2 presses the digit. Ordinary prose is typed in as if you were sitting there.

Why it types, instead of approving inside the hook

A PermissionRequest hook can return allow or deny and Claude continues. That is what the ntfy projects do, and it is the right tool when the only decision is a button.

It does not cover the rest of what the pane is showing. A question card wants the option labels. A plan you disagree with wants a sentence. A follow-up wants whatever you would have typed. The terminal already accepts all of those. So the bridge treats the terminal as the API.

The path is short. Claude's Notification hook fires because the agent is blocked. A Discord bot, allowlisted to one user id, DMs you. Your reply is loaded into a tmux paste buffer and pasted into the named session, then Enter. send-keys is the wrong primitive here: tmux parses that text as arguments, so a reply that starts with - is a flag, and quotes get eaten. A paste buffer is just bytes.

The hook itself returns immediately. PreToolUse runs before the question card is drawn. If the hook sat there waiting for your phone, the card would never appear, and you could not answer it from the keyboard either.

The bug that makes "just paste it" unsafe

Claude's modal selectors treat a paste as a choice. Measured on Claude Code 2.1.241, pasting the word hello into an open selector selected the highlighted option, with no Enter. On a plan-approval dialog, that is the agent starting to edit files because you sent a sentence.

So a reply never goes in while that widget is up. The bridge sends Escape, checks that the selector footer is gone, and only then pastes. If the widget is still there, nothing is typed and Discord says so. Refusing is recoverable. Approving a plan by accident is not.

pick is only the digits 1 through 9. The first digit of 12 would already have chosen something.

Try it

You need three things: a paid Claude plan (the free claude.ai tier does not include Claude Code), a Discord bot that only you can DM, and tmux. On Windows the typing half runs inside WSL. Without WSL you can still get the notifications, and you cannot type back into the pane.

On macOS, Linux, or a WSL distro you already have:


bash
curl -fsSL https://gitlab.com/shashankchakraborty712005/agent-bridge/-/raw/main/scripts/get.sh | sh

來源:DEV Community · dev.to