claude-rules-injector
Auto-inject a "critical rules" prompt at the start of every turn in Claude Code, plus a r-check skill for on-demand rule lookup.
claude-rules-injector is a tiny, auditable layer on top of Claude Code that solves one problem: rules you write in CLAUDE.md are advisory — they may lose salience as the session grows. This package wires the same rules into a UserPromptSubmit hook, so they are re-attached as additionalContext on every prompt. Violations short-circuit the task instead of leaking through.
It is opinionated: 13 rules, English summaries with Japanese author-original quotes preserved verbatim per R16. Fork it, edit critical-rules.md, and reinstall — the wiring is the value, the rules are an example.
Status: Personal config dump, MIT-licensed for forking. The author uses this for their own workflow; no SLA, support guarantee, or roadmap. Issues and PRs are welcome but may be answered slowly or not at all. The bundled critical-rules.md is an example — replace with your own rules before relying on it.
Install
Option A — Plugin (recommended, Claude Code v2.x+)
Inside Claude Code:
/plugin marketplace add hinanohart/claude-rules-injector
/plugin install claude-rules-injector@claude-rules-injector
/reload-plugins
The plugin bundles critical-rules.md, the hook, and the r-check skill (namespaced as /claude-rules-injector:r-check). Updates flow via the marketplace; no manual settings.json edits.
Option B — Manual install (legacy / for older Claude Code)
git clone https://github.com/hinanohart/claude-rules-injector.git
cd claude-rules-injector
bash install.sh
The installer:
- copies
critical-rules.md to ~/.claude/critical-rules.md
- installs the hook at
~/.claude/hooks/inject-rules.sh
- installs the
r-check skill at ~/.claude/skills/r-check/
- registers the hook in
~/.claude/settings.json (idempotent; creates .bak.<epoch>-<pid> backup before any edit)
Restart Claude Code after install. To confirm it works, send any prompt — the rules are re-attached as additionalContext on every turn.
Previously named claude-guardrails. Old URLs redirect; clone URLs still work via GitHub's auto-redirect.
How it works
Path resolution order for the rules file:
CLAUDE_RULES_PATH env var
- First line of
~/.claude/critical-rules.path
- Default:
~/.claude/critical-rules.md
Disable / customize
| Goal | How |
|---|
| Temporarily disable injection | export CLAUDE_RULES_DISABLE=1 |
| Use your own rules file | export CLAUDE_RULES_PATH=/path/to/rules.md |
| Pin a path persistently | echo /path/to/rules.md > ~/.claude/critical-rules.path |
| Look up one rule | invoke the r-check skill or run ~/.claude/skills/r-check/check.sh R11 |
Uninstall
Plugin install:
/plugin uninstall claude-rules-injector@claude-rules-injector
Manual install:
bash install.sh --uninstall
The manual uninstaller writes a fresh settings.json.bak.<epoch>-<pid>, then edits settings.json in place to remove only the claude-rules-injector hook entry (sibling hooks are preserved). It removes the hook script and the skill. If $HOME/.claude/critical-rules.md was modified after install, it is preserved as critical-rules.md.bak.<epoch>-<pid> instead of being deleted.
What's in the rules
13 rules across three priority tiers. Lines prefixed with 🔥 reproduce the original Japanese wording verbatim and should not be reworded (see R16); each is followed by an English paraphrase and an operational line.
| Tier | Rules | What they cover |
|---|
| 1 (immediate stop) | R11, R13, R15 | Secret handling, security isolation, cross-session contamination |
| 1.5 (special protocol) | R14, R16, R17 | Pre-large-work possibility-exploration, 100% intent comprehension, write-target audit |
| 2 (auto-progress) | R1, R2, R5, R7, R8, R12, R18 | Response style, code quality, evidence, auto-progress, failure museum, agent-bash, web-search reality-check |
The numbering has intentional gaps (R0/R3/R4/R6/R9/R10 are omitted) because some rules are locale- or person-specific and shouldn't be redistributed as defaults. Gaps are preserved so downstream tooling that addresses rules by ID stays stable across forks.
See critical-rules.md for the full text.
Non-goals