Rules
Updated
Rules are plain YAML files that you own. HoundWatch™ ships example rule sets and forces none. This page covers the format, the check types, where rules live and which wins, the example sets, your written rule documents, and the commands for writing and testing rules.
Every rule file on this page was checked with houndwatch rules validate. The architecture
example was checked with houndwatch rules test.
| Level | Where | Applies to |
|---|---|---|
| User | ~/.houndwatch/, and sets enabled in ~/.houndwatch/ | every project |
| Project | <project>/, and sets enabled in <project>/ | that project |
| Example sets | inside the package | only where a config enables them |
Only *.yaml and *.yml files directly in a rules/ folder load. Drafts in
.houndwatch/ never do.
.houndwatch/rules/ and .houndwatch/config.yaml can be committed with the project. The rest of
.houndwatch/ is local state, and init adds it to .gitignore.
User rules are the floor. A project can add rules and can make a user rule stricter (warn
to block). It cannot weaken or replace a user rule, unless that user rule says
overridable: true. A project rule that tries is reported, and the user rule is kept:
.houndwatch/rules/weaken.yaml:2: rule 'commit-subject-format' cannot weaken the user rule from /Users/you/.houndwatch/rules/commits.yaml (user rules are the floor; a project may only raise warn to block unless the user rule sets overridable: true); kept the user ruleWithin one level, a rule file overrides an example rule with the same id. That is how you tune
one rule from an example set: copy it into a rule file at the same level, keep the id, and
change what you need.
Rule ids must be unique within a level. A second rule with the same id in the same place is reported, and the first one wins.
The project's ignore list (in its config) applies to project rules only. User rules still see
files a project ignores.
A rule file holds a rules: list. Here is a user-level file, ~/.houndwatch/:
rules:
- id: commit-subject-format
says: The first line of a commit message is capitalised and 10 to 72 characters
applies_to:
subject: commit_message
check: pattern
pattern:
must_match: '^[A-Z].{9,71}$'
severity: block
tell_agent: "Rewrite the commit subject: capital first letter, 10 to 72 characters"
- id: no-ai-attribution
says: Commit messages carry no AI tool attribution
applies_to:
subject: commit_message
check: pattern
pattern:
preset: banned-trailers
severity: block
tell_agent: "Remove the AI tool attribution from the commit message"| Field | Meaning |
|---|---|
id | Letters, digits, -, _ and .. Unique within its level. |
says | The rule in one sentence. Shown in rules list and findings. |
applies_to | subject, plus optional paths and exclude (globs relative to the project root) and event. |
check | pattern, structure, llm or command. A mapping with the same name holds its settings. |
severity | block or warn. |
tell_agent | What the agent (and you) are told. Defaults to says. |
baseline | false means touching a file means fixing it: no baseline grace. Default true. |
overridable | On a user rule: lets a project weaken or replace it. Default false. |
Placeholders in tell_agent: {file}, {line}, {count}, {missing}, {reason}, {rule}.
Structure checks with a limit also fill {limit}. Model rules fill {reason} with the model's
one-line answer.
A rule id that starts with codehound- is refused with the new houndwatch- name. See
Upgrading.
subject | What is checked | When |
|---|---|---|
file | one file's content | the agent's edits, the watcher on save, each changed file at commit |
commit_message | the commit message | commit-msg hook, the agent's git commit command, the watcher |
commit | a commit's diff and changed paths | pre-commit hook, the watcher for commits that skipped it |
session | what the agent has done in its session | the agent hook (event: before_first_edit, before_edit, end_of_turn) |
plan | the current plan file | the agent hook (event: session_start, end_of_turn) and after a commit |
blockstops the action: the agent's edit or command is refused, or the commit fails.warnis shown and recorded as a finding, and never stops anything.
Some findings are always warn, whatever the rule says: a skipped model check
(llm-check-skipped), a hook that was skipped or edited, a config or rule file edited by hand.
See Day-to-day use.
Instant. No model, and nothing is run.
| Setting | Meaning |
|---|---|
must_match | text that must be present (a string or a list) |
must_not_match | text that must not be present |
within_lines | only look at the first N lines |
changed_paths_must_not_match | for commit rules: changed file paths that are not allowed |
preset | a built-in list of patterns, used as must_not_match |
flags | letters from imsx. Multiline is always on, so ^ and $ match at each line. |
On a commit, content patterns look only at the lines the diff adds. On a commit_message,
must_match tests the first line unless within_lines is set.
The presets are kept up to date with HoundWatch, so you don't have to maintain the regexes:
| Preset | Finds |
|---|---|
secrets | common key and token shapes, private keys, passwords in URLs, quoted credentials |
env-files | .env files (not .env.example, .sample, .template, .dist), key and certificate files, private SSH keys, credential and service-account files |
backup-files | .bak, .backup, .orig, .save, .copy, .old, editor swap files, names ending in ~ |
banned-trailers | AI tool attribution trailers and "generated with" footers; the tools come from banned_trailer_tools in config |
debug-leftovers | print(, console.log, breakpoint(), pdb.set_trace(), debugger |
todo-markers | TODO, FIXME, XXX, HACK |
Instant. Python files are parsed with the standard library. Other languages get pattern checks
only. A structure mapping names exactly one check:
| Check | Settings | What it checks |
|---|---|---|
max_code_lines | a number | lines of code, comments excluded |
chunk_comments | marker, applies (function, class or both) | a comment containing the marker directly above each function or class |
imports_allowed | package, allow, public_only | import directions between a package's layers |
architecture | checks, declare (or {} to use .houndwatch/) | declared modules, required and forbidden paths, folder conventions |
changed_together | scope (commit or session), when, require | if these paths change, those must change too |
session_has_read | a list of paths | the agent has read these files in its session |
plan_progress | {} | where the plan stands (nudges) |
test_file_exists | test_dir | each module has a test file in the mirrored test location |
fixtures_not_inline | max_lines, fixtures_dir | large mock data lives in fixtures |
fix_changes_a_test | message_matches | a "fix" commit adds or changes a test |
session_has_read paths may use {spec} (the current spec), {read_first_docs} and
{global_rules_dir} (below). changed_together paths may use {today}.
HoundWatch checks these names, their options and their values when it loads rules. It skips a
rule with an unknown name, an unknown option (such as alow: for allow:) or a bad value, such
as max_code_lines: lots. The module names under allow: and public_only: are up to you. Until a human fixes it, commits are
blocked by rules-invalid. Agent edits only get a warning. rules validate shows the file and
line:
.houndwatch/rules/r.yaml:2: rule 'short': unknown structure check 'max_code_line' (did you mean 'max_code_lines'?)Runs in the background through the watcher, never inside a hook. See Local models.
| Setting | Meaning |
|---|---|
prompt | the question. Placeholders: {spec}, {diff}, {file}, {text}, {plan}, {program} |
context | what to supply, e.g. [diff] or [spec, diff] |
tier | auto (the router decides), 1 or 2 |
skip_unless | removes_lines: pass without asking when the change removes no lines in applies_to.paths |
The prompt should ask for PASS or FAIL and one line why.
Runs only at commit (pre-commit), never on an edit or save, because it runs code.
| Setting | Meaning |
|---|---|
run | the command. {tests} becomes the test files for the changed files. Without run, the user config's test_command is used. |
map | how test files are found: mirror (the only one) |
timeout | seconds, default 120. See below for what happens when it runs out. |
tail | lines of output to keep, default 20 |
The command is not run through a shell, and it runs in the project root.
If the command can't run, a trusted block rule blocks the commit. This covers a rule with no
command (no run, and no test_command in your user config), a command that can't start, and
one that times out. The message says how to fix it. If you change a project rule to fix it, trust
the rule again, or it will only warn and its command won't run. Untrusted rules and warn rules
only warn.
A project-level command rule needs your trust. A command rule from a project's rule files, or from a set enabled in the project config, does not run until you trust it. Until then each commit gets one warning:
[warn] tests-pass: command rule tests-pass is not trusted for this project (it runs code): review it, then run `houndwatch rules trust tests-pass`Review the rule, then from your terminal:
houndwatch rules trust tests-passIt shows what the rule will run, asks you to confirm, and asks for a reason. Any later change to the rule needs trust again. Command rules at user level need no trust.
.houndwatch/, with one rule of each kind:
rules:
- id: max-file-length
says: Python files stay within 400 lines of code, comments excluded
applies_to:
subject: file
paths: ["**/*.py"]
exclude: ["tests/fixtures/**"]
check: structure
structure:
max_code_lines: 400
severity: block
tell_agent: "{file} has {count} lines of code; split it into modules under {limit}"
- id: no-print-in-src
says: Source files under src/ use the logger, not print()
applies_to:
subject: file
paths: ["src/**/*.py"]
check: pattern
pattern:
must_not_match: '(?<![\w.])print\('
severity: warn
tell_agent: "Replace the print() at {file}:{line} with the project's logger"
- id: no-key-files
says: Key and certificate files are never committed
applies_to:
subject: commit
check: pattern
pattern:
changed_paths_must_not_match: ['\.(pem|key|p12)$']
severity: block
tell_agent: "Unstage {file}; key files must not be committed"
- id: tests-run
says: The tests covering the changed files pass before a commit
applies_to:
subject: commit
paths: ["**/*.py"]
check: command
command:
run: "pytest -q {tests}"
map: mirror
timeout: 120
severity: block
tell_agent: "Tests fail for this commit: {reason}"
- id: diff-matches-message
says: The commit's diff does what its message says
applies_to:
subject: commit
check: llm
llm:
prompt: |
Diff: {diff}
Does the diff match a short, honest description of the change? Answer PASS or FAIL, then one line why.
context: [diff]
tier: 2
severity: warn
tell_agent: "The change may not match its description: {reason}"
- id: read-api-guide
says: The agent reads the API guide before its first edit
applies_to:
subject: session
event: before_first_edit
check: structure
structure:
session_has_read: ["docs/api-guide.md"]
severity: block
tell_agent: "Read {missing} before editing any file"With owner-standard enabled in the project config, this file in .houndwatch/rules/ replaces
its owner-tests-not-weakened rule: it asks the tier 2 model and only warns. The first trial
used an override like this.
rules:
- id: owner-tests-not-weakened
says: Tests are not deleted, skipped or loosened to make a change pass
applies_to:
subject: commit
paths: ["tests/**", "**/test_*.py"]
check: llm
llm:
prompt: |
Diff: {diff}
Lines starting with "-" were removed, lines starting with "+" were added. Adding new tests is fine.
Does this diff delete tests, add skips, or loosen assertions without a stated reason? PASS or FAIL, one line why.
context: [diff]
tier: 2
skip_unless: removes_lines
severity: warn
tell_agent: "Tests look weakened: {reason}"rules:
- id: no-todo-markers
says: Source files carry no TODO or FIXME markers
applies_to:
subject: file
paths: ["**/*.py"]
check: pattern
pattern:
preset: todo-markers
severity: warn
overridable: true
tell_agent: "Resolve or remove the marker at {file}:{line}"rules:
- id: changelog-with-code
says: A commit that changes source code also updates CHANGELOG.md
applies_to:
subject: commit
check: structure
structure:
changed_together:
scope: commit
when: ["src/**/*.py"]
require: ["CHANGELOG.md"]
severity: warn
tell_agent: "{file} changed: add a line to {missing} in this commit".houndwatch/ declares modules and what each may import, plus required and
forbidden paths:
modules:
api:
paths: ["src/api/**"]
may_import: [core]
core:
paths: ["src/core/**"]
may_import: []
forbidden_paths:
- path: src/utils.py
use: src/core/utils.py
reason: shared helpers live in coreA rule turns it on:
rules:
- id: layers
says: Modules import only in the declared directions
applies_to:
subject: file
paths: ["src/**/*.py"]
check: structure
structure:
architecture: {}
severity: block
tell_agent: "{missing}"What the agent is told for a file in src/core/ that imports from src/api/:
[block] layers: module core may not import module api (src.api); core may import: nothing (src/core/model.py:1)A user-level ~/.houndwatch/ is the floor: a project can add modules and narrow
may_import, never widen it.
All ship inactive. Enable one with houndwatch rules enable <set> (add --user for every
project).
| Set | What it holds | Needs a model |
|---|---|---|
starter | No env, key, credential or backup files committed; no secrets; debug leftovers (warn); files over 500 lines of code (warn); tests not weakened | one rule (starter-tests-) |
tests | Every Python module has a test file; test functions carry a CHUNK COMMENT (warn); no large inline mock data (warn); a fix commit changes a test (warn); the tests covering a commit pass (a command rule) | no |
judgement | Changes stay within the spec (warn); tests not weakened; no new skip or xfail markers | two rules |
progress | Where the plan stands at session start and end of turn (warn nudges) | no |
progress-program | A commit serves the plan and the program target above it (warn) | yes |
docs-in-step | API route changes update the OpenAPI file; a session that changes code updates today's work log and the README status block | no |
architecture-nextjs | Next.js layout: route groups, proxy.ts instead of middleware.ts, pages inside route groups | no |
owner-standard | The HoundWatch author's own standard: MODULE HEADER and CHUNK COMMENT, 450 lines of code, docs in docs/ with timestamps, rule documents and spec read before the first edit, stays on spec, tests not weakened, no secrets, env or backup files, no AI attribution | two rules |
houndwatch-boundaries | HoundWatch's own import boundaries; useful only as an example of imports_allowed | no |
Rule ids differ between sets, so sets can be enabled together. owner-standard is a worked
example of turning a written standard into rules. Use it as a model for your own set, not as a
default.
A few things to know before enabling:
owner-standard'sowner-spec-before-codeblocks the agent's first edit until it has read a spec. With no*-design.mdinspec_dir, it blocks every edit.owner-stays-on-specis awarnrule whose prompt uses{spec}, so it doesn't run when there is no spec (Local models).tests'stests-passneedshoundwatch rules trust tests-passwhen enabled at project level, and reads its test command fromrun. Settest_commandin your user config to use another runner by default.docs-in-step's session rules expectdocs/work-log-andYYYY-MM-DD.md docs/README.md.
Your written rules (a coding standard, a CLAUDE.md, an AGENTS.md) can live anywhere. List
them under rule_docs in your user config, ~/.houndwatch/:
rule_docs:
- path: ~/Projects/library/rules/global.md
read_first: true
- path: ~/Projects/library/rules/stvd.md
read_first: true
- path: ~/Projects/library/rulespathis a file, a folder (every*.mddirectly in it) or a glob (**searches folders).~is your home folder. A relative path is taken from your home folder too.read_first: truemarks a document the agent must read before its first edit. A file listed twice isread_firstif any entry says so.rule_docsis read from the user config only. In a project config it is ignored andrules validatereports it, because it names the documents user rules read.
Where the documents are used:
{read_first_docs}in asession_has_readrule stands for everyread_firstdocument.owner-standard'sowner-global-uses it, so the agent's first edit is refused until it has read them. With norules-read-first read_firstdocuments, the rule passes and says so once.- The session briefing lists them under "Read first" (Day-to-day use).
houndwatch rules lintcompares them with the active rules (below).
global_rules_dir: <folder> is the older setting. It still works: it counts as
rule_docs: [{path: <folder>}], and {global_rules_dir} still fills rules that name it.
houndwatch rules validatehoundwatch: 8 rule(s) validProblems are printed as file: message, with the line where known. The command exits 1. Invalid
rules are skipped; the valid ones still load. It lists all the problems it finds in config and
rule files at once:
- rule files or rules folders that can't be read or parsed;
- invalid rules, unknown check names, bad check values, repeated keys and repeated rule ids;
- mistakes in the config files, and user-only keys in a project config;
- mistakes in an architecture file, if a rule uses it.
Most of these problems block commits until a human fixes them. A user-only key in a project config, or a project rule that tries to weaken one of your user rules, only warns: HoundWatch ignores the key and keeps your rule. Configuration says which config mistakes block. A missing rules folder is fine, and so is an empty rule file.
houndwatch rules test max-file-length src/big.py[block] max-file-length: src/big.py has 410 lines of code; split it into modules under 400 (src/big.py)The target is a file path for file rules, a message file for commit_message rules, and a
commit sha for commit rules. It prints <rule-id>: pass when the rule passes, and exits 1 on a
block. session and plan rules can't be tested this way yet.
houndwatch rules lintIt reads every document rule_docs names, finds file-name conventions in them (such as
.test.py or test_*.py) and compares them with the active rules' paths:
/Users/you/rules/team.md:3: tests-file-exists: the document names test files `<name>.test.py`; the rule expects `test_<module>.py` (.../houndwatch/rules/examples/tests.yaml)
houndwatch: 1 conflict(s) between 1 rule document(s) and the active rules--deep also asks the tier 2 model for contradictions between the documents and the rules'
says lines. If the model can't be reached, the deep part is skipped. Lint never blocks
anything and always exits 0. The first trial found exactly this kind of conflict: a document
asked for <name>.test.py while the rule wanted test_<module>.py.
houndwatch rules draft AGENTS.mdhoundwatch: 3 draft rule(s) in /Users/you/Projects/myapp/.houndwatch/rules/drafts/AGENTS.yaml (inactive)
review them, then run `houndwatch rules accept AGENTS`The tier 2 model reads the document and writes draft rules, each with a comment citing its
source line. Drafts are never enforced. --force replaces an existing draft of the same name.
Review every draft. They are a starting point. In the run used for this guide, "Never commit .env files" became a pattern that would have matched any added line, and "Keep functions under 50 lines" became a 50-line limit on whole files. Command rules are never drafted, because a document from a cloned repository must not be able to propose commands.
Edit the draft by hand, then accept it from your terminal:
houndwatch rules accept AGENTSaccept checks the draft first. It refuses a draft with invalid rules, or with rule ids that
are already active. Otherwise it lists the rules, asks you to confirm and for a reason, and moves
the file into .houndwatch/rules/, where its rules are active. rules validate does not look at
drafts until you accept them.