# Class LittleGhost::Runtime::Hook

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Runtime/Hook.html

Hooks let applications prepare runs, select session history, transform
interjections, and map errors to caller-safe messages.

Hooks are instantiated once per Runtime in configuration order. Override only
the methods needed and return the supplied value when leaving it unchanged.

    class TenantHook < LittleGhost::Runtime::Hook
      def prepare_run(run)
        run.register(TenantConnection.new(run.invocation.actor_id))
        run
      end
    end

## Inheritance

`LittleGhost::Runtime::Hook < Object`

## Instance methods

<a id="method-i-error_message"></a>
### `#error_message`

```ruby
#error_message(_error, _run)
```

Returns a caller-safe error message, or nil to defer to later hooks and the
runtime default. Avoid exposing secrets or internal exception text.

<a id="method-i-prepare_execution"></a>
### `#prepare_execution`

```ruby
#prepare_execution(run)
```

Prepares a Run after its Workspace and Sandbox have opened, but before session
history or the entrypoint Agent is built. Hooks may safely store run-scoped
files here.

<a id="method-i-prepare_interjection"></a>
### `#prepare_interjection`

```ruby
#prepare_interjection(_run, payload)
```

Transforms an interjection payload before it reaches the agent.

<a id="method-i-prepare_run"></a>
### `#prepare_run`

```ruby
#prepare_run(run)
```

Prepares a newly built Run. Resources registered on the run share its
lifecycle and close in reverse order.

<a id="method-i-session_history"></a>
### `#session_history`

```ruby
#session_history(_run, stored:, fallback:)
```

Returns the history to use for this run, or nil to defer to later hooks and
the session default. `stored` is empty when the session is new; `fallback`
contains messages supplied by the invocation.
