claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

More configurable preferredNotifChannel (run an arbitrary script)

Open tylerkahn opened this issue 9 months ago • 12 comments

We should be able to have it run an arbitrary script/executable

claude config set --global preferredNotifChannel ~/.bin/notify.sh

tylerkahn avatar Feb 26 '25 00:02 tylerkahn

That's a cool idea. What were you thinking of making your script do?

bcherny avatar Feb 26 '25 01:02 bcherny

My most immediate use case would be something like this.

#!/usr/bin/env bash
/usr/bin/osascript -e 'display notification "Awaiting input" with title "Claude"'

If you passed in some info into the args, like if it's waiting for approval to do something or if it's completed a task (or if there was an error, ran out of context, etc) and maybe a (very short) summary of what it did, that could be put into the notification.

Honestly now that I think about it this could probably be an MCP server. But something simple like that would be sufficient.

tylerkahn avatar Feb 26 '25 01:02 tylerkahn

Just to give a bit more context, iTerm2 is a bit dated. Things like Ghostty are more cutting edge and it happens to lack support for visual bell.

tylerkahn avatar Feb 26 '25 01:02 tylerkahn

We don't yet have arbitrary scripts, but the new version does have better automatic notification behavior including support for Ghostty. Let us know if it works for you!

igorkofman avatar Mar 12 '25 20:03 igorkofman

The bell doesn’t work in my terminal, making this a bottleneck. Just like other configs, we should be able to set a notification script: claude config set -g path_to_notification_script /path/to/notify.sh.

Claude should call it when needed, with args for type (e.g., permission request, completion) and brief text. I’d use it for custom sounds and notify-send.

Roman- avatar Mar 15 '25 20:03 Roman-

What terminal are you using Roman? I hear you on the request for custom notification script - it makes sense, but we do want to have things work by default as broadly as possible as well.

igorkofman avatar Mar 16 '25 16:03 igorkofman

What terminal are you using Roman?

I'm on a heavily customized setup, so defaults don’t apply

Roman- avatar Mar 17 '25 07:03 Roman-

I'd love this feature too. Using terminator on arch.

hirowatari avatar May 16 '25 19:05 hirowatari

I use ghostty with tmux. Tmux eats the OSC sequence (iterm2 style notifications). While I could setup the bell to do a proper notification, I do not want all bell trigger to do a notification. Just claude code.

Being able to setup a custom script would unblock anyone with a custom setup to self serve.

Supporting allow-passthrough for tmux would be nice too. https://github.com/tmux/tmux/wiki/FAQ#what-is-the-passthrough-escape-sequence-and-how-do-i-use-it

JoeDupuis avatar May 26 '25 19:05 JoeDupuis

This would be such a win - I would also like notifications that are more elaborate (eg speak to me or ping my phone). Often I'm in another room (what a time to be alive! ;p) and want to know when my coding companion needs my help.

jkp avatar Jun 07 '25 08:06 jkp

In MacOS there is this brew package https://github.com/julienXX/terminal-notifier that can send a MacOS native notification. It would be awesome if I can trigger this script with a custom message based on the state of Claude Code. For example, the notification can be different in the case of ClaudeCode waiting for user input or when it is done vibe-coding.

AnhQuanTrl avatar Jun 19 '25 05:06 AnhQuanTrl

here is what i got working: create file

~/.claude/scripts/notify.sh
#!/bin/bash
osascript -e "display notification \"$2\" with title \"$1\" sound name \"Submarine\""
say "I'm done"

Patch cli.js make sure you back it up first this is for version 1.0.31

sed -i '' 's/hF5(A,B){return;/hF5(A,B){/g' /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js

This works for me, im investigating on how to get more notifications working e.g. when it ask a question with 3 answers you can choose from

UPDATE i got tired of looking at cli.js and asked claude to do this for me, seems to be working

# Add notification for KV function (general permissions)
sed -i '' '/z1("tengu_tool_use_show_permission_request",{messageID:A\.assistantMessage\.message\.id,toolName:A\.tool\.name})/a\
;(async()=>{try{if(ZA().customNotifyCommand)await hF5({title:"Claude Code",message:"Needs permission to proceed"},ZA().customNotifyCommand)}catch(e){}})()
' /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js

# Add notification for tH1 function (tool use permissions)  
sed -i '' '/z1("tengu_tool_use_show_permission_request",{messageID:A\.assistantMessage\.message\.id,toolName:A\.tool\.name,isMcp:A\.tool\.isMcp/a\
;(async()=>{try{if(ZA().customNotifyCommand)await hF5({title:"Claude Code",message:"Needs permission to proceed"},ZA().customNotifyCommand)}catch(e){}})()
' /opt/homebrew/lib/node_modules/@anthropic-ai/claude-code/cli.js

n0x00x avatar Jun 21 '25 17:06 n0x00x

This is already supported through Hooks now, so closing this issue now.

kushal-thakkar avatar Aug 22 '25 19:08 kushal-thakkar

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Aug 31 '25 14:08 github-actions[bot]