OmniscioGuidesA Slack notification hook
A Claude Code hook that posts to Slack when a turn ends
A long agent run ends somewhere you are not looking. Slack is where a team already is, so the useful message is not “a hook fired” but what Claude said it did, in the channel the work belongs to.
Checked against Anthropic’s Claude Code hooks documentation on November 25, 2026. By the Omniscio team. Updated .
The hook, complete
Four things, in this order.
- Create the webhook. In Slack, go to Apps, add the Incoming WebHooks app, choose the channel and post the URL it gives you. Many workspaces require an admin to approve an app, so you may need to ask for that first.
- Save the URL as the only line of
.claude/slack-webhook, and add that path to.gitignore. - Save the script below to
.claude/hooks/slack-notify.shand runchmod +xon it. - Add the block that follows it to
.claude/settings.json, merging it into an existing"hooks"object rather than replacing the file.
The script needs jq and curl. curl is already on macOS and Linux and ships with Git for Windows; install jq with brew install jq on macOS, sudo apt-get install jq on Debian and Ubuntu, or winget install jqlang.jq on Windows.
#!/bin/bash
set -u
url=$(cat "${CLAUDE_PROJECT_DIR:-.}/.claude/slack-webhook" 2>/dev/null | tr -d '\r\n')
[ -z "$url" ] && exit 0
input=$(cat)
msg=$(jq -r '.last_assistant_message // ""' <<<"$input" | head -c 600)
project=$(basename "$(jq -r '.cwd // "session"' <<<"$input")")
payload=$(jq -nc --arg p "$project" --arg m "$msg" \
'{text: ("*Claude Code finished* in `" + $p + "`\n" + $m)}')
curl -sS -f -m 10 -X POST -H 'Content-type: application/json' \
--data "$payload" "$url" >/dev/null 2>&1 || true
exit 0And this goes in .claude/settings.json:
{
"hooks": {
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/slack-notify.sh",
"timeout": 20,
"async": true
}
]
}
]
}
}There is no matcher key, and that is not an omission: Stop has no matcher support, so a matcher added here would be silently ignored.
The problem it solves
When several agents run at once, the question stops being “is Claude finished” and becomes “which one is finished, and what did it do”. A desktop notification answers neither for anyone but you, and it does not survive a screen you are not at.
A channel answers both if the message carries the reply. The Stop event hands you exactly that: last_assistant_message is the text of Claude’s final response, put there so a notification hook does not have to read the transcript file, which Anthropic warns is not guaranteed to hold the final message at Stop time.
What each line does
| Part | Job |
|---|---|
"Stop" | The event: it runs when the main Claude Code agent has finished responding. |
"async": true | Runs the handler in the background without blocking Claude. Available on type: "command" handlers only. |
cat .claude/slack-webhook | Reads the URL from a file rather than from the settings, so the credential never lands in a file you commit. |
tr -d '\r\n' | Removes a carriage return, which a webhook file saved on Windows ends every line with. A URL ending in \r is rejected by curl as malformed; the trailing newline itself is already gone, because the value is read with $(...). |
last_assistant_message | The text of Claude’s final response, which is the reason this event is the right one for a notification. |
head -c 600 | Caps the message. A full summary pasted into a channel is hard to read, and Slack has limits of its own. |
jq -nc --arg | Builds the JSON payload with proper escaping, so a message containing a quote or a newline cannot break it. |
{"text": ...} | The one field a Slack incoming webhook needs. This is why the http handler type does not fit: it posts the event’s JSON unchanged. |
curl -f | Fails on an HTTP error instead of reporting success. Without it curl exits 0 on a 400, and the hook looks like it worked. |
timeout: 20 | Seconds. The default for a command hook is ten minutes, and an async hook is not subject to it at all — it is here as intent, not as a guarantee. |
Stop, or Notification
They answer different questions, and using the wrong one is why people find the hook noisy.
| Event | When it fires | What it gives you |
|---|---|---|
Stop | When the main agent has finished responding. Not on a user interrupt; API errors raise StopFailure instead. | last_assistant_message, stop_hook_active, and the background tasks and session crons still in flight. |
Notification | On the notification types you match: permission_prompt after about six idle seconds, idle_prompt about 60 seconds after a reply and only when nothing else is running. | message, an optional title, and notification_type. |
A Stop hook posts after every completed turn, which in a long session is a lot of messages. A Notification hook is the quieter choice when you only care about the moments Claude is waiting on you. Running both is reasonable: Slack gets the summary at the end of the work, and a mention when Claude is stuck.
How to test that it fires
- Post to the channel by hand first. Before any hook is involved, prove the webhook works:
curl -sS -f -X POST -H 'Content-type: application/json' \ --data '{"text":"hello from the test"}' "$(tr -d '\r\n' < .claude/slack-webhook)"; echo $?Anything other than 0 and a message in the channel means the URL is wrong or revoked, and no hook will fix that. - Run the script with sample JSON. This separates a broken script from a hook that never ran:
echo '{"cwd":"/path/to/project","last_assistant_message":"Done: renamed the helper and updated its callers."}' \ | .claude/hooks/slack-notify.sh; echo $?The channel should show the message. The exit code tells you nothing here, because the script ends with|| trueand always exits 0. - Check the hook is registered. Type
/hooks: a read-only browser that lists each hook under its event and says where it comes from. - Let a real turn end. Ask Claude something small and wait for it to finish. The message should arrive shortly after the turn ends; an async hook posts while the session carries on.
- Read the debug log when it does not. Run
/debugmid-session, or restart withclaude --debug-file /tmp/claude.log(on Windows use a path such asC:\Temp\claude.log).
What makes this hook fail
1. The webhook URL is in a file you committed
The URL is the credential. A hook block in .claude/settings.json is meant to be shared, so putting the URL in the command or the settings puts it in git, where it stays after you delete it. Keep it in its own gitignored file, or read it from an environment variable your shell already sets, and rotate the webhook if it has ever been committed.
2. The payload is not the shape Slack wants
Slack’s incoming webhook expects an object with a text field. Anything else is refused. The script ends with || true, so a rejection shows up only as the silence in the channel — which is why the first test step posts with a bare curl -f, where a failure is still an error you can see.
3. The turn did not end the way you think
Stop does not run if the stoppage came from a user interrupt, and an API error raises StopFailure instead. If the channel goes quiet exactly when a run failed, that is the event to add, not a bug in this hook.
4. jq is missing, so the payload is empty
The script builds the JSON with jq, so without it payload is empty and curl sends a request with no body: Slack answers with an error, nothing appears in the channel, and the script still exits 0. That is the cost of never blocking a session on a notification. jq’s own message does reach stderr, so the debug log has it; if you would rather the run fail visibly, delete the trailing || true.
5. The message is too long, or the history is stale
last_assistant_message is the final reply, not the whole turn, and a reply that is a table or a code block will render badly in Slack. Cap it and lead with a sentence, which is what the head -c 600 in the script does. Reading the transcript file instead is worse: Anthropic notes it is written asynchronously and may not hold the final message when the hook runs.
Where Omniscio fits
A Slack hook is a project choice, and the project is the right place for it: commit .claude/settings.json and everyone on the team hears about the same sessions. Omniscio takes the other angle. Its Hooks panel composes the hooks it ships, and any you define, into every session it spawns, keeping them in its own database rather than writing into your global Claude configuration, with a global switch and per-project overrides.
The hooks examples hub collects the other recipes, the Claude Code hooks guide covers every event, and the hooks builder assembles a block like this one. Omniscio runs on Windows, macOS and Linux, and the pricing page covers the plans.
How this page was written
Everything about the Stop and Notification events, their input fields, matcher support, async, exit codes and the transcript warning was read from Anthropic’s Claude Code hooks reference on November 25, 2026, quoted from the page as it reads today. The Slack payload shape is Slack’s documented incoming-webhook format, read the same day.
The script was run on this machine against a local endpoint that accepted the POST, and the payload it sent was read back. No live Claude Code session was configured to run it and no real Slack workspace was posted to, so the page describes the documented behaviour of the block and the measured behaviour of the script.
Sources
- Anthropic’s Hooks reference, for
Stop,StopFailure,Notification, their input fields, matcher support, handler types andasync, read November 25, 2026. - Slack’s incoming webhooks documentation, for the
{"text": ...}payload, read November 25, 2026.
Common questions
How do I get Claude Code to notify Slack when it finishes?
Register a Stop hook that posts to a Slack incoming webhook. Stop runs when the main agent has finished responding, and it receives last_assistant_message, the text of Claude’s final reply, so the script does not have to parse the transcript.
Can I use the http hook type for Slack?
Not directly. An http hook sends the event’s own JSON as the POST body, and a Slack incoming webhook expects an object with a text field. Use a command hook that builds the payload with curl, or point the http hook at something of your own that reshapes it.
Does it run on every turn?
Yes. Stop runs whenever the main agent finishes responding, which in a long session is many times. If you only want the moments that need you, a Notification hook with permission_prompt or idle_prompt is the quieter choice.
Why did nothing post when the run failed?
Stop does not run when the stoppage came from a user interrupt, and an API error raises StopFailure instead. Add a block on that event if you want to hear about failures too.
Where should the webhook URL live?
Anywhere git does not follow. A single-line file under .claude/ added to .gitignore is the simplest, and it keeps the URL out of the settings block everyone commits. An environment variable works too, so long as the environment Claude Code starts in has it.
Know when any session finishes
Omniscio runs your Claude Code sessions side by side and composes the hooks it ships, and any you define, into every one it spawns, so a notification rule does not depend on which folder you opened.
The features page covers what else it does, pricing covers the plans, and you can download it for Windows, macOS or Linux.