Notifications

cmux supporte les notifications bureau, permettant aux agents IA et aux scripts de vous alerter quand ils ont besoin d'attention.

Cycle de vie

  1. Reçue : la notification apparaît dans le panneau, l'alerte bureau se déclenche (si non supprimée)
  2. Non lue : badge affiché sur l'onglet de l'espace de travail
  3. Lue : effacée quand vous consultez cet espace de travail
  4. Effacée : supprimée du panneau

Suppression

Les alertes bureau sont supprimées quand :

  • La fenêtre cmux est active
  • L'espace de travail spécifique qui envoie la notification est actif
  • Le panneau de notifications est ouvert

Panneau de notifications

Appuyez sur ⌘⇧I pour ouvrir le panneau de notifications. Cliquez sur une notification pour aller à cet espace de travail. Appuyez sur ⌘⇧U pour aller directement à l'espace de travail avec la notification non lue la plus récente.

Commande personnalisée

Exécutez une commande shell à chaque fois qu'une notification est planifiée. Définissez-la dans Réglages > App > Commande de notification. La commande s'exécute via /bin/sh -c avec ces variables d'environnement :

VariableDescription
CMUX_NOTIFICATION_TITLETitre de la notification (nom de l'espace de travail ou nom de l'app)
CMUX_NOTIFICATION_SUBTITLESous-titre de la notification
CMUX_NOTIFICATION_BODYTexte du corps de la notification
Examples
# Text-to-speech
say "$CMUX_NOTIFICATION_TITLE"

# Custom sound file
afplay /path/to/sound.aiff

# Log to file
echo "$CMUX_NOTIFICATION_TITLE: $CMUX_NOTIFICATION_BODY" >> ~/notifications.log

La commande s'exécute indépendamment du sélecteur de son système. Définissez le sélecteur sur « Aucun » pour utiliser uniquement la commande personnalisée, ou gardez les deux pour un son système plus une action personnalisée.

Envoyer des notifications

CLI

cmux notify --title "Task Complete" --body "Your build finished"
cmux notify --title "Claude Code" --subtitle "Waiting" --body "Agent needs input"

OSC 777 (simple)

Le protocole RXVT utilise un format fixe avec titre et corps :

printf '\e]777;notify;My Title;Message body here\a'
Shell function
notify_osc777() {
    local title="$1"
    local body="$2"
    printf '\e]777;notify;%s;%s\a' "$title" "$body"
}

notify_osc777 "Build Complete" "All tests passed"

OSC 99 (riche)

Le protocole Kitty supporte les sous-titres et les IDs de notification :

# Format: ESC ] 99 ; <params> ; <payload> ESC \

# Simple notification
printf '\e]99;i=1;e=1;d=0:Hello World\e\\'

# With title, subtitle, and body
printf '\e]99;i=1;e=1;d=0;p=title:Build Complete\e\\'
printf '\e]99;i=1;e=1;d=0;p=subtitle:Project X\e\\'
printf '\e]99;i=1;e=1;d=1;p=body:All tests passed\e\\'
FonctionnalitéOSC 99OSC 777
Titre + corpsOuiOui
Sous-titreOuiNon
ID de notificationOuiNon
ComplexitéPlus élevéePlus basse
Utilisez OSC 777 pour les notifications simples. Utilisez OSC 99 quand vous avez besoin de sous-titres ou d'IDs de notification. Utilisez le CLI (cmux notify) pour l'intégration la plus simple.

Hooks Claude Code

cmux s'intègre avec Claude Code via des hooks pour vous notifier quand les tâches sont terminées.

1. Créer le script de hook

~/.claude/hooks/cmux-notify.sh
#!/bin/bash
# Skip if not in cmux
[ -S /tmp/cmux.sock ] || exit 0

EVENT=$(cat)
EVENT_TYPE=$(echo "$EVENT" | jq -r '.hook_event_name // "unknown"')
TOOL=$(echo "$EVENT" | jq -r '.tool_name // ""')

case "$EVENT_TYPE" in
    "Stop")
        cmux notify --title "Claude Code" --body "Session complete"
        ;;
    "PostToolUse")
        [ "$TOOL" = "Task" ] && cmux notify --title "Claude Code" --body "Agent finished"
        ;;
esac
chmod +x ~/.claude/hooks/cmux-notify.sh

2. Configurer Claude Code

~/.claude/settings.json
{
  "hooks": {
    "Stop": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/cmux-notify.sh"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Task",
        "hooks": [
          {
            "type": "command",
            "command": "~/.claude/hooks/cmux-notify.sh"
          }
        ]
      }
    ]
  }
}

Redémarrez Claude Code pour appliquer les hooks.

GitHub Copilot CLI

Copilot CLI prend en charge les hooks qui exécutent des commandes shell lors d'événements du cycle de vie comme la soumission de prompts, l'arrêt de l'agent et les erreurs.

~/.copilot/config.json
{
  "hooks": {
    "userPromptSubmitted": [
      {
        "type": "command",
        "bash": "if command -v cmux &>/dev/null; then cmux set-status copilot_cli Running; fi",
        "timeoutSec": 3
      }
    ],
    "agentStop": [
      {
        "type": "command",
        "bash": "if command -v cmux &>/dev/null; then cmux notify --title 'Copilot CLI' --body 'Done'; cmux set-status copilot_cli Idle; fi",
        "timeoutSec": 5
      }
    ],
    "errorOccurred": [
      {
        "type": "command",
        "bash": "if command -v cmux &>/dev/null; then cmux notify --title 'Copilot CLI' --subtitle 'Error' --body 'An error occurred'; cmux set-status copilot_cli Error; fi",
        "timeoutSec": 5
      }
    ],
    "sessionEnd": [
      {
        "type": "command",
        "bash": "if command -v cmux &>/dev/null; then cmux clear-status copilot_cli; fi",
        "timeoutSec": 3
      }
    ]
  }
}

Pour les hooks au niveau du dépôt, créez un fichier .github/hooks/notify.json avec la même structure :

.github/hooks/notify.json
{
  "version": 1,
  "hooks": {
    "userPromptSubmitted": [ ... ],
    "agentStop": [ ... ]
  }
}

Exemples d'intégration

Notifier après une longue commande

~/.zshrc
# Add to your shell config
notify-after() {
  "$@"
  local exit_code=$?
  if [ $exit_code -eq 0 ]; then
    cmux notify --title "✓ Command Complete" --body "$1"
  else
    cmux notify --title "✗ Command Failed" --body "$1 (exit $exit_code)"
  fi
  return $exit_code
}

# Usage: notify-after npm run build

Python

python
import sys

def notify(title: str, body: str):
    """Send OSC 777 notification."""
    sys.stdout.write(f'\x1b]777;notify;{title};{body}\x07')
    sys.stdout.flush()

notify("Script Complete", "Processing finished")

Node.js

node
function notify(title, body) {
  process.stdout.write(`\x1b]777;notify;${title};${body}\x07`);
}

notify('Build Done', 'webpack finished');

Passthrough tmux

Si vous utilisez tmux dans cmux, activez le passthrough :

.tmux.conf
set -g allow-passthrough on
printf '\ePtmux;\e\e]777;notify;Title;Body\a\e\\'