mistralM

Docs

Hooks

Run shell commands at points in the Vibe Code CLI lifecycle to block, audit or rewrite tool calls, prompts and model responses with hooks.toml.

Hooks run your own shell commands at points in the Vibe Code CLI's lifecycle to gate, audit, or rewrite agent behavior. Use them to block dangerous tool calls or messages, rewrite tool arguments or prompts, add context for the model, check each model response, force the agent to retry an answer, or get notified when Vibe needs you.

Declare them in a hooks.toml file and they take effect on the next run.

Configuration file locations

Hooks are declared in hooks.toml. The CLI looks in this order:

  • 1.

    ./.vibe/hooks.toml in the working directory (project-level, loaded first, trusted folders only).
  • 2.

    ~/.vibe/hooks.toml in your home directory (user-level, loaded second).

When the same name appears in both files, the project entry wins. Project-level hooks load only when the working directory is trusted.

Subagents inherit the parent's hook configuration, so policies apply transitively.

Plugin hooks

A plugin can declare hooks in its ai.mistral.vibe/hooks.toml file, with the same fields as hooks.toml. Vibe prefixes each one with the plugin name, such as release-tools:audit-bash, and lists it in /plugins.

Plugin hooks run like the hooks in hooks.toml. For each event, hooks run in this order: ./.vibe/hooks.toml, project plugins, ~/.vibe/hooks.toml, then user plugins. A plugin hook runs in the session's pinned copy of the plugin, with PLUGIN_ROOT and PLUGIN_DATA set as for the plugin's MCP servers. Hooks in plugins written for Claude Code or Kimi Code don't run: Vibe reports them as not supported.

Declare a hook

Each hook is a [[hooks]] table:

[[hooks]]
name = "deny-rm-rf"
type = "pre_tool"
match = "bash"
command = "uv run python /path/to/guard-bash"
timeout = 60.0
strict = false
description = "Reject dangerous shell commands."

Field

Required

Details

nameyesUnique identifier. Used to deduplicate between project and user files.
typeyesOne of pre_tool, post_tool, pre_agent, pre_llm, post_llm, post_agent, notification, session_start, session_end.
commandyesShell command to spawn. Receives the hook payload on stdin. On Windows, runs in Git Bash when available, otherwise in PowerShell, like the bash tool.
matchnoWhat the hook runs for: the tool name for tool hooks, the agent name for pre_agent, pre_llm, post_llm, and post_agent, the notification type for notification, the source for session_start, and the reason for session_end. fnmatch glob, or regex with the re: prefix. Case-insensitive. Default: every value.
timeoutnoSeconds before the hook is killed. Default: 60.
strictpre_tool, post_tool, pre_agent, pre_llm, post_llmWhen true, parse and runtime failures become denials (pre_tool), text clears (post_tool), blocked messages (pre_agent), or ended turns (pre_llm, post_llm) instead of warnings. Default: false.
descriptionnoFree text shown in diagnostics.

Hook contract

Vibe starts each hook with a UTF-8 JSON object on stdin that contains the session context: session_id, parent_session_id, transcript_path, cwd, and hook_event_name. Each hook type adds its own fields (see below).

Hooks respond through their exit code and stdout. Use stderr for diagnostics and debug logs.

Exit / stdout

Effect

Exit 0, empty stdoutPassthrough.
Exit 0, valid JSON object on stdoutStructured response (see fields below).
Exit 0, non-empty but non-conforming stdoutHook failure. Warning by default; deny, clear, or block under strict = true.
Non-zero exit, timeout, or spawn failureHook failure. Diagnostic taken from stderr (fallback to stdout, then the exit code).

Universal top-level fields in the JSON response:

  • system_message (string, optional) — shown to the user in the UI.
  • decision ("allow" | "deny", optional, default "allow") — the effect of "deny" depends on the hook type.
  • reason (string, optional) — accompanies decision: "deny".
  • hook_specific_output (object, optional) — event-specific payload.

Unknown JSON fields are tolerated at every level (forward-compatible). Fields that are not meaningful for the current hook type are silently ignored.

On macOS and Linux, Vibe stops whatever a hook starts in the background with & when the hook exits. To leave a process running, start it in a new session: setsid cmd & on Linux, or perl -MPOSIX -e 'POSIX::setsid(); exec @ARGV' cmd & on macOS, which has no setsid command.

pre_tool

Fires per tool call, before the user permission prompt. The first deny skips the remaining pre_tool hooks for that call.

Receives (in addition to the session context): tool_name, tool_call_id, tool_input (the model's raw arguments).

tool_name is the full tool name, such as file_system.bash, or mcp_<server>.<tool> for MCP tools, for example mcp_linear.create_issue. match accepts both full and short names, so match = "bash" works. Commands the agent starts in the background go through process_start instead of bash, so match both in shell guards: match = "re:bash|process_start".

To act when the agent starts a subagent, use match = "agents_spawn".

Can return:

  • decision: "deny" + reason — denies the tool call; reason becomes the tool error that the LLM sees.
  • hook_specific_output.tool_input (object) — full replacement of the model's arguments. The replacement is re-validated against the tool's schema; a validation failure becomes a synthesized denial. Rewrites compose left-to-right across hooks. The rewritten arguments are also what the permission prompt displays, what the tool runs with, and what subsequent LLM turns see on the assistant message.
  • system_message — shown in the UI only.

post_tool

Fires per tool call if and only if the tool body actually ran. It doesn't fire when the tool never ran: pre_tool denial, denial at the approval prompt, or permission set to never.

Receives (in addition to the session context):

  • tool_name, tool_call_id
  • tool_input (post-rewrite)
  • tool_status — success or failure. A shell command that exits with an error code still counts as success.
  • tool_output — structured result dict; null on failure
  • tool_output_text — the running text the LLM will see, mutable by prior hooks
  • tool_error
  • duration_ms — not reported yet (always 0)

Can return:

  • decision: "deny" + reason — replaces tool_output_text with reason. The pipeline continues; subsequent hooks see the replacement.
  • hook_specific_output.additional_context (string) — appended (with a \n separator) to tool_output_text. Composes with a same-hook deny: deny replaces first, then additional_context is appended to the replacement.
  • system_message — shown in the UI only.

pre_agent

Fires once per turn, after you send a message and before the model reads it. match selects the agent whose turn starts, such as a subagent named reviewer, or main for the main agent. The first deny skips the remaining pre_agent hooks.

Receives (in addition to the session context): agent_name, turn_id, and prompt, the text you typed. Attachments aren't included.

Can return:

  • decision: "deny" + reason — blocks the message: the turn ends and the model never sees it.
  • hook_specific_output.prompt (string) — replaces the text the model receives. Your transcript still shows what you typed, and attachments are kept. Rewrites compose across hooks.
  • hook_specific_output.additional_context (string) — adds text after your message, for the model only. It stays in the conversation for later turns.
  • system_message — shown in the UI only.

pre_llm

Fires before each call to the model. A turn that uses tools calls the model several times, so keep this hook fast. match selects the agent whose turn it is, as for pre_agent. The first deny skips the remaining pre_llm hooks.

Receives (in addition to the session context): agent_name, turn_id, and model, the active model alias.

Can return:

  • decision: "deny" + reason — doesn't call the model: the turn ends, and reason becomes its answer.
  • system_message — shown in the UI only.

post_llm

Fires after each model response, before Vibe acts on it, including responses that only call tools. match selects the agent whose turn it is. post_agent still runs afterwards on the final answer.

Receives (in addition to the session context): agent_name, turn_id, response_text, tool_calls (each with tool_name, tool_call_id, and tool_input), finish_reason, and usage, the response's token counts.

Can return:

  • decision: "deny" + reason — discards the response, so its tools don't run, and asks the model to try again with reason as feedback. The first deny skips the remaining post_llm hooks. Shares the budget of 3 retries per turn with post_agent hooks.
  • system_message — shown in the UI only.

post_agent

Fires after every assistant turn that ends without pending tool calls, for the main agent and its subagents. Set match to run the hook only after a given agent, such as a subagent named reviewer, or match = "main" to run it only after the main agent.

Receives (in addition to the session context): agent_name, the name of the agent that finished its turn; turn_id; and response_text, the agent's final answer. Vibe saves the answer to the transcript at transcript_path only after every post_agent hook accepts it, so read it from response_text.

Can return:

  • decision: "deny" + reason — reason is injected as a new user message asking the agent to retry. Capped at 3 retries per turn across all post_agent and post_llm hooks; after that, Vibe accepts the answer. If a post_agent hook fails, Vibe accepts the answer and shows a warning.
  • system_message — shown in the UI only.

When a post_agent or post_llm retry would exceed --max-turns, the turn fails with a message naming the hook.

notification

Fires when Vibe needs you or when a turn ends. Use it to send a desktop or chat notification. match selects the notification type:

  • approval_requested — a tool call waits for your approval. The payload adds tool_name.
  • question_asked — the agent asks you a question.
  • turn_completed — the main agent finished its turn.
  • turn_failed — the main agent's turn failed.

Receives (in addition to the session context): notification_type, message (a short human-readable summary), and agent_name.

The hook runs in the background: Vibe doesn't wait for it and ignores its output. It doesn't fire when you interrupt the agent.

session_start

Fires when a session starts. match selects the source: startup for a new session, resume, clear after /clear, or fork when a rewind forks to a new session. It doesn't fire for subagents.

Receives (in addition to the session context): source, agent_name, and model.

Can return:

  • hook_specific_output.additional_context (string) — adds text to your next message, for the model only. Use it to load project context at the start of a session. With several hooks, Vibe joins their texts in order.
  • system_message — shown as the hook's line in the conversation.

You can type right away: your first message waits for the hooks before it reaches the model. A session_start hook can't block the session. If it fails, Vibe shows a warning and the session continues without its context.

session_end

Fires when a session ends. match selects the reason: exit when you quit Vibe, clear after /clear, or other, for example when you switch to another session. It doesn't fire after a crash.

Receives (in addition to the session context): reason.

The hook runs in the background and Vibe ignores its output. When you quit, Vibe waits up to 2 seconds in total for the session_end and notification hooks still running, then stops them.

Example: format files after each edit

This hook runs RuffarrowUpRight on every Python file the agent creates or edits. When the formatter changes the file, the hook tells the agent, so its next edit starts from the formatted content.

./.vibe/hooks.toml:

[[hooks]]
name = "format-python"
type = "post_tool"
match = "re:edit|write_file"
command = "python ./.vibe/hooks/format.py"
description = "Format Python files with Ruff after each edit."

./.vibe/hooks/format.py:

import json
import subprocess
import sys
from pathlib import Path

payload = json.load(sys.stdin)
if payload.get("tool_status") != "success":
    sys.exit(0)

path = Path(payload["tool_input"]["file_path"])
if path.suffix != ".py":
    sys.exit(0)

before = path.read_text()
subprocess.run(["ruff", "format", "--quiet", str(path)], check=True)
if path.read_text() != before:
    print(json.dumps({
        "hook_specific_output": {
            "additional_context": f"{path} was reformatted with ruff. Read it again before you edit it.",
        },
    }))

To format other languages, change the extension check and the command, for example prettier --write for TypeScript. If the formatter fails, for example on a syntax error, Vibe shows a warning and the agent's edit stays as it is.