Skip to content

Instantly share code, notes, and snippets.

@dachi023
Last active July 29, 2025 04:57
Show Gist options
  • Select an option

  • Save dachi023/9b0c834925b10355c253e8fb3ce3ee15 to your computer and use it in GitHub Desktop.

Select an option

Save dachi023/9b0c834925b10355c253e8fb3ce3ee15 to your computer and use it in GitHub Desktop.
Claude CodeのStop hookで完了時のメッセージを読み上げる
#!/bin/bash
set -euo pipefail
input=$(cat)
[[ $(echo "$input" | jq -r '.stop_hook_active') == "true" ]] && exit 0
text=$(python3 -c "
import json
with open('$(echo "$input" | jq -r '.transcript_path')') as f:
for entry in reversed([json.loads(l) for l in f if l.strip()]):
if (msg := entry.get('message', {})).get('role') == 'assistant':
if texts := [c['text'] for c in msg.get('content', []) if c.get('type') == 'text']:
print(' '.join(texts)[:300]); break
" 2>/dev/null || echo "No message")
say "$text" && afplay /System/Library/Sounds/Glass.aiff 2>/dev/null &
{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "/Users/myuser/.claude/hooks/say-output.sh"
}
]
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment