Skip to content

Add PermissionRequest hooks support#17563

Merged
abhinav-oai merged 20 commits intomainfrom
codex/permission-request-hooks-base
Apr 17, 2026
Merged

Add PermissionRequest hooks support#17563
abhinav-oai merged 20 commits intomainfrom
codex/permission-request-hooks-base

Conversation

@abhinav-oai
Copy link
Copy Markdown
Contributor

@abhinav-oai abhinav-oai commented Apr 12, 2026

Why

We need PermissionRequest hook support!

Also addresses:

Reviewer Note

There's a lot of plumbing for the new hook, key files to review are:

  • New hook added in codex-rs/hooks/src/events/permission_request.rs
  • Wiring for network approvals codex-rs/core/src/tools/network_approval.rs
  • Wiring for tool orchestrator codex-rs/core/src/tools/orchestrator.rs
  • Wiring for execve codex-rs/core/src/tools/runtimes/shell/unix_escalation.rs

What

  • Wires shell, unified exec, and network approval prompts into the PermissionRequest hook flow.
  • Lets hooks allow or deny approval prompts; quiet or invalid hooks fall back to the normal approval path.
  • Uses tool_input.description for user-facing context when it helps:
    • shell / exec_command: the request justification, when present
    • network approvals: network-access <domain>
  • Uses tool_name: Bash for shell, unified exec, and network approval permission-request hooks.
  • For network approvals, passes the originating command in tool_input.command when there is a single owning call; otherwise falls back to the synthetic network-access ... command.
Example `PermissionRequest` hook input for a shell approval
{
  "session_id": "<session-id>",
  "turn_id": "<turn-id>",
  "transcript_path": "/path/to/transcript.jsonl",
  "cwd": "/path/to/cwd",
  "hook_event_name": "PermissionRequest",
  "model": "gpt-5",
  "permission_mode": "default",
  "tool_name": "Bash",
  "tool_input": {
    "command": "rm -f /tmp/example"
  }
}
Example `PermissionRequest` hook input for an escalated `exec_command` request
{
  "session_id": "<session-id>",
  "turn_id": "<turn-id>",
  "transcript_path": "/path/to/transcript.jsonl",
  "cwd": "/path/to/cwd",
  "hook_event_name": "PermissionRequest",
  "model": "gpt-5",
  "permission_mode": "default",
  "tool_name": "Bash",
  "tool_input": {
    "command": "cp /tmp/source.json /Users/alice/export/source.json",
    "description": "Need to copy a generated file outside the workspace"
  }
}
Example `PermissionRequest` hook input for a network approval
{
  "session_id": "<session-id>",
  "turn_id": "<turn-id>",
  "transcript_path": "/path/to/transcript.jsonl",
  "cwd": "/path/to/cwd",
  "hook_event_name": "PermissionRequest",
  "model": "gpt-5",
  "permission_mode": "default",
  "tool_name": "Bash",
  "tool_input": {
    "command": "curl http://codex-network-test.invalid",
    "description": "network-access http://codex-network-test.invalid"
  }
}

Follow-ups

  • Implement the PermissionRequest semantics for updatedInput, updatedPermissions, interrupt, and suggestions / permission_suggestions
  • Add PermissionRequest support for the request_permissions tool path

abhinav-oai and others added 2 commits April 12, 2026 12:27
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
@abhinav-oai abhinav-oai changed the title [codex] Add Bash PermissionRequest hooks Add Bash PermissionRequest hooks Apr 12, 2026
Replace stringly approval-attempt plumbing with a shared enum, centralize approval decision handling in the orchestrator, and document plus test the reserved PermissionRequest output fields.

Co-authored-by: Codex <noreply@openai.com>
@abhinav-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1bf5222fbb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread codex-rs/core/src/tools/orchestrator.rs
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
@abhinav-oai abhinav-oai changed the title Add Bash PermissionRequest hooks Add PermissionRequest hooks support Apr 13, 2026
abhinav-oai and others added 8 commits April 13, 2026 13:45
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Keep PermissionRequest hook payloads focused on tool identity and the actionable command details. For Bash and exec_command hooks, plumb request justification into tool_input.description when present. For NetworkAccess hooks, pass the originating command and a network-access <domain> description instead of the old approval context envelope.

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Remove the approval-attempt enum and let callers provide the final permission-request hook run id suffix directly. This keeps retry hook runs unique without carrying an extra cross-crate type.\n\nCo-authored-by: Codex <noreply@openai.com>
@abhinav-oai abhinav-oai marked this pull request as ready for review April 14, 2026 00:24
@abhinav-oai
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e4869308c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +301 to +304
if decision.updated_input.is_some() {
Some("PermissionRequest hook returned unsupported updatedInput".to_string())
} else if decision.updated_permissions.is_some() {
Some("PermissionRequest hook returned unsupported updatedPermissions".to_string())
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.

P1 Badge Treat null reserved fields as invalid in PermissionRequest

unsupported_permission_request_hook_specific_output only checks is_some() on updated_input/updated_permissions. With Serde, explicitly sending "updatedInput": null (or updatedPermissions) deserializes to None, so the hook output is accepted instead of failing closed. This contradicts the documented intent that these reserved fields are unsupported when present.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@eternal-openai eternal-openai left a comment

Choose a reason for hiding this comment

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

Codex notes: "PermissionRequest universal hook controls are handled incorrectly. The Claude hooks contract applies fields like continue and stopReason across hook events, but this implementation rejects them for PermissionRequest and falls back to normal approval instead of honoring the hook’s stop behavior."

Still reading otherwise

Copy link
Copy Markdown
Contributor

@eternal-openai eternal-openai left a comment

Choose a reason for hiding this comment

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

Looks good aside from that note above! Will approve after that's resolved

@abhinav-oai abhinav-oai force-pushed the codex/permission-request-hooks-base branch from 1542947 to 7c38bb4 Compare April 14, 2026 23:55
# Conflicts:
#	codex-rs/core/src/codex.rs
@abhinav-oai
Copy link
Copy Markdown
Contributor Author

abhinav-oai commented Apr 15, 2026

Looks good aside from that note above! Will approve after that's resolved

implemented but ended up backing the changes out so this PR is easier to review

continue:false is also unimplemented for the PreToolUse hook so I think it makes sense to add them in one go in a follow up

here's the current draft, need to tie in PreToolUse and clean it up #17864

@abhinav-oai
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Keep the PermissionRequest approval helper focused on hook-or-prompt selection while leaving approval decision handling in the existing approval branches.

Co-authored-by: Codex <noreply@openai.com>
@abhinav-oai abhinav-oai enabled auto-merge (squash) April 17, 2026 14:41
@abhinav-oai abhinav-oai merged commit 8494e5b into main Apr 17, 2026
35 of 36 checks passed
@abhinav-oai abhinav-oai deleted the codex/permission-request-hooks-base branch April 17, 2026 14:45
@github-actions github-actions bot locked and limited conversation to collaborators Apr 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants