This post was generated by an AI agent from an article the account owner published in Japanese on note. The wording is not human-written.
In one project, clearing a morning backlog of business emails in Thunderbird meant reading each message, drafting a polite reply, and hitting send, one at a time. To cut that down, a custom "AI Reply All" button was built directly into Thunderbird, wired up to Claude Code CLI so it runs entirely within an existing subscription, with no metered API usage at all.
Environment
- Thunderbird 128.0 or later
- Windows 11
- Node.js v18 or later
- Claude Code CLI already installed
The Claude API (pay-as-you-go) is not used anywhere in this setup. Everything goes through Claude Code CLI, so a subscription plan alone covers it.
Overall design
The flow looks like this:
Thunderbird extension → Claude Bridge Server → Claude Code CLI → AI response
The key piece is the Bridge Server sitting in the middle. A Thunderbird extension cannot call a CLI tool directly, so a local HTTP server is placed in between to act as the go-between. This Bridge Server was built generically on purpose, so other tools besides Thunderbird can call it too once it's installed on a machine.
Building the Claude Bridge Server
The server is a small Node.js HTTP server listening on localhost:3456. It takes whatever prompt it receives and forwards it to the Claude CLI.
The core trick is claude -p, which invokes the CLI in non-interactive mode: the prompt is piped into standard input, and the result comes back on standard output.
It only exposes two endpoints:
-
GET /api/status— checks whether the server is running -
POST /api/chat— sends a prompt and gets the response back
Installation is just running install.bat with administrator rights, and it can also be configured to auto-start when Windows boots.
Building the Thunderbird extension
The extension is a standard WebExtension in MailExtension form. Its manifest.json defines two buttons:
-
message_display_action— appears in the header when a message is open -
browser_action— appears in the toolbar over the message list
Either one triggers the same AI reply flow.
When the button is clicked, the extension:
- Checks that the Bridge Server is running
- Reads the currently displayed (or selected) message
- Builds a prompt from the subject, sender, and body
- Sends that prompt to Claude through the Bridge Server
- Opens a "Reply All" compose window
- Inserts the generated text at the top of the body
Step 6 is the part that needed care:
// Open the reply window (signature and quote get set automatically)
const composeTab = await messenger.compose.beginReply(
message.id, 'replyToAll'
);
// Get the default content, then insert the AI reply above it
const details = await messenger.compose.getComposeDetails(composeTab.id);
await messenger.compose.setComposeDetails(composeTab.id, {
body: aiReply.replace(/\n/g, '<br>') + '<br><br>' + details.body
});
This inserts only the AI-generated reply at the top, leaving the signature and quoted text untouched. The system prompt used for generation can also be customized from a settings screen.
Packaging as an xpi
Packaging the Thunderbird extension is just zipping up the required files and renaming the archive with an .xpi extension. It loads through Thunderbird's "Install Add-on From File" option, with no need to register it on the official add-on store.
Pitfall: the SVG icon never showed up
An attempt was made to show a custom icon in the toolbar. Both SVG and PNG versions were tried, and neither displayed — Thunderbird's toolbar icons turned out to have a number of constraints. The icon was dropped in the end, leaving a text-only label. Working mattered more than looking good.
Pitfall: the signature and quote disappeared
The first attempt passed the AI-generated body directly into beginReply. That wiped out the default signature and quoted text entirely. The fix was the two-step approach described above: open the reply window empty first, fetch its contents, then prepend the AI text. With that order, both the signature and the quote stay intact.
Result
A single click now produces a reply-all draft. Generation takes a few seconds, during which the button switches to a "Generating AI reply..." state, so the wait is visible rather than silent. Once it's done, the normal compose window opens for review, edits, and sending.
The overall feel shifted from "read → think → write" to "read → check → send." Making the Bridge Server generic also paid off, since the same mechanism can be reused by other tools beyond Thunderbird going forward.
Summary
- Implemented an "AI Reply All" button inside a Thunderbird extension
- Claude Code CLI is called through a local Bridge Server
- Runs entirely within a subscription, with no metered API billing
- Signature and quoted text are preserved when inserting the AI reply
- The Bridge Server can be reused by other tools
- The system prompt is customizable to adjust reply style
Follow @kmrb_works here on DEV for more field notes from real development work. Also on X and note, mostly in Japanese.
Top comments (0)