Lyna
SupportBlogOpen Lyna
Get startedFeaturesIntegrationsPromptingTips & TricksChangelog
Build with AI

Hooks

Run a command or add an instruction automatically at set moments, such as after the AI edits a file or when a task is done.

Hooks react to events in a chat session. A hook either runs a shell command in your project's sandbox, or adds an instruction for the AI.

Settings open on Customize, Hooks chip, with hooks grouped by event.

What you can do

  • Run a check, such as lint or type checking, after every edit.
  • Remind the AI of a rule at the moment it matters.
  • Turn a hook off without deleting it.

Hook types

TypeWhat it does
CommandRuns the text as a shell command in the sandbox, for example bun run lint.
PromptAdds the text as an instruction for the AI.

Events

EventWhen it runs
Pre Tool UseBefore the assistant uses a tool.
Post Tool UseAfter a tool finishes.
Pre SendBefore a request is sent to the model.
Post SendAfter the model responds.
Session StartWhen a chat session starts.
Session EndWhen a chat session ends.
Task CreatedWhen a task is created.
Task CompletedWhen a task is completed.
File ChangedWhen a file is created, edited or deleted.
User Prompt SubmitWhen you submit a message.
Pre CompactBefore the conversation is summarized.
Post CompactAfter the conversation is summarized.
Sub-agent StartWhen a sub-agent starts.
Sub-agent StopWhen a sub-agent stops.
CWD ChangedWhen the working directory changes.

Add a hook

Open Hooks

Open Settings > AI > Customize and pick the Hooks chip. Choose Add Hook.

Configure it

Pick the Event and the Type, then write the Command or the Prompt Text. Add an optional description, such as "Run linter after AI edits".

Save and test

Save the hook. It runs the next time its event happens. To pause it, turn it off in the list, or type /hooks in the chat and toggle it.

The hooks file

Hooks are stored in .lyna_ai/hooks.json in your project:

{
  "hooks": [
    {
      "event": "PostToolUse",
      "type": "command",
      "command": "bun run lint",
      "description": "Lint the project after each edit",
      "enabled": true
    },
    {
      "event": "UserPromptSubmit",
      "type": "prompt",
      "command": "Keep changes minimal and update tests in the same change.",
      "description": "Remind the assistant of the working agreement",
      "enabled": true
    }
  ]
}

Keep command hooks fast

Command hooks run inline and hold the turn until they finish. A slow command slows every turn.

Next steps