> ## Documentation Index
> Fetch the complete documentation index at: https://gluals.arnux.net/llms.txt
> Use this file to discover all available pages before exploring further.

# @hook

> Register a method as a GMod hook handler with named lookup and type inference.

## Overview

`@hook` marks a method as a GMod hook handler. GLuaLS can then validate hook names, infer parameters from hook definitions, and autocomplete hook names in `hook.Add` and `hook.Run`.

***

## Syntax

```lua theme={null}
---@hook
---@hook HookName
```

* Without an argument: GLuaLS uses the method name as the hook name
* With an argument: GLuaLS uses the given hook name instead of the method name

***

## Basic usage

```lua theme={null}
local PLUGIN = {}

---@hook
function PLUGIN:PlayerSpawn(ply)
    -- ply is typed as Player from the hook definition ✅
end

---@hook PlayerInitialSpawn
function PLUGIN:OnPlayerFirstJoin(ply)
    -- maps to PlayerInitialSpawn hook
    -- ply typed as Player ✅
end
```

***

## `GM:` overrides

GLuaLS treats methods on the gamemode table (`GM`) as hook overrides. You do not need `@hook` for them in most cases:

```lua theme={null}
function GM:PlayerSpawn(ply)
    self.BaseClass.PlayerSpawn(self, ply)
end
```

GLuaLS infers the parameters from the GMod hook definition.

***

## Custom prefixes

If your framework uses a custom table instead of `GM` or `PLUGIN`, configure GLuaLS to recognize it:

<Tip>
  Use the settings menu instead of editing the JSON file directly. This helps you avoid config mistakes.
</Tip>

```json .gluarc.json theme={null}
{
  "gmod": {
    "hookMappings": {
      "methodToHook": {
        "Run": "PlayerSpawn"
      },
      "emitterToHook": {
        "COMPONENT": "CustomHook"
      },
      "methodPrefixes": ["COMPONENT"]
    }
  }
}
```

***

## Hook autocomplete

When you call `hook.Add("|", ...)`, `hook.Run("|", ...)`, or `hook.Call("|", ...)`, GLuaLS autocompletes known hook names, including GMod built-ins and your custom hooks.

***

## See also

* [Hook intelligence](/language/hook-intelligence): how GLuaLS analyzes hooks
