blockwatch

Some parts of a codebase have to change together: a function and its docs, or a value duplicated across configs.
blockwatch lets you write those rules in comments, right next to the code, or in blockwatch.toml. If they fall out of
sync, your pre-commit hook or CI run fails.
Supports 39 languages.
Quick Start
Install blockwatch:
brew install mennanov/blockwatch/blockwatch
For Windows and other ways to install, see Installation.
Then paste this prompt into your AI coding agent:
Run `blockwatch skill` and follow it to add `<block>` tags, plus `blockwatch.toml` if needed.
Verify your blocks with `blockwatch`, then list each block you added and the mistake it catches.
Review the blocks it adds and commit them. To check every future change, add blockwatch to your
pre-commit hook or CI. You can also install the skill so future agent runs know the
rules too.
How it works
A block is a pair of tags inside comments around some lines of code. The rules go in the start tag. A file that can't
hold a comment, such as JSON, gets its rules from blockwatch.toml instead.
In this example, a web service listens on port 8080, and three files must agree on that number.
app/settings.py holds the value. It needs no tag, because the other files point at the constant by its name,
app/settings.py#/PORT:
PORT = 8080
Dockerfile wraps the line in a block. The pattern \d+ picks 8080 out of EXPOSE 8080:
FROM python:3.13-slim
# <block name="port" same-as="app/settings.py#/PORT" same-as-pattern="\d+">
EXPOSE 8080
# </block>
deploy.json can't hold a comment:
{
"name": "web",
"port": 8080
}
So blockwatch.toml declares its block, around the port key:
[[block]]
target = 'deploy.json#/port'
same-as = 'app/settings.py#/PORT'
If you change PORT to 9090 and forget the other two files, blockwatch fails with exit code 1 and these messages:
Block Dockerfile:port at line 2 disagrees with app/settings.py#/PORT: ["8080"] != ["9090"]
Block deploy.json:(unnamed) at line 1 of "blockwatch.toml" disagrees with app/settings.py#/PORT: ["8080"] != ["9090"]
The output shows the values on each side. Update both files, and the run passes.
A name after # points at a symbol: a constant in code, a key in JSON, TOML or YAML, a Markdown
section, and more. Because same-as compares values directly, it doesn't need a diff. Running blockwatch on its own
finds mismatches anywhere in the repository. The other validators make code and docs change together,
keep lists sorted, and more.
Validators
Two validators work across files:
affects fails when a diff touches a block without also changing what it points to.
same-as fails when a block and its target hold different values. It needs no diff.
Both can point to a block, a whole file, a specific value in a file like package.json#/version, a section of a
Markdown file, an element or attribute in an XML file such as pom.xml or a .csproj, a declaration in a CSS file,
a constant in a Go, C, C++, Python, Rust, TypeScript, JavaScript, Java, C#, Kotlin, Swift, PHP or Dart file, a
variable in a .env file, shell script or Makefile, a field in a Protocol Buffers or Prisma file, or a value in a
Terraform or other HCL file (see Symbols). The other validators check a single block on their own:
the things you'd otherwise have to nitpick in code review.