Skip to content

feat: support preTool and postTool hooks to codex#860

Open
zchee wants to merge 1 commit intoentireio:mainfrom
zchee:codex-hooks-0.118.0
Open

feat: support preTool and postTool hooks to codex#860
zchee wants to merge 1 commit intoentireio:mainfrom
zchee:codex-hooks-0.118.0

Conversation

@zchee
Copy link
Copy Markdown

@zchee zchee commented Apr 7, 2026

Codex 0.118.0 has supported the PreToolUse and PostToolUse hooks.

These hooks are not required for "Entire" (such as the Gemini hook), however, they have been implemented as stubs for future additional hooks to the Codex.

Copilot AI review requested due to automatic review settings April 7, 2026 03:02
Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Codex hook surface area for the newly-supported PreToolUse / PostToolUse events (Codex CLI 0.118.0+), wiring them into the Codex agent’s hook installation and lifecycle parsing as no-op/pass-through hooks for future expansion.

Changes:

  • Add PostToolUse to Codex hook config types and supported hook names.
  • Treat PreToolUse and PostToolUse as pass-through lifecycle hooks (no lifecycle event emitted).
  • Install/uninstall/manage PreToolUse and PostToolUse hook entries in .codex/hooks.json, and update related tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/entire/cli/agent/codex/types.go Extends Codex hooks.json schema types to include PostToolUse.
cmd/entire/cli/agent/codex/lifecycle.go Registers post-tool-use hook name and treats pre/post tool hooks as pass-through.
cmd/entire/cli/agent/codex/lifecycle_test.go Updates lifecycle tests to cover both pass-through hooks.
cmd/entire/cli/agent/codex/hooks.go Updates hook install/uninstall + detection to include Pre/Post tool hooks.
cmd/entire/cli/agent/codex/hooks_test.go Updates install-count expectations for newly installed hooks.
Comments suppressed due to low confidence (1)

cmd/entire/cli/agent/codex/hooks_test.go:37

  • These tests now expect 5 hooks to be installed, but they still only assert that session-start/user-prompt-submit/stop commands appear in hooks.json. Add assertions for the new PreToolUse/PostToolUse hook commands as well so the test will catch mismatched verb names or missing hook entries.
	ag := &CodexAgent{}
	count, err := ag.InstallHooks(context.Background(), false, false)
	require.NoError(t, err)
	require.Equal(t, 5, count) // SessionStart, UserPromptSubmit, Stop, PreToolUse, PostToolUse

	// Verify hooks.json was created in the repo
	hooksPath := filepath.Join(tempDir, ".codex", HooksFileName)
	data, err := os.ReadFile(hooksPath)
	require.NoError(t, err)
	require.Contains(t, string(data), "entire hooks codex session-start")
	require.Contains(t, string(data), "entire hooks codex user-prompt-submit")
	require.Contains(t, string(data), "entire hooks codex stop")

Codex 0.118.0 has supported the `PreToolUse` and `PostToolUse` hooks.
These hooks are not required for entire, however, they have been
implemented as stubs for future additional hooks to the Codex.
@zchee zchee force-pushed the codex-hooks-0.118.0 branch from 9f4e7af to c7153e6 Compare April 7, 2026 04:08
@zchee zchee requested a review from a team as a code owner April 7, 2026 04:08
case HookNamePreToolUse:
// PreToolUse has no lifecycle significance — pass through
case HookNamePreToolUse, HookNamePostToolUse:
// Acknowledged hooks with no lifecycle action
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's where the real PR meat starts. Happy for you to take over and add an implementation that I can review later on.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let's kick off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants