Codex Hooks Tutorial for Beginners: Automate Your Workflow with Audio Notifications

Codex Hooks Tutorial for Beginners: Automate Your Workflow with Audio Notifications

Published: 2026-05-09
Author: DP
Views: 0
Category: Video
Support Content
## A. 相关脚本 > 1.1 .codex/config.toml ``` [features] codex_hooks = true ``` > 1.2 .codex/hooks.json ``` { "hooks": { "UserPromptSubmit": [ { "hooks": [ { "type": "command", "command": "\".codex/scripts/play-codex-audio.macos.sh\" \"start\" \".codex/audio/task-start.mp3\"", "timeout": 5 } ] } ], "PermissionRequest": [ { "matcher": "*", "hooks": [ { "type": "command", "command": "\".codex/scripts/play-codex-audio.macos.sh\" \"permission\" \".codex/audio/permission-needed.mp3\"", "timeout": 5 } ] } ], "Stop": [ { "hooks": [ { "type": "command", "command": "\".codex/scripts/play-codex-audio.macos.sh\" \"stop\" \".codex/audio/task-complete.mp3\"", "timeout": 5 } ] } ] } } ``` > 2.1 .codex/scripts/play-codex-audio.macos.sh ``` #!/usr/bin/env bash set -u event_name="${1:-}" audio_file="${2:-}" case "$event_name" in stop) hook_input="$(cat)" has_final_message="$( printf '%s' "$hook_input" | python3 -c 'import json,sys; data=json.load(sys.stdin); print("yes" if data.get("last_assistant_message") else "no")' 2>/dev/null )" if [ "$has_final_message" != "yes" ]; then exit 0 fi ;; esac if [ -z "$audio_file" ] || [ ! -f "$audio_file" ]; then exit 0 fi if command -v afplay >/dev/null 2>&1; then nohup afplay "$audio_file" >/dev/null 2>&1 & fi exit 0 ``` > 2.2 .codex/scripts/play-codex-audio.windows.ps1 ``` param( [string]$EventName, [string]$AudioFile ) if ($EventName -eq "stop") { $hookInput = [Console]::In.ReadToEnd() $hasFinalMessage = $false if (-not [string]::IsNullOrWhiteSpace($hookInput)) { try { $data = $hookInput | ConvertFrom-Json $hasFinalMessage = -not [string]::IsNullOrWhiteSpace([string]$data.last_assistant_message) } catch { $hasFinalMessage = $false } } if (-not $hasFinalMessage) { exit 0 } } if ([string]::IsNullOrWhiteSpace($AudioFile) -or -not (Test-Path -LiteralPath $AudioFile)) { exit 0 } try { Add-Type -AssemblyName PresentationCore $player = New-Object System.Windows.Media.MediaPlayer $player.Open([Uri]::new((Resolve-Path -LiteralPath $AudioFile).Path)) $player.Play() Start-Sleep -Milliseconds 1200 } catch { } exit 0 ``` > 2.3 .codex/scripts/play-codex-audio.linux.sh ``` #!/usr/bin/env bash set -u event_name="${1:-}" audio_file="${2:-}" case "$event_name" in stop) hook_input="$(cat)" has_final_message="$( printf '%s' "$hook_input" | python3 -c 'import json,sys; data=json.load(sys.stdin); print("yes" if data.get("last_assistant_message") else "no")' 2>/dev/null )" if [ "$has_final_message" != "yes" ]; then exit 0 fi ;; esac if [ -z "$audio_file" ] || [ ! -f "$audio_file" ]; then exit 0 fi if command -v paplay >/dev/null 2>&1; then nohup paplay "$audio_file" >/dev/null 2>&1 & elif command -v mpg123 >/dev/null 2>&1; then nohup mpg123 -q "$audio_file" >/dev/null 2>&1 & elif command -v ffplay >/dev/null 2>&1; then nohup ffplay -nodisp -autoexit "$audio_file" >/dev/null 2>&1 & fi exit 0 ``` ## B. 音频文件 > 3.1 通知音频文件下载 ``` https://pan.quark.cn/s/07c47e87f6e7 ``` ## C. links > 4.1 Codex Hooks 官方文档 ``` https://developers.openai.com/codex/hooks ```
Summary Content
# Codex Hooks Tutorial for Beginners: Automate Your Workflow with Audio Notifications ## Say Goodbye to Idle Waiting: Make Your Codex Tasks Speak to You Have you ever started a long-running Codex task, expecting it to take an hour, only to return later and find it's been stuck waiting for a permission prompt for the last 50 minutes? This video introduces an elegant solution to this common productivity killer: **Codex Hooks**. This tutorial provides a simple yet practical guide on how to use Codex Hooks to play audio notifications at **key lifecycle moments** of a task—such as when a task starts, requires user permission, or completes. This way, you get real-time feedback on your task's status without being glued to your screen. ### What You Will Learn * **Core Concepts of Codex Hooks**: Understand what Hooks are and their lifecycle, including key events like `session_start`, `user_prompt_submit`, `permission_request`, and `stop`. * **Step-by-Step Hook Configuration**: We will walk you through creating a `. codex` directory in your project and setting up the `config` and `hooks. json` files to define your automated actions. * **Writing and Integrating Custom Scripts**: Learn to write a simple script (with support for macOS, Windows, and Linux) to play audio and link it to the corresponding Hooks. * **Activating and Testing Your Hooks**: Discover the crucial step of reviewing and "trusting" your configured Hooks within the Codex UI to enable them, followed by a live test involving a file deletion command to see it all in action. ### More Than Just Sound While this video uses audio playback as a beginner-friendly example, it's just scratching the surface. The true power of Codex Hooks lies in its **automation** potential. Once you grasp the fundamentals, you can implement far more advanced functionalities: - **Advanced Notification Systems**: Push notifications to your phone or team collaboration tools like Slack. - **Automated Logging**: Automatically record detailed logs at each stage of a task. - **Code Quality Checks**: Run linters or code formatters automatically after code generation. - **Git Auto-Commit**: Automatically commit changes to your version control system upon successful task completion. ### Project-Level vs. Global Hooks The video also clarifies the difference between **project-level Hooks** and **global (user-level) Hooks**. You'll learn how to apply configurations to a single project or set them up as global rules that affect all your projects, providing flexibility for your automated workflows. If you're looking to boost your development efficiency and create a more intelligent and seamless AI collaboration experience, this Codex Hooks tutorial is a must-watch!
Related Contents
Recommended
Synology SFTP Tutorial: Secure Remote Data Transfer
Synology SFTP Tutorial: Secure...
05:12 | 170

Beginner's tutorial on how to configure and use SF...

Google AI IDE Antigravity: Deep Dive into the 2026 Mass Ban Wave - Causes & Strategies
Google AI IDE Antigravity: Dee...
00:00 | 444

On Feb 12, 2026, Google's Antigravity AI IDE initi...

Antigravity Quota Slashed: 1500 to 250? Is Pro Just a "Trial" Now?
Antigravity Quota Slashed: 150...
00:00 | 636

This video provides an in-depth test of the latest...

Nginx Proxy Manager on Synology 7.2 Docker Guide
Nginx Proxy Manager on Synolog...
14:11 | 392

docker-based Nginx graphical management tool, Ngin...