agentsclimarketplace

En guardrail

Skill manok4/ensemble/skills/en-guardrail

Always-on safety guardrail. PreToolUse hooks on Bash AND DB-writing MCP tools inspect each command/statement for destructive patterns (recursive rm, non-recursive deleters, DROP TABLE, TRUNCATE, DELETE/UPDATE-without-WHERE, SQL-from-file, ORM resets, force-push, git reset --hard, branch -D, kubectl delete, docker rm -f / system prune, terraform destroy, aws s3 rm --recursive, gcloud delete) and force a permission prompt. In-tree build artifacts and localhost+test/dev databases pass without prompting. Human-only bypass via exporting ENSEMBLE_GUARDRAIL_BYPASS=on before launch (the old inline ENSEMBLE_GUARDRAIL=off prefix no longer works). Trigger phrases: 'guardrail', 'safety mode', 'check guardrail', 'what's protected'.From its SKILL.md

Install
npx -y skills add manok4/ensemble --skill en-guardrail

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

10.8 KB, as published. Nobody here has run it

Helper resolution. All references/X and bin/Y paths in this skill resolve relative to $ENSEMBLE_ROOT — the install root (skill at $ENSEMBLE_ROOT/skills/<name>/, shared helpers at $ENSEMBLE_ROOT/{references,bin}/). Compute once at start: $ENSEMBLE_ROOT env var if set; otherwise $(realpath "$(dirname <this-SKILL.md>)/../.."). Fail loudly if $ENSEMBLE_ROOT/references/host-detect.md does not resolve — that indicates a partial install (run /en-setup to repair).

/en-guardrail

Always-on PreToolUse hook that prompts before destructive Bash commands. Vendored from gstack/careful and extended for Ensemble use.

Activation model. The script is run by a global PreToolUse hook registered in ~/.claude/settings.json. Once installed, it is on for every session and every Bash call — no opt-in per session needed.

Process (when invoked manually)

  1. Detect host. Source $ENSEMBLE_ROOT/references/host-detect.md.
  2. Status check. Verify the hook is registered in ~/.claude/settings.json (PreToolUse → Bash matcher → $ENSEMBLE_ROOT/skills/en-guardrail/bin/check-guardrail.sh). If missing, surface the install snippet (see "Installation" below) and stop.
  3. Show protected patterns — render the table from "What's protected" below.
  4. Show recent fires if ~/.ensemble/analytics/guardrail.jsonl exists — last 10 lines, summarized as pattern × count × repo.
  5. Optional dry-run. If user passes a sample command (/en-guardrail "rm -rf /tmp/foo"), pipe a synthetic tool-input JSON through $ENSEMBLE_ROOT/skills/en-guardrail/bin/check-guardrail.sh and show the verdict (ask vs allow).

What's protected

PatternExampleRisk
rm -r / rm -rf / rm --recursiverm -rf /var/dataRecursive delete
DROP TABLE / DROP DATABASEDROP TABLE users;Schema/data loss
TRUNCATETRUNCATE orders;Data loss
DELETE FROM <table> without WHEREDELETE FROM users;Silent table-wipe
git push --force / -fgit push -f origin mainRemote history rewrite
git reset --hardgit reset --hard HEAD~3Uncommitted-work loss
git checkout . / git restore .git checkout .Working-tree wipe
git branch -D / git tag -dgit branch -D feature/xForced ref deletion
git worktree remove --forcegit worktree remove -f ../wtForced worktree removal
kubectl deletekubectl delete podProduction impact
docker rm -f / docker system prunedocker system prune -aContainer/image loss
terraform destroyterraform destroy -auto-approveInfrastructure teardown
aws s3 rm … --recursiveaws s3 rm s3://bkt/ --recursiveBulk object delete
gcloud … deletegcloud compute instances delete xCloud-resource delete
find … -delete / -exec rmfind / -name x -deleteBulk file delete (EN09)
rsync … --deletersync -a --delete src/ dst/Destination file delete (EN09)
shred / truncate -s 0 / unlinkshred secret.pemFile destruction (EN09)
> truncation of an existing file / symlinkecho x > important.logOverwrite existing file (EN09)
UPDATE … without a top-level WHEREUPDATE users SET active=falseSilent mass-update (EN09)
SQL from a file / stdin / pipe (non-local)psql -h prod -f migrate.sqlUn-inspectable SQL (EN09)
ORM destroyersprisma migrate reset, rails db:dropDatabase wipe (EN09)
DB-writing MCP toolsmcp__Neon__run_sql running DROP TABLEMCP DB write (EN09)

Single-file rm (e.g. rm foo.ts) is not flagged — too noisy for routine cleanup. UPDATE/DELETE with a real top-level WHERE, >> append, and new-file > creation are likewise not flagged.

Safe exceptions

These pass without prompting:

  • rm -rf of common build artifacts: node_modules, .next, dist, __pycache__, .cache, build, .turbo, coverage — only as a plain, in-tree relative path (EN09). An absolute (/build), home (~/dist, $HOME/…), shell-expanded (${HOME}/dist, $PWD/dist, $(pwd)/dist), globbed (/*), or parent-escaping (../dist) target is NOT exempt and prompts — the exemption is a positive allowlist that fails closed, so a "safe" artifact name can never greenlight a delete outside the working tree.

  • DROP / TRUNCATE / DELETE- or UPDATE-without-WHERE / SQL-from-file / ORM-reset against an explicit local test/dev DB. Both signals must be present in the same command:

    • Localhost connection — -h localhost, -h 127.0.0.1, @localhost, @127.0.0.1, or host=localhost|127.0.0.1.
    • Test/dev/local DB name — DB name (after /, -d, dbname=, or database=) contains test, dev, or local.

    Examples that exempt: psql -h localhost -d test_app -c 'DROP TABLE users', psql postgresql://[email protected]/myapp_test -c 'TRUNCATE orders'. Examples that don't exempt: psql -h localhost -d production, psql -h staging-db -d test_app.

MCP database tools (EN09)

A second PreToolUse matcher routes DB-writing MCP tools (e.g. mcp__Neon__run_sql, mcp__Postgres__execute) to the same hook, so a DROP TABLE issued through an MCP tool is caught the same as one via psql. The hook resolves the statement and the tool's controlling target field through a per-tool adapter; the local test/dev exemption is decided ONLY from that authoritative field, never from the SQL text (a localhost/test string in a comment can't spoof it). Remote-only providers (e.g. Neon) never exempt — a destructive statement there always prompts. A DB-write-named tool with no adapter, or unresolvable input, fails closed.

Scope (what the guardrail is, and is not)

The guardrail is a pattern-based accident brake, not a path sandbox or a policy wall:

  • It does not enforce the working-folder boundary. Which directories the agent may read/write is the host permission system's job (Claude Code). The guardrail adds a destructive-pattern prompt on top; it does not, on its own, confine deletes to the repo.
  • "Production" is inferred by exemption, not a positive detector. Anything not provably a local test/dev target is treated as potentially production and prompts. A configurable positive production-marker (production_hosts / URL patterns) is a possible future extension, not implemented today.
  • Coverage is a maintained list, not exhaustive. New destructive tools/verbs are added as they're identified; the behavioral test suite (tests/en-guardrail/) is the source of truth for exactly what's covered.

Temporary disable (human-only, out-of-band — EN09)

The bypass is read only from the hook's own process environment, set by you in your shell before launching the agent:

export ENSEMBLE_GUARDRAIL_BYPASS=on   # in your shell, then start Claude Code

Why not an inline prefix or a config file: the old ENSEMBLE_GUARDRAIL=off <command> prefix was model-writable — an agent could prepend it to self-exempt — so it no longer bypasses anything (it now prompts like any other destructive command). A command-level VAR=value <command> assignment only scopes that subprocess and cannot reach the hook's environment, and the agent cannot mutate the already-running parent process's env. This makes the bypass a genuine human-only control within a session.

Agents: never set, export, or write ENSEMBLE_GUARDRAIL_BYPASS, and never edit shell profiles (~/.zshrc, ~/.bashrc) to set it. The bypass exists for the human operator only. (Editing a profile affects only future shells, not the running session, but it is still off-limits.)

To turn the guard back on, unset ENSEMBLE_GUARDRAIL_BYPASS (or start a new shell without the export).

Installation

The hook is registered in ~/.claude/settings.json under hooks.PreToolUse. The canonical entry:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "bash \"${ENSEMBLE_HOME:-$HOME/CodeRepo/ensemble}/skills/en-guardrail/bin/check-guardrail.sh\"",
            "statusMessage": "Checking for destructive commands..."
          }
        ]
      }
    ]
  }
}

The ${ENSEMBLE_HOME:-$HOME/CodeRepo/ensemble} expansion lets you move the Ensemble checkout — set ENSEMBLE_HOME in your shell profile to override.

How it works

$ENSEMBLE_ROOT/skills/en-guardrail/bin/check-guardrail.sh reads the tool-input JSON on stdin, extracts tool_input.command, normalizes case, and matches against the destructive-pattern catalog. On match, it returns {"permissionDecision": "ask", "message": "[guardrail] <reason>"} — Claude pauses and prompts the user. On no match (or safe-exception hit), it returns {} — Claude proceeds normally.

The hook fires only on Bash tool calls — Edit, Write, Read are unaffected.

Reference files

  • $ENSEMBLE_ROOT/skills/en-guardrail/bin/check-guardrail.sh — the hook script (canonical source).
  • $ENSEMBLE_ROOT/references/host-detect.md — host detection.
  • Upstream: gstack/careful — the original this is vendored from. To pull updates, diff against the upstream and selectively re-apply.

Failure protocol

FailureBehavior
~/.claude/settings.json lacks the PreToolUse registration/en-guardrail surfaces the install snippet and exits non-zero — guardrail is not active
Hook script missing or unreadableClaude Code's hook runner skips it silently — surface a warning when /en-guardrail runs
Pattern false positive (legitimate command flagged)Override the prompt manually; if it recurs, tighten the regex in $ENSEMBLE_ROOT/skills/en-guardrail/bin/check-guardrail.sh
Pattern false negative (destructive command not flagged)Open a tech-debt entry; add the pattern. Do not widen the safe-exceptions list reactively
ENSEMBLE_GUARDRAIL_BYPASS=on set in the launch environment/en-guardrail warns that the bypass is active session-wide; suggest unset ENSEMBLE_GUARDRAIL_BYPASS and relaunch

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.