Getting notified in Zellij when Claude Code is done

I usually run multiple Claude Code instances in my terminal using Zellij together with ygg. Knowing when the agent is done when many are running at the same time isn't the easiest of things.

Since Claude Code has a bunch of hooks for different events, I just hooked up the stop hook to ring the terminal bell, but only if I am not in that active terminal.

Add this to your ~/.claude/settings.json:

  "hooks": {
    "Stop": [{
      "hooks": [{
        "type": "command",
        "command": "jq -e '.stop_hook_active == true' >/dev/null 2>&1 && exit 0; zellij action list-clients 2>/dev/null | awk 'NR>1 {print $2}' | grep -qx \"terminal_${ZELLIJ_PANE_ID}\" && exit 0; tty=$(ps -p $PPID -o tty= | tr -d ' '); printf '\\a' > \"/dev/$tty\" 2>/dev/null; exit
   0"
      }]
    }]
  }

Now you will get a notification for the Zellij tab where Claude is done working.