Claude Code Hooks in Practice: Automatic Task Completion Notifications
💬 hippo: These are my real-world notes from setting up Claude Code Hooks. Getting from “it works” to “it’s actually reliable” involved plenty of pitfalls—hopefully this saves you from hitting the same ones.
1. Why Automate Notifications?
Sound familiar?
- You kick off a long-running task in Claude Code (say, rewriting 28 blog posts)
- You step away to do something else…
- When you check back, the job finished ages ago—you just never knew
Wouldn’t it be great if it notified you automatically?
That is exactly what Hooks are for.
2. Final Result
Desktop Notification

Displays a summary of the task and the total tool call count.
Feishu Notification

Formatted as an interactive card showing:
- Completion timestamp
- Tool call count
- Task summary
3. Implementation
3.1 Create the Notification Scripts
Desktop notification script .claude/hooks/notify.sh:
1 |
|
Feishu notification script .claude/hooks/feishu-notify.sh:
1 |
|
3.2 Configure the Hooks
Add the following to .claude/settings.json:
1 | { |
3.3 Get a Feishu Webhook URL
- Open your Feishu group chat and click Settings (top right) → Bots
- Click Add Bot → select Custom Bot
- Copy the generated Webhook URL
4. Pitfalls Encountered
Pitfall 1: Stop vs SessionEnd
I started with SessionEnd, which caused an unexpected problem:
- Notifications only fired when the session ended (on exit or
/clear) - Not after each completed task
The fix: Use the Stop event, which fires whenever Claude finishes a response.
| Event | Trigger Timing | Use Case |
|---|---|---|
Stop |
When Claude finishes responding | ✅ Task completion notifications |
SessionEnd |
When the session exits | Cleanup tasks (1.5s timeout limit) |
Pitfall 2: The Stop Event Has No reason Field
The official docs show a reason field on SessionEnd, but Stop does not include one.
At first I tried reading reason from the Stop payload and kept getting unknown.
The fix: The actual Stop event payload looks like this:
1 | { |
Extract the task summary from transcript_path instead of looking for reason.
Pitfall 3: type: "user" Entries Aren’t All User Prompts
Records with type: "user" in the transcript JSONL include:
- Actual user prompts
- Tool outputs (
tool_result) - IDE-injected messages (such as
<ide_opened_file>)
The fix: Filter out non-prompt entries:
1 | grep '"type":"user"' "$TRANSCRIPT_PATH" | \ |
Pitfall 4: Feishu Interactive Card Schema
Feishu custom bots support two message formats:
text: plain text—simple, but bare-bonesinteractive: rich card—clean layout, but stricter schema
My first card payload failed to deliver because fields inside elements must be an array of objects.
Correct schema:
1 | { |
Pitfall 5: Hook Changes Require a Session Restart
This is an intentional security mechanism in Claude Code:
- A snapshot of your Hook config is captured at session startup
- The running session executes against that snapshot
- External edits do not take effect immediately
The fix: Restart your session after modifying Hook config, or run /hooks to verify the active setup.
5. Debugging Tips
Test the Script Manually
1 | # Simulate Stop event input |
Verify the Feishu Webhook
1 | export FEISHU_WEBHOOK_URL="https://open.feishu.cn/open-apis/bot/v2/hook/your-webhook-token" |
A response of {"StatusCode":0} confirms the webhook is working.
6. Key Takeaways
Three lessons stood out from building this:
- Hooks are deterministic: Claude can “forget” instructions written in
CLAUDE.md, whereas a Hook runs 100% of the time - Read the official docs closely: The difference between
StopandSessionEnd, along with their exact payload schemas, is documented right there - Debug incrementally: The transcript format is complex—verify the output of each step one at a time
Related Posts
- Official Docs Breakdown: Hooks Reference - A complete walkthrough of the official Hooks documentation
- Getting the Most Out of Claude Code: My Best Practices - Original field-tested workflow patterns
Last updated: 2026-03-25





