A lightweight tool for sending Slack notifications when Claude Code requires human intervention or when tasks are completed.
- 🔔 Automatic Notifications: Automatically send Slack messages when Claude Code needs approval or tasks complete
- 🎨 Rich Messages: Create beautiful notifications using Slack Block Kit
- ⚙️ Flexible Configuration: Support for multiple event types and custom triggers
- 🔒 Secure: Manage sensitive information through environment variables
- 📬 Dual Mode Support: Send via Webhook or Direct Message (DM)
- 📦 Minimal Dependencies: Webhook mode uses only Python stdlib, DM mode requires
slack-sdk
| File | Description |
|---|---|
claude_slack_notifier.py |
Main notification script |
hooks_minimal.json |
Minimal configuration example (recommended) |
hooks_example.json |
Complete configuration example |
Send notifications as direct messages to your Slack account.
- Visit https://api.slack.com/apps and create a new app
- Go to OAuth & Permissions and add these scopes:
chat:writeusers:read
- Install the app to your workspace
- Copy the Bot User OAuth Token (starts with
xoxb-) - Get your Member ID:
# Visit Slack in browser, click your profile -> Copy member ID # Or use: https://api.slack.com/methods/users.list/test
pip install slack-sdkexport SLACK_CLAUDE_CODE_BOT_TOKEN="xoxb-your-bot-token-here"
export SLACK_MEMBER_ID="U01234567"Add to ~/.bashrc or ~/.zshrc to make it permanent.
Edit ~/.claude/settings.json:
{
"hooks": {
"Notification": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python3 ~/bin/claude_slack_notifier.py --event-type notification --mode dm",
"timeout": 10
}
]
}
],
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python3 ~/bin/claude_slack_notifier.py --event-type stop --mode dm",
"timeout": 10
}
]
}
]
}
}Run in Claude Code:
/hooks
Then review and approve the configuration.
Send notifications to a Slack channel via Incoming Webhooks.
- Visit https://api.slack.com/apps
- Create a new app and enable Incoming Webhooks
- Copy the generated Webhook URL
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"Add to ~/.bashrc or ~/.zshrc to make it permanent.
Edit ~/.claude/settings.json:
{
"hooks": {
"Notification": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python3 ~/bin/claude_slack_notifier.py --event-type notification --mode webhook",
"timeout": 10
}
]
}
],
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python3 ~/bin/claude_slack_notifier.py --event-type stop --mode webhook",
"timeout": 10
}
]
}
]
}
}Run in Claude Code:
/hooks
Then review and approve the configuration.
After installation, Claude Code will automatically send notifications in the following situations:
-
When Approval is Needed (Notification event)
- Example: When executing dangerous commands
- Example: When modifying important files
-
When Tasks Complete (Stop event)
- At the end of any conversation
- Review results and decide next steps
# Test DM mode
echo '{"notification":"Test message"}' | \
python3 ~/bin/claude_slack_notifier.py \
--event-type notification \
--mode dm \
--message "This is a test message"
# Test Webhook mode
echo '{"notification":"Test message"}' | \
python3 ~/bin/claude_slack_notifier.py \
--event-type notification \
--mode webhook \
--message "This is a test message"Notify only on file modifications:
{
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "python3 ~/bin/claude_slack_notifier.py --event-type post_tool_use"
}
]
}
]
}| Event | Trigger | Recommended |
|---|---|---|
Notification |
Claude Code requests user approval | ✅ |
Stop |
Task completion | ✅ |
UserPromptSubmit |
User submits new task | Optional |
PreToolUse |
Before tool execution | Optional |
PostToolUse |
After tool execution | Optional |
PreCompaction |
Before context compression | Optional |
SessionStart |
Session begins | Optional |
🔔 Claude Code Needs Your Action
Time: 2025-10-11 10:30:15
Event Type: notification
Notification:
About to execute command 'rm -rf /tmp/*', confirmation needed
✅ Claude Code Task Completed
Time: 2025-10-11 10:35:42
Event Type: stop
Session ID: abc123-def456
Create .claude/settings.json in project directory:
{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "python3 ~/bin/claude_slack_notifier.py --event-type stop --webhook-url 'https://hooks.slack.com/services/PROJECT/SPECIFIC/URL'"
}
]
}
]
}
}Modify the create_notification_blocks function in the script to customize message layout.
Use environment variables or script logic to filter certain notifications:
# Only send notifications during work hours
if [ $(date +%H) -ge 9 ] && [ $(date +%H) -le 18 ]; then
python3 ~/bin/claude_slack_notifier.py --event-type stop
fiFor DM Mode:
-
Verify environment variables:
echo $SLACK_CLAUDE_CODE_BOT_TOKEN | head -c 20 echo $SLACK_MEMBER_ID
-
Verify slack-sdk is installed:
python3 -c "import slack_sdk; print('OK')" -
Test the script:
echo '{}' | python3 ~/bin/claude_slack_notifier.py --event-type stop --mode dm --message "Test"
For Webhook Mode:
-
Verify Webhook URL:
echo $SLACK_WEBHOOK_URL
-
Test the script:
echo '{}' | python3 ~/bin/claude_slack_notifier.py --event-type stop --mode webhook --message "Test"
Common Issues:
-
Check if Claude Code loaded the configuration:
/hooks -
View logs:
ls -la ~/.claude/logs/
Keep only critical events (Notification and Stop), or use matcher to filter specific tools.
Ensure you're using Python 3.6+:
python3 --versionInstall the Slack SDK:
pip install slack-sdk
# or
pip3 install slack-sdk- Claude Code Official Documentation
- Slack API Documentation
- Slack Webhooks Documentation
- Slack Block Kit Builder
- slack-sdk Documentation
Issues and Pull Requests are welcome!
MIT License
Built on Claude Code's hooks system and Slack's Incoming Webhooks API.