GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — codex-cli-best-practice/best-practice/codex-hooks.md at main · ucsahinn/codex-cli-best-practice

Expand file tree

/

codex-hooks.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
74 lines (55 loc) · 2.23 KB
/

codex-hooks.md

Copy path

File metadata and controls

74 lines (55 loc) · 2.23 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Best Practice: Hooks

Hooks let Codex run reviewed commands at lifecycle points such as session start, prompt submission, tool use, and turn stop. Use them for deterministic guardrails, logging, context injection, and lightweight checks.

Back to Codex CLI Operator Handbook Codex

Status

Hooks are an active Codex feature. Keep the exact event list and output schema refreshed from official docs before release.

Feature Flag

Use the current feature key:

[features]
hooks = true

Discovery Locations

Location Scope
.codex/hooks.json Project-shared hooks
~/.codex/hooks.json Personal hooks

Project hooks and user hooks can both run. Keep shared hooks small, reviewed, and deterministic.

Supported Events

Event Use
SessionStart Add startup context or run a light initialization check
UserPromptSubmit Validate or enrich a submitted prompt
PreToolUse Inspect a pending tool call before execution
PostToolUse Inspect a completed tool call result
Stop Add final checks or request continuation

Windows Commands

Use commandWindows when the POSIX command is not portable:

{
  "type": "command",
  "command": "python3 .codex/hooks/scripts/hooks.py --hook SessionStart",
  "commandWindows": "python .codex/hooks/scripts/hooks.py --hook SessionStart",
  "timeout": 10
}

Safety Rules

  • Treat hooks as guardrails, not a complete security boundary.
  • Keep hook timeouts short.
  • Parse JSON from stdin defensively.
  • Keep local overrides in .codex/hooks/config/*.local.json.
  • Ignore generated hook logs.
  • Do not put tokens or auth material in hook config.

Anti-Patterns

Anti-pattern Fix
Relying on hooks as the only protection Combine sandbox, approvals, review, and secret scanning
Committing local hook overrides Use ignored *.local.json files
Writing long-running hook commands Keep hooks fast and bounded
Logging full sensitive payloads Redact or disable logging
Using only POSIX commands Add commandWindows when sharing with Windows users
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.