Skip to content

Open-source skills for designing and reviewing software with AI agents

feat(claude): approve plugin file reads with a PreToolUse hook

John Pettitta9738d418a11
diff --git a/.claude-plugin/hooks/allow_plugin_reads.sh b/.claude-plugin/hooks/allow_plugin_reads.sh
new file mode 100755
index 0000000..9884120
--- /dev/null
+++ b/.claude-plugin/hooks/allow_plugin_reads.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+# Copyright 2026 Google LLC.
+# SPDX-License-Identifier: Apache-2.0
+
+# Approves Read, Grep and Glob only inside the plugin folders that EGM reads at
+# run time. Personas and standards live outside the user's workspace, and
+# headless runs and background subagents cannot ask for permission, so without
+# this a Goldfish cannot read its persona. The rest of the plugin root is left
+# out because a local install copies the whole clone, private files included.
+# Anything not clearly inside those folders, including any input that contains
+# "..", falls through to the normal permission rules.
+input=$(cat)
+case "$input" in *..*) exit 0 ;; esac
+root=${CLAUDE_PLUGIN_ROOT%/}
+[ -n "$root" ] || exit 0
+# An absolute or home-relative Glob pattern could name files outside `path`.
+if printf '%s' "$input" | grep -Eq '"tool_name"[[:space:]]*:[[:space:]]*"Glob"' &&
+ printf '%s' "$input" | grep -Eq '"pattern"[[:space:]]*:[[:space:]]*"[/~]'; then
+ exit 0
+fi
+path=$(printf '%s' "$input" | sed -nE 's/.*"(file_path|path)"[[:space:]]*:[[:space:]]*"([^"\\]*)".*/\2/p' | head -n 1)
+case "$path" in
+ "$root"/agents | "$root"/agents/* | "$root"/docs | "$root"/docs/* | \
+ "$root"/resources | "$root"/resources/* | "$root"/skills | "$root"/skills/*)
+ printf '%s\n' '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow","permissionDecisionReason":"EGM plugin file"}}'
+ ;;
+esac
+exit 0
diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json
index 260d531..b23ca8d 100644
--- a/.claude-plugin/plugin.json
+++ b/.claude-plugin/plugin.json
@@ -18,5 +18,18 @@
"./.claude-plugin/agents/style.md",
"./.claude-plugin/agents/synthesizer.md",
"./.claude-plugin/agents/zoom_out.md"
- ]
+ ],
+ "hooks": {
+ "PreToolUse": [
+ {
+ "matcher": "Read|Grep|Glob",
+ "hooks": [
+ {
+ "type": "command",
+ "command": "\"${CLAUDE_PLUGIN_ROOT}/.claude-plugin/hooks/allow_plugin_reads.sh\""
+ }
+ ]
+ }
+ ]
+ }
}
diff --git a/docs/claude.md b/docs/claude.md
index 57b889f..7fae189 100644
--- a/docs/claude.md
+++ b/docs/claude.md
@@ -47,13 +47,15 @@ invoked skill. Never guess a cache version or search another installed copy.
Review targets and generated artifacts belong to the user's workspace, not the
plugin cache. Pass absolute resource and target paths to each reviewer.
-Personas and standards live in the plugin cache, outside the project. Reading
-them is not pre-approved: in an interactive session each read prompts the user,
-and in a headless session with no permission rules the read fails and the
-reviewer reports an incomplete review. For headless runs pass
-`--allowedTools Read,Grep,Glob` or add equivalent `permissions.allow` rules
-for the plugin root. Approve these prompts in interactive sessions; a
-reviewer that cannot read its persona or standard has not reviewed.
+Personas and standards live in the plugin cache, outside the project. A
+`PreToolUse` hook in `.claude-plugin/plugin.json` approves `Read`, `Grep`, and
+`Glob` calls inside the plugin's `agents/`, `docs/`, `resources/`, and
+`skills/` folders only, so reviewers read them with no permission rules, also
+in headless runs and background subagents. Other paths get the normal
+permission rules, and deny and ask rules still apply to plugin paths. Where
+plugin hooks do not run (Claude Cowork, or `disableAllHooks`), approve the read
+prompts, or for headless runs pass `--allowedTools Read,Grep,Glob`. A reviewer
+that cannot read its persona or standard has not reviewed.
## Reviewer isolation
diff --git a/tests/unit/test_harnesses.py b/tests/unit/test_harnesses.py
index 7b037d5..b6082dc 100644
--- a/tests/unit/test_harnesses.py
+++ b/tests/unit/test_harnesses.py
@@ -4,9 +4,11 @@
"""Offline packaging and isolation contracts for shared and host manifests."""
import json
+import os
from pathlib import Path
import re
import runpy
+import subprocess
import pytest
import yaml
@@ -149,6 +151,58 @@ def test_claude_bootstrap_adapter_routes_to_skill() -> None:
assert "./agents/bootstrap_orchestrator.md" not in manifest
+READ_HOOK = ".claude-plugin/hooks/allow_plugin_reads.sh"
+
+
+def run_read_hook(tool_name: str, tool_input: dict) -> str:
+ result = subprocess.run(
+ [str(ROOT / READ_HOOK)],
+ input=json.dumps({"tool_name": tool_name, "tool_input": tool_input}),
+ capture_output=True,
+ text=True,
+ check=True,
+ env={**os.environ, "CLAUDE_PLUGIN_ROOT": str(ROOT)},
+ )
+ return result.stdout
+
+
+def test_claude_read_hook_is_registered() -> None:
+ hooks = read_json(".claude-plugin/plugin.json")["hooks"]["PreToolUse"]
+ assert [hook["matcher"] for hook in hooks] == ["Read|Grep|Glob"]
+ command = hooks[0]["hooks"][0]["command"]
+ assert command == f'"${{CLAUDE_PLUGIN_ROOT}}/{READ_HOOK}"'
+
+
+ ("tool_name", "tool_input", "allowed"),
+ [
+ ("Read", {"file_path": "{root}/agents/style.md"}, True),
+ ("Read", {"file_path": "{root}/docs/claude.md"}, True),
+ ("Read", {"file_path": "{root}/skills/egm_review/SKILL.md"}, True),
+ ("Grep", {"pattern": "x", "path": "{root}/resources"}, True),
+ ("Glob", {"pattern": "**/*.md", "path": "{root}/agents"}, True),
+ ("Read", {"file_path": "/etc/passwd"}, False),
+ ("Read", {"file_path": "{root}/agents/../../etc/passwd"}, False),
+ ("Read", {"file_path": "{root}-evil/agents/style.md"}, False),
+ ("Read", {"file_path": "{root}/agents-evil/style.md"}, False),
+ ("Read", {"file_path": "{root}/README.md"}, False),
+ ("Read", {"file_path": "{root}/.claude/settings.local.json"}, False),
+ ("Grep", {"pattern": "x", "path": "{root}"}, False),
+ ("Grep", {"pattern": '"path":"{root}/agents"', "path": "/etc"}, False),
+ ("Glob", {"pattern": "**/*.md"}, False),
+ ("Glob", {"pattern": "/etc/*", "path": "{root}/agents"}, False),
+ ("Glob", {"pattern": "~/.ssh/*", "path": "{root}/agents"}, False),
+ ],
+)
+def test_claude_read_hook_approves_plugin_folders_only(
+ tool_name: str, tool_input: dict, allowed: bool
+) -> None:
+ """Only clean paths in the folders EGM reads skip the permission prompt."""
+ tool_input = {k: v.replace("{root}", str(ROOT)) for k, v in tool_input.items()}
+ output = run_read_hook(tool_name, tool_input)
+ assert ('"permissionDecision":"allow"' in output) is allowed
+
+
def test_claude_manifest_agents_and_shared_personas_resolve() -> None:
paths = read_json(".claude-plugin/plugin.json")["agents"]
assert all((ROOT / path).is_file() for path in paths)