codex - 💡(How to fix) Fix File write operations do not fire PreToolUse/PostToolUse hooks [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#17794Fetched 2026-04-15 06:28:07
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×4commented ×1unlabeled ×1

File write operations (e.g. apply_patch) do not trigger PreToolUse or PostToolUse hooks. File read operations correctly fire both hooks.

Error Message

Read (hooks fire correctly):

› read 1.json
• Running UserPromptSubmit hook
• Running PreToolUse hook      ← fires
  PreToolUse hook (completed)
• Running PostToolUse hook     ← fires
  PostToolUse hook (completed)
• Running Stop hook

Root Cause

File write operations (e.g. apply_patch) do not trigger PreToolUse or PostToolUse hooks. File read operations correctly fire both hooks.

Fix Action

Fix / Workaround

File write operations (e.g. apply_patch) do not trigger PreToolUse or PostToolUse hooks. File read operations correctly fire both hooks.

When asked which tool was used: Codex confirmed it used functions.apply_patch.

PreToolUse and PostToolUse hooks should fire for all tool calls, including apply_patch and any other tool that writes to the filesystem.

Code Example

› read 1.json
Running UserPromptSubmit hook
Running PreToolUse hook      ← fires
  PreToolUse hook (completed)
Running PostToolUse hook     ← fires
  PostToolUse hook (completed)
Running Stop hook

---

› write 1.json
Running UserPromptSubmit hook
Added 1.json (+10 -0)
Running Stop hook            ← no PreToolUse, no PostToolUse
RAW_BUFFERClick to expand / collapse

Summary

File write operations (e.g. apply_patch) do not trigger PreToolUse or PostToolUse hooks. File read operations correctly fire both hooks.

Observed behavior

Read (hooks fire correctly):

› read 1.json
• Running UserPromptSubmit hook
• Running PreToolUse hook      ← fires
  PreToolUse hook (completed)
• Running PostToolUse hook     ← fires
  PostToolUse hook (completed)
• Running Stop hook

Write (hooks do not fire):

› write 1.json
• Running UserPromptSubmit hook
• Added 1.json (+10 -0)
• Running Stop hook            ← no PreToolUse, no PostToolUse

When asked which tool was used: Codex confirmed it used functions.apply_patch.

Impact

This is critical for integrations that rely on PreToolUse hooks to enforce policies before file modifications (e.g. access control, skill enforcement, HITL approval flows). Reads being observable while writes are not is the inverse of what security tooling needs — writes are higher risk.

Expected behavior

PreToolUse and PostToolUse hooks should fire for all tool calls, including apply_patch and any other tool that writes to the filesystem.

Environment

  • Tool: functions.apply_patch
  • Hook events affected: PreToolUse, PostToolUse
  • Hook events working: UserPromptSubmit, Stop

extent analysis

TL;DR

The PreToolUse and PostToolUse hooks may need to be explicitly configured or updated to support file write operations like apply_patch.

Guidance

  • Review the hook configuration to ensure it includes support for write operations, specifically apply_patch.
  • Verify that the apply_patch function is correctly registered as a tool that triggers PreToolUse and PostToolUse hooks.
  • Check the documentation for any specific requirements or limitations for hook events related to file write operations.
  • Test the hooks with other write operations to determine if the issue is specific to apply_patch or a broader problem.

Example

No code example is provided due to the lack of specific implementation details in the issue.

Notes

The issue seems to be related to the specific implementation of the apply_patch function and its interaction with the hook system. Without more information about the underlying code and configuration, it's difficult to provide a more detailed solution.

Recommendation

Apply a workaround by manually triggering the PreToolUse and PostToolUse hooks before and after the apply_patch function is called, until a more permanent fix can be implemented. This will ensure that the necessary policies and checks are enforced for file write operations.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

PreToolUse and PostToolUse hooks should fire for all tool calls, including apply_patch and any other tool that writes to the filesystem.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING