// book 28
patriola.com

Book 28 · Patriola’s Guide to Claude

Hallway Rules


Every Claude session starts fresh. The rules your agents agreed to follow are gone the moment context clears. This book builds the layer that makes behavioral constraints durable — a governance system agents check, not one they hope to remember.

Buy Ebook on Amazon

Patriola's Guide to Claude — Hallway Rules: Teaching Claude Rules That Stick Across Sessions and Resets
What this book is

A governance layer that agents check

The rule was written into the system prompt. Everyone on the project knew it. Agents confirmed it at the start of each session. And then, three sessions later, an agent violated it — not because it decided to, but because the context had cleared and the rule was gone. Nobody flagged it. The session completed successfully. The damage was quiet.

That failure mode is structural. A system prompt is not a database. Rules written into context exist only for the lifetime of that context. Run enough sessions across enough projects and the question is not whether a constraint will be dropped — it is when, and whether the system will notice.

This book builds the persistent layer. Six artifacts replace hope-to-remember with enforced-at-load: a SQLite rule store that holds constraints outside any session, a cache layer that serves them without a database hit on every lookup, a CLI tool that resolves rules from a routing queue, a constraint enforcer that checks actions before they complete, a diagnostic pass that distinguishes a broken rule from an ambiguous one, and a session hook that loads rules before any agent acts.

What you’ll learn

Six artifacts from rule store to session hook

  • The rule store — A SQLite database that holds behavioral constraints as versioned records with scope, priority, and expiry fields. Why a flat file fails at scale and what the schema buys you when rules conflict.
  • The cache layer — An in-memory cache that serves rules without hitting the database on every lookup. Cache invalidation strategy, TTL discipline, and what happens when a rule is updated mid-session.
  • The CLI lookup tool — A command-line interface for resolving rules from a routing queue. How agents query the store without embedding SQL, and how the queue decouples rule resolution from rule enforcement.
  • The constraint enforcer — The runtime component that intercepts actions, checks them against active rules, and emits a violation signal to the orchestrator before the action completes. The difference between a soft constraint and a hard gate.
  • The diagnostic pass — The process for distinguishing a broken rule (one that was triggered but not enforced) from an ambiguous rule (one that the enforcer could not apply). Why ambiguous rules are more dangerous than broken ones.
  • The session hook — The hook that fires at session start, loads the active rule set into context, and ensures every agent in the session operates against a current snapshot. How to test that rules loaded correctly before any work begins.
From the book

A preview

The session hook is the last line. Every artifact before it builds something worth protecting — the store, the cache, the enforcer. The hook is what makes those artifacts present. A rule stored in SQLite and never loaded into context is a constraint that exists only in theory. Load it wrong and it exists only in the log. Load it correctly, before any agent acts, and it is the first thing the session knows.
You How do I know a rule was actually enforced and not just loaded?
Claude The enforcer logs every check with three fields: the rule ID, the action that triggered it, and the verdict — permitted, blocked, or flagged-for-review. Run rule_log.py --session <id> --verdict blocked to see every action the enforcer stopped. If you want to verify a specific rule fired, filter by rule ID. A rule that loaded but never triggered appears in the load log but not the enforcement log — that is expected. A rule that should have triggered but did not is a diagnostic problem; the diagnostic pass handles that case specifically.
Who it’s for

Claude Code users who need rules to survive resets

This book is for Claude Code users running agents across sessions or projects who have written behavioral rules and watched them vanish at context boundary. The governance layer here does not require Federation (Book 27), but the two books work together: Federation draws the boundaries between nodes; Hallway Rules enforces behavioral constraints inside them. If you have already built the Federation layer, Hallway Rules is the natural next step.

A longer excerpt is available to newsletter subscribers.

Buy Ebook on Amazon

You might also like

More from Patriola

Federation Federation Memory Memory AI Teams AI Teams

Browse all books →

Stay current

New books in this series

One short email per book launch.