OmniscioGuidesA plugin hooks bundle
A Claude Code plugin hooks bundle you can copy
Hooks in a plugin are the same hooks you would put in .claude/settings.json, with two differences that matter: they travel with the plugin to everyone who installs it, and their commands should point at files inside the plugin through ${CLAUDE_PLUGIN_ROOT}, because an installed plugin lives in a cache directory whose path changes with each version.
This is the hooks example from the five copyable plugin examples. If you want hooks without packaging them, the hooks examples puts five hook setups in a settings file, including the format-on-edit one here.
Checked against Anthropic’s Claude Code hooks and plugin documentation on November 25, 2026. By the Omniscio team. Updated .
What it bundles
Three hooks on three events, and one shell script for each. The manifest can be tiny, because every hook is found in its default file.
| Event | Matcher | What runs |
|---|---|---|
SessionStart | none needed | Prints the repository’s current branch and the last three commits; plain stdout from this event is added to Claude’s context |
PreToolUse | Write|Edit | Refuses a write to a generated or vendored path by exiting 2, with the reason on stderr |
PostToolUse | Write|Edit | Formats the file that was just written |
The two tool hooks carry a matcher because they should only run on file writes. A matcher made only of letters, digits, _, -, spaces, commas and | is read as an exact list of names, so Write|Edit matches either tool exactly. A matcher containing any other character is read as an unanchored JavaScript regular expression.
The full directory
team-guard/
├── .claude-plugin/
│ └── plugin.json
├── hooks/
│ └── hooks.json
└── scripts/
├── session-context.sh
├── guard-generated.sh
└── format.shThe manifest
{
"name": "team-guard",
"description": "Session context, a generated-file guard and format-on-edit for this repository",
"version": "1.0.0",
"author": { "name": "Platform Team" }
}The hooks file
{
"hooks": {
"SessionStart": [
{
"hooks": [
{ "type": "command", "command": "\"${CLAUDE_PLUGIN_ROOT}/scripts/session-context.sh\"" }
]
}
],
"PreToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{ "type": "command", "command": "\"${CLAUDE_PLUGIN_ROOT}/scripts/guard-generated.sh\"" }
]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{ "type": "command", "command": "\"${CLAUDE_PLUGIN_ROOT}/scripts/format.sh\"" }
]
}
]
}
}Every command here is written as a quoted string with no args. That form runs through a shell, so the double quotes are what keep the expanded ${CLAUDE_PLUGIN_ROOT} path one shell word when the install directory contains a space.
The three scripts
The two tool hooks read the event JSON on stdin; every script exits with the code that decides the outcome. Both tool scripts need jq, and the formatter needs Prettier installed in the project — without jq the file path comes back empty and the guard passes everything, and without Prettier the formatter exits 0 having changed nothing.
#!/bin/bash
cd "${CLAUDE_PROJECT_DIR:-.}" || exit 0
echo "Branch: $(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo unknown)"
echo "Recent commits:"
git log -3 --pretty='- %h %s' 2>/dev/null
exit 0#!/bin/bash
input=$(cat)
file=$(jq -r '.tool_input.file_path // empty' <<<"$input")
case "$file" in
*/generated/*|*/vendor/*|*.lock)
echo "Blocked: $file is generated. Change its source and regenerate it." >&2
exit 2
;;
esac
exit 0#!/bin/bash input=$(cat) file=$(jq -r '.tool_input.file_path // empty' <<<"$input") case "$file" in *.ts|*.tsx|*.js|*.jsx|*.json) npx --no-install prettier --write --ignore-unknown "$file" ;; esac exit 0
Make each script executable with chmod +x inside scripts/. A script that cannot start exits with a shell error such as 127, which is a non-blocking error unless the hook is one whose failure is configured to block the action.
What each part does
The configuration has three levels: the event, the matcher group that filters it, and one or more hook handlers that run when it matches. Every entry in this file follows that shape.
| Piece | What it decides |
|---|---|
hooks | The top-level key. Its value has the same shape as the hooks object in a settings file, so an existing settings hook copies in unchanged |
| Event name | When it fires: SessionStart, PreToolUse, PostToolUse here. Names are case-sensitive |
matcher | Which occurrences fire it. Omitted or an empty string matches all |
hooks[].type | What runs: command is the shell form used here; http, mcp_tool, prompt and agent are the others |
command | The shell command. It receives the event payload as JSON on stdin |
Each hook process also receives CLAUDE_PLUGIN_ROOT, CLAUDE_PLUGIN_DATA, and one CLAUDE_PLUGIN_OPTION_<KEY> for each user-configured value, so a script can read them from its environment instead of hard-coding a path.
A hook can also match the plugin’s own MCP tools, but only by the full tool name mcp__plugin_<plugin>_<server>__<tool>. A matcher on the bare server name never fires.
Nothing in this manifest points at hooks/, because hooks/hooks.json is the default location. A manifest hooks key adds to it rather than replacing it, so you only need one when the file lives elsewhere.
Install and enable it
claude plugin marketplace add your-org/your-marketplace claude plugin install team-guard@your-marketplace --scope project
The install id is the plugin name, an @, and the marketplace name. --scope project writes .claude/settings.json so the hooks are enabled for everyone in the repository; the default is user. The marketplace command above assumes a repository with a .claude-plugin/marketplace.json; the marketplace example builds one.
In a session, /plugin install team-guard@your-marketplace opens the plugin’s details and lets you choose the scope before anything is installed. Enable or disable it afterwards on the Installed tab, or with claude plugin enable and claude plugin disable.
Because a plugin’s hooks fire as soon as the session loads the plugin, an install or enable in the middle of a session needs /reload-plugins before the new hooks are live.
Confirm it loaded
First the files: claude plugin validate ./team-guard checks the manifest and exits 0 on Validation passed. It does not run your hooks, so the next three checks are for behaviour.
A blocking hook is the easiest to prove. Ask Claude to edit a file under generated/; the write should fail with the hook’s own sentence attached, prefixed with the event, the tool and the command.
A PostToolUse hook that exits 0 leaves no trace in the transcript. Turn on debug logging, trigger the event, and read the debug log: a hook that ran appears there with its exit code. The SessionStart hook is visible without any of that, because its plain stdout is added to Claude’s context at the start of the session.
Confirm the plugin itself too: claude plugin list shows it with Status: ✔ enabled, and /plugin on the Installed tab lists it with its scope.
The failure that is hardest to see: a hook that never fires
The plugin loads, the hook file parses, and nothing happens. Work through these in order, because each one eliminates a different layer.
- The event name. Names are case-sensitive, so
posttoolusematches nothing whilePostToolUsedoes. - The matcher. On a tool event it is matched against the tool name, so
Edit, WriteandEdit|Writeboth work, andeditdoes not. - The plugin name. If two enabled plugins share a name, one of them registers its
hooks/hooks.jsonand the other’s are left out. The plugin’s details in/pluginsay so with a note beginningIts hooks.json hooks do not run. - The command. A script path that does not exist fails before any of your code runs; the notice carries the shell’s
No such file or directory.
The second failure is quieter: the hook runs, prints something to stderr, and exits 1. That is a non-blocking error, so the tool call goes ahead and the notice is the only sign. Blocking needs exit 2.
A plugin’s hooks are also subject to managed settings: an administrator can use allowManagedHooksOnly to block user, project, local and plugin hooks, with an exemption for plugins force-enabled in managed settings.
Common questions
Where do a plugin’s hooks go?
In hooks/hooks.json at the plugin root, under a top-level hooks key, in the same shape as a settings file. A hooks key in plugin.json adds to it.
Why does my hook not block anything?
Only exit 2 blocks, and only on events that can block. Exit 1 and every other code are non-blocking errors.
How do I know a plugin hook fired?
A PostToolUse hook that exits 0 prints nothing. Use debug logging and read the log, which records each hook with its exit code, or use a blocking hook where the refusal itself is the proof.
Do plugin hooks run only while a skill is in use?
No. They are registered when the session loads the plugin and fire on their events from then on.
Every session, one window
Omniscio runs several agent sessions side by side in one window, each with its own context and its own diff view. Any model, any harness — Claude Code, Codex, OpenCode, Devin, Pi, and Hermes all supported.