> ## Documentation Index
> Fetch the complete documentation index at: https://allhandsai-chore-regenerate-agent-sdk-openapi.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Hooks

> Load hooks from the workspace .openhands/hooks.json file.

This endpoint reads the hooks configuration from the project's
.openhands/hooks.json file if it exists.

Args:
    request: HooksRequest containing the project directory path.

Returns:
    HooksResponse containing the hook configuration or None.



## OpenAPI

````yaml /openapi/agent-sdk.json post /api/hooks
openapi: 3.1.0
info:
  description: OpenHands Agent Server - REST/WebSocket interface for OpenHands AI Agent
  title: OpenHands Agent Server
  version: 1.52.0
servers: []
security: []
paths:
  /api/hooks:
    post:
      tags:
        - Hooks
      summary: Get Hooks
      description: |-
        Load hooks from the workspace .openhands/hooks.json file.

        This endpoint reads the hooks configuration from the project's
        .openhands/hooks.json file if it exists.

        Args:
            request: HooksRequest containing the project directory path.

        Returns:
            HooksResponse containing the hook configuration or None.
      operationId: get_hooks_api_hooks_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HooksRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HooksResponse'
          description: Successful Response
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: Validation Error
      security:
        - APIKeyHeader: []
components:
  schemas:
    HooksRequest:
      description: Request body for loading hooks.
      properties:
        project_dir:
          anyOf:
            - type: string
            - type: 'null'
          description: Workspace directory path for project hooks
          title: Project Dir
      title: HooksRequest
      type: object
    HooksResponse:
      description: Response containing hooks configuration.
      properties:
        hook_config:
          anyOf:
            - $ref: '#/components/schemas/HookConfig'
            - type: 'null'
          description: Hook configuration loaded from the workspace, or None if not found
      title: HooksResponse
      type: object
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      type: object
    HookConfig:
      additionalProperties: false
      description: >-
        Configuration for all hooks.


        Hooks can be configured either by loading from `.openhands/hooks.json`
        or

        by directly instantiating with typed fields:

            # Direct instantiation with typed fields (recommended):
            config = HookConfig(
                pre_tool_use=[
                    HookMatcher(
                        matcher="terminal",
                        hooks=[HookDefinition(command="block_dangerous.sh")]
                    )
                ]
            )

            # Load from JSON file:
            config = HookConfig.load(".openhands/hooks.json")
      properties:
        post_tool_use:
          description: Hooks that run after tool execution
          items:
            $ref: '#/components/schemas/HookMatcher'
          title: Post Tool Use
          type: array
        pre_tool_use:
          description: Hooks that run before tool execution
          items:
            $ref: '#/components/schemas/HookMatcher'
          title: Pre Tool Use
          type: array
        session_end:
          description: Hooks that run when a session ends
          items:
            $ref: '#/components/schemas/HookMatcher'
          title: Session End
          type: array
        session_start:
          description: Hooks that run when a session starts
          items:
            $ref: '#/components/schemas/HookMatcher'
          title: Session Start
          type: array
        stop:
          description: Hooks that run when the agent attempts to stop
          items:
            $ref: '#/components/schemas/HookMatcher'
          title: Stop
          type: array
        user_prompt_submit:
          description: Hooks that run when user submits a prompt
          items:
            $ref: '#/components/schemas/HookMatcher'
          title: User Prompt Submit
          type: array
      title: HookConfig
      type: object
    ValidationError:
      properties:
        ctx:
          title: Context
          type: object
        input:
          title: Input
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: Location
          type: array
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object
    HookMatcher:
      description: >-
        Matches events to hooks based on patterns.


        Supports exact match, wildcard (*), and regex (auto-detected or
        /pattern/).
      properties:
        hooks:
          items:
            $ref: '#/components/schemas/HookDefinition'
          title: Hooks
          type: array
        matcher:
          default: '*'
          title: Matcher
          type: string
      title: HookMatcher
      type: object
    HookDefinition:
      description: A single hook definition.
      properties:
        async:
          default: false
          title: Async
          type: boolean
        command:
          title: Command
          type: string
        max_iterations:
          default: 3
          title: Max Iterations
          type: integer
        name:
          anyOf:
            - type: string
            - type: 'null'
          title: Name
        prompt:
          anyOf:
            - type: string
            - type: 'null'
          title: Prompt
        system_prompt:
          anyOf:
            - type: string
            - type: 'null'
          title: System Prompt
        timeout:
          default: 60
          title: Timeout
          type: integer
        tools:
          items:
            type: string
          title: Tools
          type: array
        type:
          $ref: '#/components/schemas/HookType'
          default: command
      required:
        - command
      title: HookDefinition
      type: object
    HookType:
      description: Types of hooks that can be executed.
      enum:
        - command
        - prompt
        - agent
      title: HookType
      type: string
  securitySchemes:
    APIKeyHeader:
      in: header
      name: X-Session-API-Key
      type: apiKey

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.