Karvey Guard
Purpose
A cross-cutting support layer of the Karvey Method — NOT a pipeline phase. It provides the method's guardrails: it manages the enforcement hooks (which do block deterministically via PreToolUse), grants temporary override of the plan-gate, and can apply an edit-lock that restricts Edit/Write to a single directory.
Inspired by gstack's /careful + /freeze + /guard, absorbed as a single skill integrated into the method.
Hard rules:
- It is a cross-cutting skill, not a phase: it does NOT change
spec.json:phase or the change's state.
- The hooks are OPT-IN per project, reversible. They are never imposed globally without the user deciding so.
- Aligned with
karvey/rules/enforcement.md (the canonical rule) and karvey/rules/project-config.md.
It manages the two hooks defined in karvey/rules/enforcement.md, whose templates live in karvey/hooks/:
- git-flow-guard (
git-flow-guard.sh) — PreToolUse over Bash. Blocks direct push to production, commits on dev/master, and manual deploy. Allowed flow: feature/* → integration → PR → production.
- plan-gate (
plan-gate.sh) — PreToolUse over Edit/Write/destructive Bash. Requires an approved plan (the KARVEY_PLAN_FLAG marker, default /tmp/claude-plan-approved) throughout the flow.
Execution steps
ALWAYS read karvey/rules/enforcement.md first to align before touching anything.
Resolve the mode from $ARGUMENTS. If no argument is provided, show the current state (which hooks are registered in settings.json, whether a freeze is active, whether the approval marker exists) and offer the options.
--install — Enable the enforcement hooks
- Locate the project config. Read
docs/spec/project.json (schema in karvey/rules/project-config.md). If it doesn't exist, stop and indicate that karvey-init should be run first. Take branch_flow (feature_prefix, integration, production) to parameterize.
- Copy the templates from
karvey/hooks/ to the project's hooks location (e.g., .claude/hooks/git-flow-guard.sh and .claude/hooks/plan-gate.sh). Keep them executable (chmod +x).
- Register them in the project's
settings.json (.claude/settings.json) as PreToolUse hooks:
git-flow-guard with a matcher over Bash.
plan-gate with a matcher over Edit, Write, NotebookEdit, and Bash.
- Pass the parameterization via the hook command's env, reading
branch_flow: KARVEY_BRANCH_INTEGRATION, KARVEY_BRANCH_PRODUCTION, KARVEY_FEATURE_PREFIX, and optionally KARVEY_PLAN_FLAG.
- Mark
enforcement in project.json: set enforcement.git_flow_hook: true and enforcement.plan_gate_hook: true.
- Confirm to the user what was installed and remind them it is reversible with
--disable-hooks.
--disable-hooks — Disable (reversible)
- Remove the
git-flow-guard and plan-gate entries from the PreToolUse section of the project's settings.json.
- Set
enforcement.git_flow_hook: false and enforcement.plan_gate_hook: false in project.json.
- Leave the templates in
.claude/hooks/ (they are not deleted; only deregistered) so they can be quickly reinstalled.
- Confirm that enforcement is disabled.
--override — Temporary override of the plan-gate
- Present the plan to the user and wait for explicit approval (do not proceed without it).
- Once approved, create the approval marker:
touch "$KARVEY_PLAN_FLAG" (default /tmp/claude-plan-approved).
- The
plan-gate hook will let Edit/Write/destructive Bash through while the marker exists. Inform that this is a one-off grant and that it's best to remove it (rm <flag>) when the approved block of changes is done.
--freeze <dir> — Edit-lock to a directory (boundary)
For sensitive work or debugging: restrict Edit/Write to a single directory.
- Resolve
<dir> to an absolute path and validate that it exists inside the project.
- Install/register a
PreToolUse hook over Edit/Write/NotebookEdit that blocks (exit 2) any write whose file_path is not under the boundary; persist the boundary (e.g., in a KARVEY_FREEZE_DIR marker or a freeze state file).
- Confirm the active boundary and remind that edits are only allowed inside
<dir> until --unfreeze.
--unfreeze — Remove the edit-lock
- Remove the freeze hook from
settings.json and clear the boundary marker/state.
- Confirm that the lock is lifted and that normal edits are allowed again (subject to the other hooks if they are active).
Notes
--install/--freeze edit settings.json and copy scripts: respect the approved-plan gate like any other change.
- This skill complements the phase gates (
karvey-qa, etc.) but does not replace them or approve them on its own.
- After touching artifacts in
docs/spec/, sync knowledge per karvey/rules/knowledge-sync.md.
Part of the Karvey™ Method — © HainTech, by Mauricio Quezada Ibáñez · Apache 2.0 · see karvey/LICENSE and karvey/TRADEMARK.md.
1---2name: karvey-guard3description: Safety guardrails for the Karvey method. Installs/disables the opt-in enforcement hooks (git-flow + plan-gate), grants temporary override, and can edit-lock work to a single directory. Triggers include "karvey guard", "guardrails", "freeze", "edit lock", "activar hooks", "enable hooks", "bloquear cambios", "lock changes", "candado", "lock".4---56# Karvey Guard78## Purpose910A **cross-cutting support layer** of the Karvey Method — NOT a pipeline phase. It provides the method's **guardrails**: it manages the enforcement hooks (which do block deterministically via `PreToolUse`), grants temporary override of the plan-gate, and can apply an **edit-lock** that restricts `Edit`/`Write` to a single directory.1112Inspired by gstack's `/careful` + `/freeze` + `/guard`, absorbed as a single skill integrated into the method.1314**Hard rules:**15- It is a **cross-cutting** skill, not a phase: **it does NOT change `spec.json:phase`** or the change's state.16- The hooks are **OPT-IN per project**, reversible. They are **never** imposed globally without the user deciding so.17- Aligned with `karvey/rules/enforcement.md` (the canonical rule) and `karvey/rules/project-config.md`.1819It manages the two hooks defined in `karvey/rules/enforcement.md`, whose templates live in `karvey/hooks/`:2021- **git-flow-guard** (`git-flow-guard.sh`) — `PreToolUse` over `Bash`. Blocks direct push to production, commits on `dev`/`master`, and manual deploy. Allowed flow: `feature/* → integration → PR → production`.22- **plan-gate** (`plan-gate.sh`) — `PreToolUse` over `Edit`/`Write`/destructive `Bash`. Requires an approved plan (the `KARVEY_PLAN_FLAG` marker, default `/tmp/claude-plan-approved`) throughout the flow.2324## Execution steps2526ALWAYS read `karvey/rules/enforcement.md` first to align before touching anything.2728Resolve the mode from `$ARGUMENTS`. If no argument is provided, show the current state (which hooks are registered in `settings.json`, whether a freeze is active, whether the approval marker exists) and offer the options.2930### `--install` — Enable the enforcement hooks31321. **Locate the project config.** Read `docs/spec/project.json` (schema in `karvey/rules/project-config.md`). If it doesn't exist, stop and indicate that `karvey-init` should be run first. Take `branch_flow` (`feature_prefix`, `integration`, `production`) to parameterize.332. **Copy the templates** from `karvey/hooks/` to the project's hooks location (e.g., `.claude/hooks/git-flow-guard.sh` and `.claude/hooks/plan-gate.sh`). Keep them executable (`chmod +x`).343. **Register them in the project's `settings.json`** (`.claude/settings.json`) as `PreToolUse` hooks:35 - `git-flow-guard` with a matcher over `Bash`.36 - `plan-gate` with a matcher over `Edit`, `Write`, `NotebookEdit`, and `Bash`.37 - Pass the parameterization via the hook command's env, reading `branch_flow`: `KARVEY_BRANCH_INTEGRATION`, `KARVEY_BRANCH_PRODUCTION`, `KARVEY_FEATURE_PREFIX`, and optionally `KARVEY_PLAN_FLAG`.384. **Mark `enforcement` in `project.json`**: set `enforcement.git_flow_hook: true` and `enforcement.plan_gate_hook: true`.395. Confirm to the user what was installed and remind them it is reversible with `--disable-hooks`.4041### `--disable-hooks` — Disable (reversible)42431. Remove the `git-flow-guard` and `plan-gate` entries from the `PreToolUse` section of the project's `settings.json`.442. Set `enforcement.git_flow_hook: false` and `enforcement.plan_gate_hook: false` in `project.json`.453. Leave the templates in `.claude/hooks/` (they are not deleted; only deregistered) so they can be quickly reinstalled.464. Confirm that enforcement is disabled.4748### `--override` — Temporary override of the plan-gate49501. Present the plan to the user and **wait for explicit approval** (do not proceed without it).512. Once approved, **create the approval marker**: `touch "$KARVEY_PLAN_FLAG"` (default `/tmp/claude-plan-approved`).523. The `plan-gate` hook will let `Edit`/`Write`/destructive `Bash` through while the marker exists. Inform that this is a one-off grant and that it's best to remove it (`rm <flag>`) when the approved block of changes is done.5354### `--freeze <dir>` — Edit-lock to a directory (boundary)5556For sensitive work or debugging: restrict `Edit`/`Write` to a single directory.57581. Resolve `<dir>` to an absolute path and validate that it exists inside the project.592. Install/register a `PreToolUse` hook over `Edit`/`Write`/`NotebookEdit` that **blocks** (exit 2) any write whose `file_path` is not under the boundary; persist the boundary (e.g., in a `KARVEY_FREEZE_DIR` marker or a freeze state file).603. Confirm the active boundary and remind that edits are only allowed inside `<dir>` until `--unfreeze`.6162### `--unfreeze` — Remove the edit-lock63641. Remove the freeze hook from `settings.json` and clear the boundary marker/state.652. Confirm that the lock is lifted and that normal edits are allowed again (subject to the other hooks if they are active).6667## Notes6869- `--install`/`--freeze` edit `settings.json` and copy scripts: respect the approved-plan gate like any other change.70- This skill **complements** the phase gates (`karvey-qa`, etc.) but does not replace them or approve them on its own.71- After touching artifacts in `docs/spec/`, sync knowledge per `karvey/rules/knowledge-sync.md`.7273---74*Part of the Karvey™ Method — © HainTech, by Mauricio Quezada Ibáñez · Apache 2.0 · see `karvey/LICENSE` and `karvey/TRADEMARK.md`.*