0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VS Code上のCodex拡張機能に承認待ちの通知を追加する

0
Last updated at Posted at 2026-11-07

VS Code で Codex 拡張機能を利用していると、承認待ちになっていても気付かず作業が停止していることが度々ありました。
そこで、Codex のフック機能を利用し、承認待ちになった際に Windows のトースト通知を表示させました。
追加の拡張機能の導入は不要で、2つのファイルを追加するだけで実現できます。

環境

  • Windows
  • VS Code: v1.145.2
  • Codex 拡張機能: v16,509,244

関連ファイル

  • 通知用PowerShellスクリプト
  • hooks.json

通知用PowerShellスクリプト

以下のスクリプトを配置してください。
scriptsフォルダがない場合は新規作成してください。別のPathに作成した場合は、hooks.json のスクリプトPathの指定を修正してください。

ファイルパス: %UserProfile%\.codex\scripts\codex-approval-notification.ps1

$ErrorActionPreference = 'Stop'

[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
$toastXml = New-Object Windows.Data.Xml.Dom.XmlDocument
$toastXml.LoadXml(@'
<toast>
    <visual>
        <binding template="ToastGeneric">
            <text>Codex:承認待ち</text>
            <text>実行の許可待ちです。承認要求を確認してください。</text>
        </binding>
    </visual>
</toast>
'@)
$toast = [Windows.UI.Notifications.ToastNotification]::new($toastXml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('Microsoft.VisualStudioCode').Show($toast)

hooks.json

ファイルが存在しない場合は新規作成してください。
以下の内容を記述して保存してください。

ファイルパス: %UserProfile%\.codex\hooks.json

{
  "hooks": {
    "PermissionRequest": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "statusMessage": "承認待ちをトースターで通知",
            "command": "powershell.exe -NoProfile -NonInteractive -WindowStyle Hidden -ExecutionPolicy Bypass -File \"${env:UserProfile}\\.codex\\scripts\\codex-approval-notification.ps1\"",
            "timeout": 5
          }
        ]
      }
    ]
  }
}

ファイル配置後

設定の読み込み

VS Code を再起動するか [Ctrl + Shift + P] でコマンドパレットを開き、「開発者: ウィンドウの再読み込み」(Developer: Reload Window) を実行してください。

権限の許可

前述のファイルの保存後、チャット入力欄にある⚓️マークをクリックしてください。
image.png

フックを許可する必要があるので、今回のフックを選択し許可してください。
image.png

実行結果

以下のような、承認待ちが発生するようなテキストを送ってください。

承認待ちになるような検証用の操作をしてください。

以下のようなトースター通知が出力された場合は設定成功となります。
image.png

トースター選択時に VS Code をアクティブにしたい

先に書いたスクリプトで最低限トースター通知を出せるようにしましたが、トースター通知を選択時に VS Code に戻りたい人もいると思います。
そのような方はトースター用のスクリプトを以下に書き換えてください。

ファイルパス: %UserProfile%\.codex\scripts\codex-approval-notification.ps1

$ErrorActionPreference = 'Stop'

[Console]::InputEncoding = [System.Text.UTF8Encoding]::new($false)
$hook = [Console]::In.ReadToEnd() | ConvertFrom-Json
$session_id = $hook.session_id
$uri = "vscode://openai.chatgpt/local/${session_id}"

[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null

$toastXml = New-Object Windows.Data.Xml.Dom.XmlDocument
$toastXml.LoadXml(@"
<toast activationType="protocol" launch="$uri">
    <visual>
        <binding template="ToastGeneric">
            <text>Codex:【承認要求】確認してください</text>
        </binding>
    </visual>
</toast>
"@)

$toast = [Windows.UI.Notifications.ToastNotification]::new($toastXml)
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('Microsoft.VisualStudioCode').Show($toast)

トースター選択時には VS Code 側で以下のポップアップが出力されます。
image.png
チェックを入れて「開く」を選択することで、トースター選択時に VS Code がアクティブなります。
この拡張機能による URI 利用の許諾を無効にするには [Ctrl + Shift + P] から "拡張機能: 承認された拡張 URI を管理します..." から openai.chatgpt のチェックボックスを外して保存してください。

なお、ここで利用している vscode://openai.chatgpt/local/ はCodex拡張機能の内部実装に依存する非公式の URI 利用であり、将来的に動作しなくなる可能性があります。
セキュリティ上の懸念などから、この URI を利用したくない場合にはその他の方法をご検討ください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?