## 関連Issue [[フック (GitHub Copilot)|フック]]で[[cmux]]への通知処理を書ければシンプルだったが、ユーザーレベルスコープには対応されていなそうなので断念。リポジトリレベルだけだった。 以下のissueが解消すれば、実現できるかも。 <div class="link-card-v2"> <div class="link-card-v2-site"> <img class="link-card-v2-site-icon" src="https://github.githubassets.com/favicons/favicon.svg" /> <span class="link-card-v2-site-name">GitHub</span> </div> <div class="link-card-v2-title"> Feature Request: User Level Hooks · Issue #1067 · github/copilot-cli </div> <div class="link-card-v2-content"> Describe the feature or problem you'd like to solve No response Proposed solution Based on the following user re ... </div> <img class="link-card-v2-image" src="https://opengraph.githubassets.com/f5761d088cffb3ac7b9bcbc17ebb0d56fabd59aa66ea166c19a145a20b70ecc7/github/copilot-cli/issues/1067" /> <a href="https://github.com/github/copilot-cli/issues/1067"></a> </div> ## 回避策として[[プラグイン (GitHub Copilot CLI)|プラグイン]]をつくる [[Codex CLI]]からは[[プラグイン (GitHub Copilot CLI)|プラグイン]]の作成を推奨されたので作ってみた。 <div class="link-card-v2"> <div class="link-card-v2-site"> <img class="link-card-v2-site-icon" src="https://github.githubassets.com/favicons/favicon.svg" /> <span class="link-card-v2-site-name">GitHub</span> </div> <div class="link-card-v2-title"> GitHub - tadashi-aikawa/copilot-plugin-notify: Copilot CLI hook events are emitted as OSC 777 notification escape sequences; listeners such as cmux can consume these notifications. </div> <div class="link-card-v2-content"> Copilot CLI hook events are emitted as OSC 777 notification escape sequences; listeners such as cmux can consume ... </div> <img class="link-card-v2-image" src="https://opengraph.githubassets.com/075add3b68367bccb400f4dc59cafe1388070d78bc7f58180b0e614bcd7c7644/tadashi-aikawa/copilot-plugin-notify" /> <a href="https://github.com/tadashi-aikawa/copilot-plugin-notify"></a> </div> ## インストールする ```console copilot plugin install tadashi-aikawa/copilot-plugin-notify ``` ローカル開発中は `tadashi-aikawa` 配下でこうだ。 ```console copilot plugin install ./copilot-plugin-notify ``` 確認する。 ```console $ copilot plugin list Installed plugins: • copilot-plugin-notify (v0.1.0) ``` インストールはここにされている。 ```console $ tree ~/.copilot/installed-plugins/_direct/copilot-plugin-notify  /Users/tadashi-aikawa/.copilot/installed-plugins/_direct/copilot-plugin-notify ├──  hooks.json ├──  LICENSE ├──  plugin.json ├── 󰂺 README.md └──  scripts └──  notify.sh ``` ## 苦労したポイント ### [[cmuxコマンドが不安定]] `cmux notify` が使えなくなってしまう事象がたびたび発生していた。おそらく `cmux` コマンドのバグだと思うが、[[OSC 777 シーケンス]]を使った方が安定するので、[[通知 (cmux)|通知]]のサンプルコードを使う。 ```bash notify() { local title="$1" local body="$2" # >dev/tty に出力しないとcopilotにインターセプトされて端末まで伝わらないので注意 printf '\e]777;notify;%s;%s\a' "$title" "$body" >/dev/tty } ``` `cmux` コマンドが不安定 & [[OSC 777 シーケンス]]の出力先の罠に結構ハマった。。 <div class="link-card-v2"> <div class="link-card-v2-site"> <img class="link-card-v2-site-icon" src="https://publish-01.obsidian.md/access/35d05cd1bf5cc500e11cc8ba57daaf88/favicon-64.png" /> <span class="link-card-v2-site-name">Minerva</span> </div> <div class="link-card-v2-title"> 📝GitHub Copilot CLIのプラグインでOSC9やOSC777シーケンスをprintfしても通知されない </div> <div class="link-card-v2-content">GitHub Copilot CLIプラグインでOSC 9やOSC 777シーケンスをprintfした通知が、標準出力がCopilot側で消費されたためGhosttyやcmuxに届かずOS通知されなかった事象である。通知シーケンスを/dev/ttyに出力したところ、端末が直接認識して通知された。</div> <img class="link-card-v2-image" src="https://publish-01.obsidian.md/access/35d05cd1bf5cc500e11cc8ba57daaf88/Notes/attachments/troubleshooting.webp" /> <a data-href="📝GitHub Copilot CLIのプラグインでOSC9やOSC777シーケンスをprintfしても通知されない" class="internal-link"></a> </div> %%[[📝GitHub Copilot CLIのプラグインでOSC9やOSC777シーケンスをprintfしても通知されない]]%% ### 許可を求める通知がうまくできない `preToolUse` はツール実行前にすべて通知されるため、**ユーザーの許可が必要かどうか**は考慮してくれない。そのため、ツールを使用するたびに通知がくる。一方、`preToolUse` をオフにしてしまうと権限確認されたケースを拾うことができない。 これは流石に無視できないのでガッツリ調べてもらった。 > [!left-bubble] ![[chappy.webp]] > • 2026年2月22日時点で調べた結論として、この要望には明確に需要があります。 > 特に「グローバル hooks」「入力待ち通知(完了通知含む)」「--resume/--continue 時の hooks 信頼性」は、複数ユーザーが同じ方向で要望・不具合報告しています。 > > 需要の根拠(GitHub Issues) > > 1. #1067 User Level Hooks(open, 2026-01-22作成, comments 2, reactions 7) > 2. #1157 Global Hooks + UserPromptSubmit/Stop/Notification(open, 2026-01-28作成) > 3. #1128 awaitingUserInput hook 追加要望(open, 2026-01-26作成, comments 1, reactions 9) > 4. #1084 --continue で hooks が発火しない(open, 2026-01-23作成, reactions 3) > 5. #1503 --resume で hooks がロードされない(open, 2026-02-17作成) > 6. #991 sessionStart/sessionEnd が対話モードでプロンプト単位発火(open, 2026-01-15作成) > 7. #971 通知用 hooks 要望(closed/completed, 2026-01-16クローズ) > 8. #1184 サウンド設定要望(closed/completed, 2026-02-05クローズ) > > 公式/実装側の現状 > > 1. 公式ドキュメントは hooks 設定とイベントを案内しているが、ユーザー共通(global/user-level)設定は未整備。 > 2. ローカル changelog.md では、hooks機能は短期間で拡張されている。 > changelog.md:326(preToolUse), changelog.md:248(agentStop/subagentStop), changelog.md:232(session lifecycle hooks) > > 要点 > > 1. 既存ユーザー要望は「あなたのユースケース」とほぼ一致しています。 > 2. ただし現状はイベント粒度と読み込み経路(global, resume/continue)に未解決点が残っており、誤通知や通知欠落が起きやすい状態です。 > > 参照URL > > - https://github.com/github/copilot-cli/issues/1067 > - https://github.com/github/copilot-cli/issues/1157 > - https://github.com/github/copilot-cli/issues/1128 > - https://github.com/github/copilot-cli/issues/1084 > - https://github.com/github/copilot-cli/issues/1503 > - https://github.com/github/copilot-cli/issues/991 > - https://github.com/github/copilot-cli/issues/971 > - https://github.com/github/copilot-cli/issues/1184 > - https://docs.github.com/en/copilot/reference/hooks-configuration > - https://docs.github.com/en/copilot/concepts/agents/coding-agent/about-hooks > - https://docs.github.com/en/copilot/tutorials/copilot-cli-hooks > - changelog.md:232 > - changelog.md:248 > - changelog.md:326 このissueがそれにあたりそうだけど、進展する様子はなさそう。 <div class="link-card-v2"> <div class="link-card-v2-site"> <img class="link-card-v2-site-icon" src="https://github.githubassets.com/favicons/favicon.svg" /> <span class="link-card-v2-site-name">GitHub</span> </div> <div class="link-card-v2-title"> Feature Request: Add awaitingUserInput hook type · Issue #1128 · github/copilot-cli </div> <div class="link-card-v2-content"> Describe the feature or problem you'd like to solve Currently, the userPromptSubmitted hook fires after the user ... </div> <img class="link-card-v2-image" src="https://opengraph.githubassets.com/07126e7cffc9cbad137a3fdae7862b419b7ae37f2fba27e9b6fe18f6356b95f1/github/copilot-cli/issues/1128" /> <a href="https://github.com/github/copilot-cli/issues/1128"></a> </div> **自前で実装していくことになった。** ### ユーザーへの確認 ```json { "sessionId": "af75adf4-7aeb-4485-9134-cef342fce386", "timestamp": 1771811561078, "cwd": "/Users/tadashi-aikawa/git/github.com/tadashi-aikawa/copilot-plugin-cmux-notify", "toolName": "ask_user", "toolArgs": "{\"question\":\"スクリプト名と環境変数名の扱いを確認します:\\n「スクリプトを scripts/notify.sh にリネームし、環境変数 CMUX_NOTIFY_* を COPILOT_NOTIFY_*(または PLUGIN_NOTIFY_*)に移行しつつ、既存の CMUX_* は互換で維持する」方針で進めてよいですか?\",\"choices\":[\"Rename script and env vars (recommended): リネームと env var 移行を行う\",\"Only update docs and plugin.json: スクリプト/環境変数は現状維持\"],\"allow_freeform\":false}" } ``` > [!attention] > permissionsチェックとは別 ### プランのレビュー ```json { "sessionId": "af75adf4-7aeb-4485-9134-cef342fce386", "timestamp": 1771811926184, "cwd": "/Users/tadashi-aikawa/git/github.com/tadashi-aikawa/copilot-plugin-cmux-notify", "toolName": "exit_plan_mode", "toolArgs": "{\"summary\":\"- README、plugin.json、hooks.json、scripts を copilot-plugin-notify に合わせて更新\\n- scripts/cmux-notify.sh を scripts/notify.sh にリネームし、環境変数を COPILOT_NOTIFY_* に変更(CMUX_NOTIFY_* のフォールバックは行わない)\\n- plugin.json.name を copilot-plugin-notify に変更\\n- ローカルで OSC 777 の出力とフック動作を検証\"}" } ``` ### ファイル編集 ```json { "sessionId": "8c137963-02e6-4318-a83e-62ea37f61485", "timestamp": 1771818716536, "cwd": "/Users/tadashi-aikawa/tmp/ai-sandbox", "toolName": "edit", "toolArgs": "{\"path\":\"/Users/tadashi-aikawa/tmp/ai-sandbox/hoge.sh\",\"old_str\":\"notify \\\"aa\\\" \\\"bb cc ddd: bash\\\"\",\"new_str\":\"notify \\\"aa\\\" \\\"bb cc ddd: bash\\\"\\nexit 0\"}" } ``` ### 特定のコマンドは許可(通知しない) [[GitHub Copilot CLI]]で[[特定のコマンドを許可 (GitHub Copilot CLI)|特定のコマンドを許可]]するにはCLIオプションしかない。なので、[[zshrc|.zshrc]]などで設定する。今回は `lot` コマンド。 ```bash lot() { copilot \ --banner \ --allow-tool 'write' \ --allow-tool "shell(git:*)" \ --deny-tool "shell(git push)" \ --deny-tool "shell(git reset:*)" \ --deny-tool "shell(git clean:*)" \ --allow-tool "shell(gh:*)" \ --deny-tool "shell(gh api)" \ --deny-tool "shell(gh pr merge)" \ --allow-tool "shell(curl)" \ --allow-url "api.github.com" \ --allow-url "raw.githubusercontent.com" \ --allow-url "github.com" \ --allow-url "minerva.mamansoft.net" \ "$@" } ``` これだけだと、許可されたコマンド......つまり通知が不要なコマンドでも通知がきてしまう。上記の設定にあわせて環境変数を設定し、[[🦉copilot-plugin-notify]]がそれを解釈して通知を抑制する。 ```bash # `lot()` の場合 export COPILOT_NOTIFY_ALLOW_TOOL_RULES="write,shell(git:*),shell(gh:*),shell(curl)" export COPILOT_NOTIFY_DENY_TOOL_RULES="shell(git push),shell(git reset:*),shell(git clean:*),shell(gh api),shell(gh pr merge)" export COPILOT_NOTIFY_ALLOW_URLS="api.github.com,raw.githubusercontent.com,github.com,minerva.mamansoft.net" ```