Skip to content
youdede

Protected branch guard

OperationsHookv1.0.0

A deterministic Claude Code PreToolUse hook that discovers the current and repository-default Git branches with bounded subprocesses, blocks native file changes on protected branches, and parses static shell envelopes for narrow history mutation, deletion, and direct-push cases.

Runs on

Scope
$npx @youdede/toolkit add protected-branch-guard --target claude-code

What it does

Block native edits and direct Git mutations that target a protected branch.

When it fires

  • implementation
  • pre-commit
  • release

How it behaves

Discover protected Git branch context and reject narrow native or static command mutations before execution.

It does not create a branch, commit, checkpoint, merge, rebase, delete, or push on the user's behalf.

It does not accept a project-writable allowlist, environment switch, command comment, or embedded approval as a bypass.

It does not claim to protect server-side branch rules or arbitrary repository mutations performed by non-native tools.

Configuration

targets/claude-code/protected-branch-guard.mjsnode · read-only

Version
1.0.0
Requires
Shell command guard
Licence
RiskThis automatic gate blocks native edits and direct Git mutations that target a protected branch; a false denial can interrupt legitimate work, but it does not execute the blocked action.
Medium
ModeHow it works: fixed rules, model instructions, or both.
Deterministic only
Behaviour
Enforces, blocks on violation
On failure
Denies and blocks
LatencyTo block native edits and direct Git mutations that target a protected branch, the entrypoint may run a bounded local subprocess before returning.
Bounded
Data retentionWhether data remains after use and who manages its storage.
Not retained

Often used with

All in Operations