To send Codex CLI notifications to Telegram, Slack or Discord, create a bot or an incoming webhook in that app, then add a Codex hook that posts a short message to it with curl. A Stop hook covers "Codex has finished", and a PermissionRequest hook covers "Codex wants approval". Telegram needs a bot token and your chat ID; Slack and Discord need only a webhook URL. Trust the hooks once with /hooks. The same script works on Mac and Linux, and a short PowerShell version covers Windows.
01Get a token or webhook
Telegram
- In Telegram, message @BotFather, send
/newbotand follow the steps. It gives you a bot token like123456:ABC.... - Send any message to your new bot.
- Open
https://api.telegram.org/bot<TOKEN>/getUpdatesin a browser and find"chat":{"id":...}. That number is your chat ID.
Slack
- Create a Slack app for your workspace, turn on Incoming Webhooks, and add a webhook to a channel (a private channel or a DM with yourself works well).
- Copy the webhook URL (
https://hooks.slack.com/services/...).
Discord
- In a server you control, open the channel's settings > Integrations > Webhooks > New Webhook.
- Copy the webhook URL (
https://discord.com/api/webhooks/...).
Treat all of these like passwords. Anyone with the URL or token can post to your channel.
02One script for all three
Save as ~/.codex/hooks/chat-notify.sh, fill in the service you use, and chmod +x it:
#!/bin/sh
# Posts a Codex alert to Telegram, Slack or Discord. Prints nothing.
SERVICE="slack" # telegram | slack | discord
TELEGRAM_TOKEN="" TELEGRAM_CHAT="" # for telegram
WEBHOOK_URL="" # for slack or discord
input=$(cat)
text=$(printf '%s' "$input" | python3 -c '
import json, os, sys
e = json.load(sys.stdin)
project = os.path.basename(e.get("cwd", "")) or "Codex"
if e.get("hook_event_name") == "Stop":
msg = (e.get("last_assistant_message") or "Turn complete")[:300]
print(f"Codex finished in {project}: {msg}")
elif e.get("hook_event_name") == "PermissionRequest":
cmd = ((e.get("tool_input") or {}).get("command") or "an action")[:300]
print(f"Codex wants approval in {project}: {cmd}")
')
[ -z "$text" ] && exit 0
json=$(printf '%s' "$text" | python3 -c 'import json,sys; print(json.dumps(sys.stdin.read()))')
case "$SERVICE" in
telegram) curl -s -o /dev/null --max-time 10 \
--data-urlencode "chat_id=$TELEGRAM_CHAT" --data-urlencode "text=$text" \
"https://api.telegram.org/bot$TELEGRAM_TOKEN/sendMessage" ;;
slack) curl -s -o /dev/null --max-time 10 -H 'Content-Type: application/json' \
-d "{\"text\": $json}" "$WEBHOOK_URL" ;;
discord) curl -s -o /dev/null --max-time 10 -H 'Content-Type: application/json' \
-d "{\"content\": $json}" "$WEBHOOK_URL" ;;
esac
exit 0
Then in ~/.codex/hooks.json:
{
"hooks": {
"Stop": [
{ "hooks": [ { "type": "command", "command": "~/.codex/hooks/chat-notify.sh", "timeout": 15 } ] }
],
"PermissionRequest": [
{ "hooks": [ { "type": "command", "command": "~/.codex/hooks/chat-notify.sh", "timeout": 15 } ] }
]
}
}
Start codex, run /hooks and trust both entries.
Two Codex-specific details:
- Print nothing. Codex reads what a
Stophook prints, and plain text is invalid output. That's why everycurlhas-s -o /dev/null. - Decide nothing. The
PermissionRequesthook prints no decision, so Codex still shows the approval prompt in the terminal. The message just tells you it's there.
If the network is slow, add "async": true to each handler so Codex doesn't wait for the post.
03Windows
The same idea in PowerShell, with Slack shown (swap the body for @{ content = $text } for Discord). Save as %USERPROFILE%\.codex\hooks\chat-notify.ps1:
$webhook = "https://hooks.slack.com/services/..."
$e = [Console]::In.ReadToEnd() | ConvertFrom-Json
$project = Split-Path -Leaf $e.cwd
if ($e.hook_event_name -eq "Stop") { $text = "Codex finished in ${project}: $($e.last_assistant_message)" }
elseif ($e.hook_event_name -eq "PermissionRequest") { $text = "Codex wants approval in ${project}: $($e.tool_input.command)" }
else { exit 0 }
$body = @{ text = $text } | ConvertTo-Json
Invoke-RestMethod -Method Post -Uri $webhook -ContentType 'application/json' -Body $body | Out-Null
Use "command": "powershell -NoProfile -ExecutionPolicy Bypass -File C:\\Users\\you\\.codex\\hooks\\chat-notify.ps1" in both hooks.
04Mind what you post
The message includes the project name, Codex's last message and the command it wants to run. In a shared Slack or Discord channel, everyone in it sees that. Use a private channel or a direct message, and shorten the message if your work is sensitive.
05One-way only
A chat message tells you Codex is waiting; it can't carry your answer back into the session. Building that (a bot that receives your reply and a hook that waits for it) is possible but a project of its own; approving from your phone explains what's involved. Notifier for Codex is a ready-made two-way option: a free codex-notifier tool for Mac, Windows and Linux plus an iPhone or Android app where you approve, reject, answer and follow up. It's independent and not affiliated with OpenAI.
06FAQ
Which of the three is quickest to set up?
Discord and Slack: one webhook URL and you're done. Telegram needs a bot and a chat ID, but its mobile notifications are very reliable.
Can I use Codex's notify setting instead of hooks?
For "finished" only, yes. notify passes the turn's JSON as an argument rather than on stdin, so adapt the script to read sys.argv[-1]. See the notify guide.
Why does nothing arrive?
Check the hook is trusted in /hooks, then run the script by hand: echo '{"hook_event_name":"Stop","cwd":"/tmp/demo","last_assistant_message":"test"}' | ~/.codex/hooks/chat-notify.sh. Remove -s -o /dev/null from the curl line while testing to see the service's reply.
Can I send alerts to a team channel?
Yes, but think about what the messages reveal. Commands and file paths from your projects will be visible to everyone in the channel.