Skip to content

Add prompt hooks#24634

Draft
abhinav-oai wants to merge 5 commits into
mainfrom
abhinav/prompt-hooks
Draft

Add prompt hooks#24634
abhinav-oai wants to merge 5 commits into
mainfrom
abhinav/prompt-hooks

Conversation

@abhinav-oai
Copy link
Copy Markdown
Collaborator

@abhinav-oai abhinav-oai commented May 26, 2026

Why

Codex hooks should support prompt handlers for the events where prompt hooks have defined semantics

What

  • Add prompt hook config/API fields: prompt, model, timeout, statusMessage, and continueOnBlock.
  • Add a lightweight prompt behavior table with comments for each supported/no-op/unsupported event class.
  • Run prompt hooks through the existing hook dispatcher and output parsers by mapping model JSON output into existing hook JSON decisions.
  • Wire prompt hook execution to the session model client and regenerate config/app-server schema artifacts.

Example

Tried this hook

[[hooks.UserPromptSubmit.hooks]]
type = "prompt"
statusMessage = "Checking whether the request is actionable"
prompt = "Evaluate if the ask is well specified: $ARGUMENTS. Block requests that are underspecified!"

Results

› help

• UserPromptSubmit hook (blocked)
  feedback: Request is underspecified: clarify what help is needed and the desired outcome.

FeedbackOrStop,
}

pub(crate) fn prompt_hook_behavior(event_name: HookEventName) -> PromptHookBehavior {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Comment thread codex-rs/config/src/hook_config.rs

let request = PromptHookRequest {
event_name: handler.event_name,
prompt: render_prompt(prompt, input_json),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[P1] This renders the full hook input JSON into a model request. For PostToolUse and Stop hooks that input can include unbounded tool output or last assistant text, so a single prompt hook can exceed context limits or spend a huge number of tokens before existing hook output spilling applies. Please hard-cap or truncate the rendered prompt before calling the runner.

Copy link
Copy Markdown
Collaborator Author

@abhinav-oai abhinav-oai May 26, 2026

Choose a reason for hiding this comment

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

since we're not injecting to the main context I don't think its an issue? p sure codex picked this up from the AGENTS.md guidance to limit injected context to 10k toks

# Conflicts:
#	codex-rs/core/src/session/session.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant