add_custom_hook
[MAINTENANCE] 273287cb — define a user-creatable Claude Code hook (PreToolUse | PostToolUse | Stop), generalizing past sprint_guard.sh/.ps1 (the only hook Meridian auto-writes today). Written into the repo's .claude/hooks/<slug>.sh / .ps1 on the next generate_handoff — the same auto-inject mechan...
This record as markdown: /tools/io-github-ajc3xc-meridian/add-custom-hook.md
What add_custom_hook does on Meridian
AI agents use add_custom_hook to create or update resources in Meridian, usually the action step of a workflow, after the agent has gathered context. Every call changes real data in your Meridian environment.
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Human-readable hook name; sanitized to a filesystem-safe slug used for the written filename(s). Must not be 'sprint_guard'. |
event | string | Yes | Which Claude Code hook event this fires on. |
enabled | boolean | — | Default true. Disabled hooks are skipped on the next generate_handoff write (their files aren't touched, but also aren't refreshed). |
matcher | string | — | Optional Claude Code tool-name matcher regex (e.g. "Edit|Write"); ignored for Stop hooks. |
blocking | boolean | — | Default true. true = real exit-code-blocking semantics (script written verbatim). false = advisory/non-blocking (an exit 2 is downgraded to 1 before writing). |
script_sh | string | Yes | POSIX shell script body (required). Receives the same stdin JSON payload Claude Code passes to any hook. |
project_id | string | — | |
script_ps1 | string | — | Optional PowerShell script body. Omit to only write the .sh file. |
project_name | string | — | Project name — an alternative to project_id; resolved to the id internally. project_id wins if both are given. |
Parameters from the server's own tool schema.
Why add_custom_hook is rated Medium
This tool writes executable shell/PowerShell scripts into the repository's .claude/hooks/ directory. While it's a Write operation (creating files), the files it creates are executable hook scripts that run during AI coding sessions (PreToolUse, PostToolUse, Stop).
From the tool's definition define a user-creatable Claude Code hook ... Written into the repo's .claude/hooks/<slug>.sh / .ps1 on the next generate_handoff
Attacks that exploit this kind of access
The rule that runs add_custom_hook safely
PolicyLayer is an MCP gateway: it sits between your AI agents and Meridian, and checks every tool call against a rule you set before the call runs. Nothing changes on the server itself. For add_custom_hook, this is the rule to start with:
add_custom_hook stays usable, but capped: an agent stuck in a loop can't make hundreds of changes a minute. Everything else on the server is denied unless you say otherwise.
The button opens the PolicyLayer dashboard: create your workspace, connect Meridian, apply this rule, and every add_custom_hook call is checked against it from then on.
Questions about add_custom_hook
[MAINTENANCE] 273287cb — define a user-creatable Claude Code hook (PreToolUse | PostToolUse | Stop), generalizing past sprint_guard.sh/.ps1 (the only hook Meridian auto-writes today). Written into the repo's .claude/hooks/<slug>.sh / .ps1 on the next generate_handoff — the same auto-inject mechanism sprint_guard already uses. script_sh (POSIX shell body) is required; script_ps1 (PowerShell body) is optional — omit it to only ever write the .sh file. matcher is a Claude Code tool-name regex (e.g. "Edit|Write"), ignored for Stop hooks. blocking (default true) controls determinism vs. suggestion power: true writes the script byte-for-byte so its own exit code drives REAL Claude Code exit-code-blocking semantics (exit 2 blocks a PreToolUse call / a Stop / feeds PostToolUse output back to the model); false wraps it so an exit 2 is downgraded to 1 before it's written — the hook still runs and its output still surfaces, but it can never hard-block ('strong suggestion power' without determinism). name must not be 'sprint_guard' (reserved for Meridian's own hook) or collide with an existing hook's derived slug on this project — both raise a clear {error}. Persistent-state disclosure: on hosted Meridian, supplied text and project/session metadata are sent to and stored in Meridian's service; self-hosted deployments keep them in the configured local SQLite/Postgres database. This data is visible in the dashboard/API and later project context or handoffs. Delete individual tasks, notes, or decisions where supported, or delete the project/account using the documented controls. Do not include secrets. It is categorised as a Write tool in the Meridian MCP Server, which means it can create or modify data. Consider rate limits to prevent runaway writes.
add_custom_hook accepts 9 parameters: name, event, enabled, matcher, blocking, script_sh, project_id, script_ps1, project_name. Required: name, event, script_sh. The full parameter table on this page comes from the server's own tool schema.
Register the Meridian MCP server in PolicyLayer and add a rule for add_custom_hook: allow, deny, rate-limit, or require approval. Point your MCP client at the PolicyLayer proxy URL and the rule is enforced on every call, before it reaches Meridian. Nothing to install.
add_custom_hook is a Write tool with medium risk. Write tools should be rate-limited to prevent accidental bulk modifications.
Yes. Add a rate_limit block to the add_custom_hook rule in your PolicyLayer policy. For example, setting max: 10 and window: 60 limits the tool to 10 calls per minute. Rate limits are tracked per agent session and reset automatically.
Set action: deny in the PolicyLayer policy for add_custom_hook. The AI agent will receive a policy violation error and cannot call the tool. You can also include a reason field to explain why the tool is blocked.
add_custom_hook is provided by the Meridian MCP server (@meridianmcp/mcp). PolicyLayer sits as a proxy in front of this server to enforce policies before tool calls reach the server.
More on Meridian, and thousands of servers like it.
This server
Across the catalogue