Send phone notifications from Codex and OpenCode
6 min read
Published · Updated
Codex can run a program after a turn. OpenCode can subscribe to successful executions in a server plugin. Both can call the same command. Before installing either integration, test delivery from the machine that runs the agent:
pushbag notify 'Ready for review' --title 'Agent'
Use a Notifications key with access to your personal channel. Sign in to the mobile app with the same account and confirm the test arrives. The CLI reference covers installation and authentication.
Codex
Save this file as pushbag-notify.mjs in your Codex config directory. Codex appends an event as a single JSON argument. Reading only its type keeps the conversation out of the phone notification.
import { execFileSync } from "node:child_process";
const notification = JSON.parse(process.argv[2]);
const project = process.env.PUSHBAG_ALERT_PROJECT;
if (project && notification.type === "agent-turn-complete") {
const args = ["notify", project + ": ready to read", "--title", "Codex"];
if (process.env.PUSHBAG_REPORT_URL) args.push("--click", process.env.PUSHBAG_REPORT_URL);
execFileSync("pushbag", args, { stdio: "inherit" });
}
Add the top-level setting below to ~/.codex/config.toml, before any table headings. On macOS or Linux, this entry runs the script from the default config directory. The shell expands your home directory and passes the JSON argument through unchanged.
notify = ["sh", "-c", 'exec node "$HOME/.codex/pushbag-notify.mjs" "$1"', "pushbag-notify"]
Set PUSHBAG_ALERT_PROJECT=review in the launch environment. Start a new Codex session and ask it for a one-line reply. The alert means the turn ended. A subsequent turn produces a new alert. Codex external notifications
OpenCode
For the OpenCode server plugin API, save this as .opencode/plugins/pushbag/index.ts in the project. The server discovers local plugins in that directory. Subscribe to execution success so intermediate tool results do not send pings.
import { execFile } from "node:child_process";
import { Plugin } from "@opencode/plugin";
export default Plugin.define({
id: "pushbag",
async setup(ctx) {
const project = process.env.PUSHBAG_ALERT_PROJECT;
if (!project) return;
const args = ["notify", project + ": execution finished", "--title", "OpenCode"];
if (process.env.PUSHBAG_REPORT_URL) args.push("--click", process.env.PUSHBAG_REPORT_URL);
const controller = new AbortController();
const events = ctx.event.subscribe({
signal: controller.signal,
types: ["session.execution.succeeded"],
});
void (async () => {
for await (const event of events) {
execFile("pushbag", [...args, "--idempotency-key", event.id], (error) => {
if (error) console.error(error.message);
});
}
})().catch((error) => {
if (!controller.signal.aborted) console.error(error);
});
return () => controller.abort();
},
});
Start OpenCode with the project label set and let one request complete. The plugin runs on the server, so that process needs access to the CLI and its credentials. With a remote server, installing pushbag only on the laptop running the UI leaves the plugin without an executable. OpenCode plugin discovery · Server plugin events · Event schema
To route these alerts to a shared channel, add --channel and its ID to each command’s argument list and grant the key permission to publish there. See channel setup and agent notification workflows.
Opt in when you leave the terminal
Set PUSHBAG_ALERT_PROJECT in the environment of the agent process to enable the examples above. A short, recognizable label works well. A useful convention is to turn this on only for a session you’re about to leave running. Short interactive sessions then produce no phone traffic. This also gives you control over the name that appears on the lock screen. You can label a client project “review” without sending the directory path, branch, prompts, or tool results.
PUSHBAG_ALERT_PROJECT=docs codex
For OpenCode, set the same variable when launching the server that loads the plugin. If a service manager runs the server, put it in the service environment and restart that process. Setting it on a terminal client that connects to an already running server cannot change the server’s environment. The label applies to alerts from that server. Use a dedicated project server if several unrelated sessions share one instance and you need to distinguish their alerts.
For a session that should point back to a review document, set PUSHBAG_REPORT_URL as well. Use the numbered URL after publishing the report if the reviewer should open a particular result. Leave the variable unset when a tap on a notification should have no custom destination. The hook passes the URL to the CLI as its own argument. A space in the project name therefore doesn’t become another command-line option.
Test one boundary at a time
You can exercise the Codex adapter without paying for another model turn. Assuming you installed the script at the location above, run it once with a fabricated completion event. This publishes a real test message to your personal channel:
PUSHBAG_ALERT_PROJECT=smoke-test node "$HOME/.codex/pushbag-notify.mjs" \
'{"type":"agent-turn-complete"}'
The normal CLI confirmation has the form Sent to CHANNEL_ID (MESSAGE_ID). Match the title and project label on the phone, then run the same command with the label variable unset. That second run should exit quietly. Together these checks establish that the script reads the argument, your session can find the binary, and the opt-in gate actually suppresses publication. Next start Codex with the label set and submit a small request. If only the direct script test works, check that the top-level TOML entry points to the same file you tested.
In OpenCode, let a single request that uses several tools finish successfully. The expected alert count tracks successful executions, not individual tool calls. The subscription only asks for success events. A failed or interrupted execution may leave the phone quiet, so don’t use silence as a health check for an unattended worker. The event ID doubles as the publish idempotency key, so a repeated delivery of the same event and payload can reuse its receipt. The cleanup aborts the subscription when the plugin unloads. If identical messages arrive in pairs, check for copies of the integration in both the user configuration and the project configuration before changing channels.
Choose the message according to the evidence
An execution can succeed with an answer that asks you to choose between two designs. A completed Codex turn can accurately report that the build failed. Labels such as “ready to read” preserve that distinction. If you want the actual build result, let the build script send its own success or failure message after inspecting the exit code. For an uploaded artifact, the publisher can instead use pushbag upload report.html --notify --private with a Both key. It will link the version it just published, including when another version later becomes current.
If publication fails with This credential cannot publish to this channel., compare the agent’s key and channel with the pair used for the manual test. If the CLI succeeds while the phone stays silent, look for the message in the dashboard. A stored message points you toward the receiving account, subscription, or device settings. A missing message calls for checking the publisher, its process environment, and the event you chose. Codex setup · OpenCode setup · Developer notification service comparison
Frequently asked questions
What does a Codex completion alert certify?
It marks the end of a turn. Send a separate alert from the test command if you need confirmation that tests passed.
Where does the OpenCode plugin need the pushbag key?
Configure it for the server process running the plugin. A credential on a separate device running the UI is insufficient.
Can I leave both integrations installed while working quietly?
Yes. The examples below send only when PUSHBAG_ALERT_PROJECT is set for the process that runs them.