agentleFS
JordanHoodJordanHood/claude-skills/skills/guardrails/SKILL.md

guardrails

Skill0 starsChanged 8 months agoMITView on GitHub

Safety hooks for Claude Code that protect against destructive operations, enforce write boundaries, and gate sensitive actions. Essential when running autonomous workers with --dangerously-skip-permissions. Use when: setting up a new Claude Code environment, configuring safety for dispatch/pipeline workers, or auditing existing hook coverage.

  • Reads credentials
  • Deletes or force-pushes
  • Commits and pushes

15 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use evaluation, prototype and 2 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • NVIDIASkill

    evaluation

    Evaluates accuracy of quantized or unquantized LLMs using NeMo Evaluator Launcher (NEL). Triggers on "evaluate model", "benchmark accuracy", "run MMLU", "evaluate quantized model", "run nel". Handles deployment, config generation, and evaluation execution. Always load when validating completed runs or reporting evaluation scores, including standalone launching-evals analysis. Not for quantizing models (use ptq), standalone serving (use deployment), or comparing completed baseline-vs-quantized results (use compare-results).

    Also in 3 projects that use this

  • GoogleSkill

    prototype

    Build a throwaway prototype to answer a design question. Use when the user wants to sanity-check whether a state model or logic feels right, or explore what a UI should look like.

    Also in 3 projects that use this

  • GoogleSkill

    grill-me

    A relentless interview to sharpen a plan or design.

    Also in 4 projects that use this

  • MicrosoftSkill

    handoff

    Compact the current conversation into a handoff document for another agent to pick up.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 15 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When using Dispatch or Pipeline to spawn autonomous workers, those workers run with --dangerously-skip-permissions because they're headless …

    line 17
  2. Very specific:

    Add to your ~/.claude/settings.json:

    line 68

“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Guardrails

Safety hooks for Claude Code that act as the real enforcement layer when running autonomous workers with --dangerously-skip-permissions.

Why This Matters

When using Dispatch or Pipeline to spawn autonomous workers, those workers run with --dangerously-skip-permissions because they're headless (no terminal to prompt for approval). Without hooks, they can do anything -- force-push to main, delete files, write secrets, modify your Claude config.

Guardrails hooks are the safety net. They fire on every tool use regardless of permission mode, blocking or prompting for dangerous actions.

What's Included

Example Hooks

These are generalised, production-tested hooks. Copy them to ~/.claude/hooks/ and wire them into your settings.json.

HookTypePurpose
bash-precheck.pyPreToolUse (Bash)Blocks destructive commands, protects sensitive paths, gates commits, prevents credential reads
write-boundary.pyPreToolUse (Edit/Write)Restricts file writes to project directory + /tmp, extra restrictions for workers

What They Block

Hard deny (always blocked):

  • git reset --hard, git push --force, git clean -f
  • Writes to /etc/, /usr/, /System/, ~/.ssh/, ~/.aws/, ~/.gnupg/
  • npm publish, pnpm publish, yarn publish
  • DROP TABLE, TRUNCATE TABLE
  • launchctl service modifications, crontab edits
  • Workers modifying Claude config (~/.claude/hooks/, settings.json, CLAUDE.md)

Prompt (ask user, allow or deny):

  • rm -rf and recursive rm
  • Docker destructive commands (docker rm, docker stop, docker system prune)
  • kill -9, killall
  • Outbound data via curl POST / wget --post
  • Writes outside the project directory
  • Reading credential files (~/.ssh/, ~/.aws/, ~/.npmrc/, ~/.netrc/)

Commit gates (blocks commit until fixed):

  • Direct commits on protected branches (main, master, staging)
  • Commits when lint fails
  • Commits when tests fail
  • Pushes from/to protected branches

Installation

1. Copy hooks

cp examples/bash-precheck.py ~/.claude/hooks/
cp examples/write-boundary.py ~/.claude/hooks/
chmod +x ~/.claude/hooks/bash-precheck.py ~/.claude/hooks/write-boundary.py

2. Wire into settings.json

Add to your ~/.claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "~/.claude/hooks/bash-precheck.py" }]
      },
      {
        "matcher": "Edit|Write|MultiEdit",
        "hooks": [{ "type": "command", "command": "~/.claude/hooks/write-boundary.py" }]
      }
    ]
  }
}

3. Customise

Edit the hooks to match your setup:

  • BLOCKED_TOOLS in bash-precheck.py -- add/remove CLI tools that should use package.json scripts instead of direct invocation
  • PROTECTED_BRANCHES -- change from {"staging", "main", "master"} to your branch names
  • SENSITIVE_PATHS -- add paths specific to your environment
  • ALWAYS_ALLOWED in write-boundary.py -- add directories workers should be able to write to
  • CLAUDE_ALLOWED_WRITE_PATHS env var -- colon-separated additional write paths

How Hooks Work

Claude Code hooks fire on every tool use, even with --dangerously-skip-permissions:

Agent calls Bash("git push --force")
  -> PreToolUse hooks fire
  -> bash-precheck.py reads the command
  -> Matches destructive pattern
  -> Returns deny with reason
  -> Command is blocked, agent sees the error

Three possible outcomes:

  • Allow (hook returns nothing) -- tool executes normally
  • Deny (hook returns permissionDecision: "deny") -- tool blocked, agent sees reason
  • Ask (hook returns permissionDecision: "ask") -- user prompted to allow or deny

Workers running headless with --dangerously-skip-permissions never see "ask" prompts -- they auto-approve. This is why the hooks use "deny" for genuinely dangerous operations and "ask" only for things the user might reasonably want to allow.

Worker Safety

The hooks detect worker sessions by checking for /tmp/claude-workers/<session_id>.meta. Workers get stricter rules:

  • Cannot modify Claude config files (hooks, settings, CLAUDE.md)
  • Cannot redirect output to Claude config
  • Same destructive operation blocks as interactive sessions

This prevents a dispatched worker from modifying its own safety constraints.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.