Documentation
¶
Overview ¶
Package codex provides types for Codex hook inputs and outputs.
Codex invokes command hooks as subprocesses, passing a JSON payload on stdin and reading optional JSON from stdout. The types in this package model the documented command-hook payloads.
See https://developers.openai.com/codex/hooks for the full specification.
Index ¶
- type BaseOutput
- type CompactTrigger
- type ContextHookOutput
- type Decision
- type EventName
- type Input
- type PermissionBehavior
- type PermissionDecision
- type PermissionMode
- type PermissionRequestDecision
- type PermissionRequestHookOutput
- type PermissionRequestInput
- type PermissionRequestOutput
- type PostCompactInput
- type PostToolUseInput
- type PostToolUseOutput
- type PreCompactInput
- type PreToolUseHookOutput
- type PreToolUseInput
- type PreToolUseOutput
- type SessionSource
- type SessionStartInput
- type SessionStartOutput
- type StopInput
- type StopOutput
- type SubagentStartInput
- type SubagentStartOutput
- type SubagentStopInput
- type SubagentStopOutput
- type TurnInput
- type UserPromptSubmitInput
- type UserPromptSubmitOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseOutput ¶
type BaseOutput struct {
Continue *bool `json:"continue,omitempty"`
StopReason *string `json:"stopReason,omitempty"`
SystemMessage *string `json:"systemMessage,omitempty"`
SuppressOutput *bool `json:"suppressOutput,omitempty"`
}
BaseOutput contains common JSON fields accepted by Codex hooks.
type CompactTrigger ¶
type CompactTrigger string
CompactTrigger describes what initiated context compaction.
const ( CompactManual CompactTrigger = "manual" CompactAuto CompactTrigger = "auto" )
type ContextHookOutput ¶
type ContextHookOutput struct {
HookEventName EventName `json:"hookEventName"`
AdditionalContext *string `json:"additionalContext,omitempty"`
}
ContextHookOutput adds model-visible context for supported events.
type Decision ¶
type Decision string
Decision is a top-level block decision used by several events.
const (
DecisionBlock Decision = "block"
)
type EventName ¶
type EventName string
EventName identifies which Codex hook event fired.
const ( EventSessionStart EventName = "SessionStart" EventSubagentStart EventName = "SubagentStart" EventPreToolUse EventName = "PreToolUse" EventPermissionRequest EventName = "PermissionRequest" EventPostToolUse EventName = "PostToolUse" EventPreCompact EventName = "PreCompact" EventPostCompact EventName = "PostCompact" EventUserPromptSubmit EventName = "UserPromptSubmit" EventSubagentStop EventName = "SubagentStop" EventStop EventName = "Stop" )
type Input ¶
type Input struct {
SessionID string `json:"session_id"`
TranscriptPath *string `json:"transcript_path,omitempty"`
CWD string `json:"cwd"`
HookEventName EventName `json:"hook_event_name"`
Model string `json:"model"`
PermissionMode PermissionMode `json:"permission_mode,omitempty"`
}
Input contains fields shared by Codex command hooks.
type PermissionBehavior ¶
type PermissionBehavior string
PermissionBehavior is a PermissionRequest allow/deny ruling.
const ( BehaviorAllow PermissionBehavior = "allow" BehaviorDeny PermissionBehavior = "deny" )
type PermissionDecision ¶
type PermissionDecision string
PermissionDecision is the hook-specific PreToolUse ruling.
const ( PermissionAllow PermissionDecision = "allow" PermissionDeny PermissionDecision = "deny" PermissionAsk PermissionDecision = "ask" )
type PermissionMode ¶
type PermissionMode string
PermissionMode describes the active Codex permission mode.
const ( PermissionDefault PermissionMode = "default" PermissionAcceptEdits PermissionMode = "acceptEdits" PermissionPlan PermissionMode = "plan" PermissionDontAsk PermissionMode = "dontAsk" PermissionBypassPermissions PermissionMode = "bypassPermissions" )
type PermissionRequestDecision ¶
type PermissionRequestDecision struct {
Behavior PermissionBehavior `json:"behavior"`
Message *string `json:"message,omitempty"`
}
PermissionRequestDecision is the hook's ruling on a permission prompt.
type PermissionRequestHookOutput ¶
type PermissionRequestHookOutput struct {
HookEventName EventName `json:"hookEventName"`
Decision PermissionRequestDecision `json:"decision"`
}
PermissionRequestHookOutput contains PermissionRequest-specific fields.
type PermissionRequestInput ¶
type PermissionRequestInput struct {
TurnInput
ToolName string `json:"tool_name"`
ToolInput json.RawMessage `json:"tool_input"`
}
PermissionRequestInput is sent when Codex is about to ask for approval.
type PermissionRequestOutput ¶
type PermissionRequestOutput struct {
BaseOutput
HookSpecificOutput *PermissionRequestHookOutput `json:"hookSpecificOutput,omitempty"`
}
PermissionRequestOutput is the response for PermissionRequest.
type PostCompactInput ¶
type PostCompactInput struct {
TurnInput
Trigger CompactTrigger `json:"trigger"`
}
PostCompactInput is sent after Codex compacts the conversation.
type PostToolUseInput ¶
type PostToolUseInput struct {
TurnInput
ToolName string `json:"tool_name"`
ToolUseID string `json:"tool_use_id"`
ToolInput json.RawMessage `json:"tool_input"`
ToolResponse json.RawMessage `json:"tool_response"`
}
PostToolUseInput is sent after a supported tool produces output.
func (*PostToolUseInput) FilePaths ¶
func (in *PostToolUseInput) FilePaths() []string
FilePaths extracts target file paths from a PostToolUse tool input.
Direct file tools may provide file_path. Codex edit flows generally use apply_patch, whose input carries patch text in a string field such as command or patch.
type PostToolUseOutput ¶
type PostToolUseOutput struct {
BaseOutput
Decision *Decision `json:"decision,omitempty"`
Reason *string `json:"reason,omitempty"`
HookSpecificOutput *ContextHookOutput `json:"hookSpecificOutput,omitempty"`
}
PostToolUseOutput is the response for PostToolUse.
type PreCompactInput ¶
type PreCompactInput struct {
TurnInput
Trigger CompactTrigger `json:"trigger"`
}
PreCompactInput is sent before Codex compacts the conversation.
type PreToolUseHookOutput ¶
type PreToolUseHookOutput struct {
HookEventName EventName `json:"hookEventName"`
PermissionDecision PermissionDecision `json:"permissionDecision,omitempty"`
PermissionDecisionReason *string `json:"permissionDecisionReason,omitempty"`
UpdatedInput json.RawMessage `json:"updatedInput,omitempty"`
AdditionalContext *string `json:"additionalContext,omitempty"`
}
PreToolUseHookOutput contains PreToolUse-specific output fields.
type PreToolUseInput ¶
type PreToolUseInput struct {
TurnInput
ToolName string `json:"tool_name"`
ToolUseID string `json:"tool_use_id"`
ToolInput json.RawMessage `json:"tool_input"`
}
PreToolUseInput is sent before a supported tool call executes.
type PreToolUseOutput ¶
type PreToolUseOutput struct {
BaseOutput
Decision *Decision `json:"decision,omitempty"`
Reason *string `json:"reason,omitempty"`
HookSpecificOutput *PreToolUseHookOutput `json:"hookSpecificOutput,omitempty"`
}
PreToolUseOutput is the response for PreToolUse.
type SessionSource ¶
type SessionSource string
SessionSource describes what triggered SessionStart.
const ( SessionSourceStartup SessionSource = "startup" SessionSourceResume SessionSource = "resume" SessionSourceClear SessionSource = "clear" SessionSourceCompact SessionSource = "compact" )
type SessionStartInput ¶
type SessionStartInput struct {
Input
Source SessionSource `json:"source"`
}
SessionStartInput is sent when a Codex session starts or resumes.
type SessionStartOutput ¶
type SessionStartOutput struct {
BaseOutput
HookSpecificOutput *ContextHookOutput `json:"hookSpecificOutput,omitempty"`
}
SessionStartOutput is the response for SessionStart.
type StopInput ¶
type StopInput struct {
TurnInput
StopHookActive bool `json:"stop_hook_active"`
LastAssistantMessage *string `json:"last_assistant_message,omitempty"`
}
StopInput is sent when a Codex turn is about to stop.
type StopOutput ¶
type StopOutput struct {
BaseOutput
Decision *Decision `json:"decision,omitempty"`
Reason *string `json:"reason,omitempty"`
}
StopOutput is the response for Stop.
type SubagentStartInput ¶
type SubagentStartInput struct {
TurnInput
AgentID string `json:"agent_id"`
AgentType string `json:"agent_type"`
}
SubagentStartInput is sent when a subagent starts.
type SubagentStartOutput ¶
type SubagentStartOutput struct {
BaseOutput
HookSpecificOutput *ContextHookOutput `json:"hookSpecificOutput,omitempty"`
}
SubagentStartOutput is the response for SubagentStart.
type SubagentStopInput ¶
type SubagentStopInput struct {
TurnInput
AgentID string `json:"agent_id"`
AgentType string `json:"agent_type"`
AgentTranscriptPath *string `json:"agent_transcript_path,omitempty"`
StopHookActive bool `json:"stop_hook_active"`
LastAssistantMessage *string `json:"last_assistant_message,omitempty"`
}
SubagentStopInput is sent when a subagent is about to stop.
type SubagentStopOutput ¶
type SubagentStopOutput struct {
BaseOutput
Decision *Decision `json:"decision,omitempty"`
Reason *string `json:"reason,omitempty"`
}
SubagentStopOutput is the response for SubagentStop.
type UserPromptSubmitInput ¶
UserPromptSubmitInput is sent before a prompt is submitted to Codex.
type UserPromptSubmitOutput ¶
type UserPromptSubmitOutput struct {
BaseOutput
Decision *Decision `json:"decision,omitempty"`
Reason *string `json:"reason,omitempty"`
HookSpecificOutput *ContextHookOutput `json:"hookSpecificOutput,omitempty"`
}
UserPromptSubmitOutput is the response for UserPromptSubmit.