К основному содержанию
скилл CX Codex

agent-guardrails — скилл для Claude Code: что делает и как установить

Защищает репозиторий от деструктивных действий агента с помощью хуков PreToolUse, правил permissions.deny и барьеров верификации.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add rainmanjam/poka-yoke --skill agent-guardrails -a claude-code
Открыть на GitHub

Что делает agent-guardrails

Обычные указания в CLAUDE.md стираются при сжатии контекста и игнорируются субагентами. Скилл переносит ограничения на уровень технических барьеров. Он помогает составить правила запрета для перехвата git push --force, блокировки чтения и правок .env, а также запрета прямых коммитов с флагом --no-verify.

Подход закрывает три частые проблемы: необратимый вред веткам и базам данных, правдоподобный нерабочий код и ложные заявления агента об успешных тестах. Для каждого случая задаётся проверка на границе инструмента: если агент получает отказ, сообщение должно чётко объяснять причину и давать безопасную альтернативу.

Правила permissions.deny сверяют только начало строки вызова. Для перехвата составных команд вроде rm -rf или запросов DELETE без условия WHERE текстовой маски мало: здесь потребуется отдельный скрипт хука PreToolUse.

Какие задачи решает

  • заблокировать git push --force и пропуск проверок при коммите
  • закрыть агенту чтение и редактирование переменных в .env
  • перехватить опасные SQL-команды без условий до их выполнения
  • настроить запуск тестов для проверки реальной готовности задачи

Примеры запросов агенту

  • Помоги составить правила permissions.deny для защиты файлов окружения и ветки main
  • Напиши PreToolUse хук, который блокирует удаление таблиц без подтверждения
  • Настрой проверку типов и тестов перед тем, как агент объявит задачу завершённой

Как установить agent-guardrails

1Через Skills CLI (Vercel)

npx skills add rainmanjam/poka-yoke --skill agent-guardrails -a claude-code

2Вручную: положить файлы

~/.claude/skills/agent-guardrails/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/agent-guardrails/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о agent-guardrails

Как установить agent-guardrails в Claude Code?

Выполните команду npx skills add rainmanjam/poka-yoke --skill agent-guardrails -a claude-code в терминале.

Что делает скилл agent-guardrails?

Он помогает внедрить технические барьеры вместо ненадёжных инструкций в промптах: настраивает правила отказа в settings.json и хуки проверок.

Почему правил в CLAUDE.md недостаточно для безопасности?

Инструкции в файлах проекта выпадают из контекста при долгих сессиях, а субагенты могут их вообще не читать. Ограничения на уровне вызова инструментов срабатывают до запуска команды.

Исходный текст

SKILL.md · MIT
---
name: agent-guardrails
description: >-
  Stop an AI agent damaging your repo: PreToolUse hooks, permission deny rules, protected paths, verification gates. Use when "claude keeps force pushing", "CLAUDE.md says X but it still does Y", "stop the agent touching prod or .env", or making a repo safe for unattended agent work. For AI features you ship to users use llm.
---

# Poka-Yoke for AI-Written Code

An agent is a fast, tireless operator with no memory of yesterday and a strong prior toward
appearing successful. That is the exact profile Shingo designed poka-yoke for, except an
agent makes mistakes faster than any human, and never learns from the ones you correct in
conversation.

The governing insight: **instructions to an agent are rung zero.** A line in CLAUDE.md saying
"never commit to main" is training, and training degrades, under long contexts, compaction,
and subagents that never read the file. A PreToolUse hook that denies the push is a device. If
you have been repeating the same correction to an agent, that is the signal to stop writing
instructions and install a device.

## A complete answer covers all five

**The diagnosis is not the answer.** "Instructions are not enforcement" is the right insight,
and it is satisfying to write, but someone asking *"what am I doing wrong?"* has a repo they
need to fix: not a question about their prose. Explaining why the rules fail and stopping
there leaves them exactly where they started. State the insight in a sentence, then spend the
rest of the answer on the replacement.

Replacing an instruction with a device is not one step, it is five, and stopping after the
first leaves the person with a rule that looks enforced and is not. Naming the deny rule is
the easy part and the least of it. Cover every one of these, briefly, before adding depth:

1. **The deny rule, with real syntax.** Show the actual `permissions.deny` entry for their
   case, `"Bash(git push --force:*)"`: not a description of one. A pattern they have to
   invent themselves is a step where this fails.
2. **A hook where a pattern is not enough.** Deny rules match strings. Anything conditional: a `DELETE` without a `WHERE`, an edit allowed in one directory but not another, a
   production hostname, needs a `PreToolUse` hook that inspects the call and returns a deny.
   Say which of their two rules needs which.
3. **What the deny message says.** The agent reads it and acts on it, so a bare refusal
   produces a workaround, often a worse one. The message must name what was blocked, why, and
   what to do instead. This is the one place prose belongs in a device.
4. **Where the config lives, so it applies to everyone.** `.claude/settings.json`, committed.
   A rule in `settings.local.json` protects one machine, which is the same failure as
   documenting it: the protection exists only where someone remembered to set it up.
5. **Proof that it fires.** Run the blocked action and confirm the denial *and* its message,
   then run the legitimate neighbouring action and confirm it still works. Untested hooks fail
   open more often than people expect: a regex that does not match the real command string is
   a hook that does nothing while looking like protection. **An unverified device is worse
   than no device, because it creates confidence without protection.**

Steps 3 and 5 are the ones most often dropped, and they are what separate a device that works
from one that merely exists.

## The three failure modes, and the device for each

**1. The agent does something destructive.** Force-push, `rm -rf`, dropping a table, editing
`.env`, running against production, `git checkout .` over uncommitted work, `--no-verify`.
These are irreversible and fast. Device: **deny at the tool boundary**: a hook or permission
rule that refuses the call before it executes. This is Control and it is the only rung that
matters for irreversible actions.

**2. The agent writes code that looks right and isn't.** Plausible-but-wrong is an agent's
characteristic defect: correct-looking imports of things that don't exist, tests that assert
nothing, error handling that swallows, a stub that returns a hardcoded value. Device: **the
type checker and the test suite as required gates**, plus lint rules against silent failure.
Everything in `guardrails` applies here with extra force, because the volume of
generated code is higher and human review attention per line is lower.

**3. The agent reports success it didn't achieve.** "All tests pass" when the suite wasn't
run; "done" with the build broken. Device: **verification the agent cannot fake**: a Stop
hook that actually runs the tests, or a CI gate. Never accept a claim of completion that only
exists as text.

## Devices, strongest first

### Deny rules in settings.json

The cheapest device and the first thing to install. Permission denies are evaluated before the
tool runs and need no scripting:

```jsonc
{
  "permissions": {
    "deny": [
      "Bash(git push --force:*)",
      "Bash(git push -f:*)",
      "Bash(git commit --no-verify:*)",
      "Read(./.env)",
      "Read(./.env.*)",
      "Edit(./.env)",
      "Edit(./migrations/**)",
      "Bash(terraform apply:*)"
    ]
  }
}
```

Reading `.env` matters as much as writing it: an agent that reads a secret can echo it into a
log, a commit, or a message to a third-party service. Deny the read.

A deny entry matches the **start** of the command, so it only holds where the dangerous form
is the prefix. That is why `rm -rf` is not on this list: `"Bash(rm -rf /:*)"` would leave
`rm -fr /`, `rm -Rf /` and `cd / && rm -rf *` untouched while looking like coverage.
Recursive delete needs the hook below, see the `rm` pattern in
`../../assets/devices/claude-hooks/guard_dangerous_commands.py`.

Put team-wide rules in `.claude/settings.json` (committed) and personal ones in
`.claude/settings.local.json` (gitignored), otherwise the rules exist only on the machine of
whoever set them up, which is the same failure as documenting them.

### PreToolUse hooks for anything conditional

When the rule needs logic, "block `DELETE` without a `WHERE`", "block edits to
`schema.prisma` unless a migration exists", "block production hostnames in a connection
string": a hook script inspects the call and returns a deny with a reason.

Templates in `../../assets/devices/claude-hooks/`. The critical detail:
**the deny message is read by the agent and is your only chance to redirect it.** A bare
"denied" produces a workaround attempt, often a creative and worse one. A message that says
what was blocked, why, and what to do instead produces the right action. Write it as you would
write an error message for a colleague:

> Blocked: `DELETE` without a `WHERE` clause on `users`. Unbounded deletes are irreversible
> here. Add a `WHERE` clause, or if a full truncate is genuinely intended, ask the user to
> confirm and run it themselves.

### Stop hooks that verify completion

Run the type check and the test suite when the agent tries to finish. This converts "tests
pass" from a claim into a fact, and it is the single highest-value hook in most repos.

### Machine-checkable CLAUDE.md

Anything in CLAUDE.md that *can* be a check should be one; what remains should be facts the
agent needs rather than rules you hope it follows.

- "Always run `make fmt` before committing" → a pre-commit hook.
- "Never use `any`" → a lint rule with a required check.
- "Don't edit generated files" → a deny rule, plus a header in the generated files.
- "Use `pnpm`, not `npm`" → a deny on `Bash(npm install:*)` with a message naming `pnpm`.

What legitimately stays as prose: architecture, domain vocabulary, where things live, why
past decisions were made. Facts, not commands.

### Make the safe path the easy path

Agents follow the shortest route to a working answer. If `make test` runs the right thing with
the right env, it gets used; if the correct invocation is a fifteen-flag command documented in
a wiki, it does not. Every ergonomic improvement here is a poka-yoke: a `make check` that
bundles fmt + lint + types + tests, a `.env.example` with every key present, a devcontainer or
a single setup script. Ambiguity is where agents improvise, and improvisation is where damage
comes from.

## A caution about over-restriction

Deny rules that block ordinary work produce an agent that spends its turns fighting the
harness, and a user who turns the rules off. Aim the strong devices at **irreversible and
outward-facing** actions, force-push, prod, secrets, destructive SQL, deletion, publishing, and leave ordinary editing and reading alone. Reversibility is the right axis: git makes most
code changes cheap to undo, so they do not need a gate. A rotated credential and a dropped
table do not.

## Verify each device

Same discipline as any other guardrail, and easy to check here: try the blocked action and
confirm the denial and its message, then confirm the legitimate neighbouring action still
works. Untested hooks fail open surprisingly often: a regex that doesn't match the real
command string is a hook that does nothing while looking like protection.

Leave a `poka-yoke:` marker comment on each rule naming what it prevents, and show the user
each config before writing it. Hooks execute code on their machine on every tool call; that is not a change to
make on someone's behalf unseen.

© rainmanjam · MIT · rainmanjam/poka-yoke

Похожие скиллы

Все скиллы по теме «Настройка агента: память, контекст, субагенты» →
setup-matt-pocock-skills Matt Pocock Скилл настраивает репозиторий для инженерных скиллов Matt Pocock: задаёт трекер задач, метки триажа и расположение доменной документации. Запустите его перед первым использованием остальных скиллов. 1 052 851установок ask-matt Matt Pocock Помогает выбрать подходящий скилл или рабочий поток из набора Matt Pocock. Пригодится, когда непонятно, с чего начать задачу: от идеи до разбора бага. 766 587установок to-tickets Matt Pocock Разбивает план, спецификацию или переписку на небольшие сквозные задачи и отмечает, какие из них блокируют остальные. Пригодится, когда нужно согласовать порядок работы до публикации задач в трекере. 711 230установок writing-plans Jesse Vincent Скилл превращает требования к многошаговой задаче в подробный план реализации до начала работы с кодом. Пригодится, когда исполнителю нужно зафиксировать файлы, интерфейсы и проверки. CX Codex 282 859установок caveman-review JuliusBrussee Пишет замечания к коду одной строкой: место, проблема, исправление. Пригодится, когда ревью диффа или PR надо пройти быстро и без воды. CX Codex +1 411 800установок caveman-compress JuliusBrussee Сжимает CLAUDE.md, списки задач и другие текстовые файлы в краткий формат, сохраняя читаемую резервную копию. CX Codex +1 411 500установок

Из того же набора20

poka-yoke Скилл разбирает, как ошибка превращается в дефект, и предлагает встроенную защиту для кода, схемы или процесса. Пригодится, когда нужно сделать действие труднее выполнить неправильно. CX Codex +1 ★ 24звёзд репо ops Помогает оценить радиус поражения перед выкаткой: что необратимо, что ломается в окне деплоя и как быстро откатиться. CX Codex +1 ★ 24звёзд репо llm Помогает проектировать надёжные LLM-фичи для пользователей: валидацию схем, защиту от инъекций и контроль опасных вызовов инструментов. CX Codex +1 ★ 24звёзд репо guardrails Помогает внедрять проверки в проект: от сканирования секретов до обязательных проверок CI. Пригодится, когда правил в документации уже недостаточно. CX Codex +1 ★ 24звёзд репо design Скилл проектирует API, схемы и машины состояний так, чтобы некорректное обращение просто не выражалось в коде. Пригодится, когда пишешь новый интерфейс и не хочешь миграций потом. CX Codex +1 ★ 24звёзд репо data Помогает выявлять скрытые ошибки в хранилищах данных, dbt-моделях и метриках, когда пайплайн завершается без сбоя, но выдаёт неверные цифры. CX Codex +1 ★ 24звёзд репо authz Скилл ищет пути к межтенантным утечкам и помогает встроить проверку доступа в запросы, репозитории и маршруты. CX Codex +1 ★ 24звёзд репо audit Ищет в уже написанном коде места, где легко ошибиться незаметно: перепутанные аргументы, молчаливые фолбэки, удаление без проверок. CX Codex +1 ★ 24звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой