Readable code answers what. It cannot answer why this and not the obvious
alternative, what bit us here before, or what breaks if you "simplify" this.
Comments are the usual home for that and they rot — they duplicate the code,
drift from it silently, and nothing ever tells you they have stopped being true.
koment puts that reasoning beside the code instead: prose anchored to a
verbatim snippet, stored in .koment/ in git, reviewable in the same pull
request as the change that motivated it. Then it checks the anchor. When the
annotated code changes, koment check fails the build rather than serving a note
that no longer describes anything.
Your agents read it too. One MCP server gives Claude Code, Cursor, Codex, Zed,
Hermes and the rest the same reasoning through the same interface — because an
agent that cannot see why something was built a certain way will happily
refactor the reason away.
See it running → — koment's own
annotations, rendered by koment onto GitHub Pages by the workflow you can
copy.
How it works
-
You annotate a snippet. koment records the prose, the excerpt and its
SHA-256, the commit you were on, and who you are.
-
The record lands in .koment/annotations/<mirrored path>.yaml, one file per
annotated source file. It is YAML, it is in git, and it diffs line by line.
-
Resolution searches the current file for that excerpt and produces exactly
one status:
|
meaning |
build |
ok |
found where it was last seen |
passes |
moved |
still there, different line |
passes |
drifted |
file exists, the annotated code is gone |
fails |
orphaned |
the file is gone |
fails |
-
koment check exits non-zero on drifted or orphaned. That is the whole
mechanism: an annotation nobody revisited is worse than no annotation, so it
has to be impossible to ignore.
-
When it fails, koment reanchor <id> --excerpt '<new text>' repoints it —
keeping its id and creation date, recomputing the hash and line for you.
Nothing re-attaches automatically; a person confirms the reasoning still holds.
Anchoring is by excerpt, never by line number — line numbers rot on the next
edit above them. The commit hash is recorded, but only to reconstruct history;
it never decides whether an annotation still applies. Two questions, two
mechanisms (ADR 0014).
koment is read-only over the network. The UI and the MCP server serve; they
never write. Annotations are created by the CLI, by a person or an agent with a
checkout — so a published instance exposes no way for a visitor to change
anything.
Three ways to run it
Pick one. Each is a place to stop, not a step you have to take, and moving
between them is not a migration — all three read the same .koment/ in git,
so there is nothing to export, import or back up
(ADR 0026).
|
you run |
you get |
| local |
the CLI, and koment mcp in your agent's config |
annotate, koment check, agents read the reasoning. Nothing to host. |
| published |
one workflow file → GitHub Pages |
everyone reads the annotations in a browser. No server, no auth to design, no cost. |
| served |
the container or the Helm chart |
the live working tree, several repositories, search across them, metrics |
Quick start
go install github.com/janpuc/koment/cmd/koment@latest
No Go toolchain? Every release carries binaries for linux, macOS and Windows on
amd64 and arm64, with checksums —
grab one.
cd ~/your-project
koment add src/auth.go \
--excerpt 'if token.Expiry.Before(now.Add(-clockSkew)) {' \
--kind gotcha \
--body 'The skew subtraction is deliberate. Without it, clients whose clock
runs fast get logged out mid-request. Bit us in #412.'
koment check # green
koment ui # look at it
Now edit that line and run koment check again. It fails — because the reasoning
you wrote no longer describes the code, and silently keeping it is exactly how
comments rot.
Or run the viewer against a checkout with the container:
docker run --rm -p 8080:8080 -v "$PWD:/repo:ro" ghcr.io/janpuc/koment:latest
Several repositories
One deployment serves many. Identity is assigned, so a repository that moves
keeps its annotations and its index (ADR 0024):
# KOMENT_CONFIG=/etc/koment.yaml
repositories:
- id: payments # assigned once; never derived from the path
name: Payments API
root: /repos/payments
clone_url: https://github.com/you/payments
default_branch: main
- id: web
root: /repos/web
Or, for a container with a couple of mounts and nothing else to say:
KOMENT_REPOS=payments=/repos/payments,web=/repos/web
A single repository needs none of this — koment finds it by walking up from the
working directory, exactly as before.
Kubernetes
koment publishes an OCI Helm chart to oci://ghcr.io/janpuc/charts/koment:
helm install koment oci://ghcr.io/janpuc/charts/koment \
--set repository.clone.enabled=true \
--set repository.clone.url=https://github.com/you/your-repo \
--set metrics.enabled=true \
--set metrics.serviceMonitor.enabled=true \
--set metrics.dashboard.enabled=true
Metrics land on a separate port from the serving one — the serving port is
unauthenticated and ingress-facing, and /metrics must not inherit that
(ADR 0020). The
chart ships a Grafana dashboard the sidecar discovers by label. Its headline
panel is drift over time, which is the one question koment check cannot answer,
because it only ever sees one moment.
Configuration
Every flag can be set from the environment, which is how you configure the
container. --flag-name becomes KOMENT_FLAG_NAME, and an explicit flag always
wins.
|
|
KOMENT_REPO |
one repository; defaults to the working directory |
KOMENT_REPOS |
several: api=/repos/api,web=/repos/web |
KOMENT_CONFIG |
a YAML registry, for per-repository settings |
KOMENT_LISTEN |
address for koment ui |
KOMENT_HTTP |
address for koment mcp --http |
KOMENT_STREAMABLE_HTTP |
address for koment mcp --streamable-http |
KOMENT_METRICS |
address for the metrics listener; off unless set |
KOMENT_OUT |
output directory for koment export |
KOMENT_INDEX |
SQLite index file; defaults to the cache directory |
KOMENT_DATABASE_URL |
use Postgres for the index, which makes the service stateless |
.koment/ bootstraps the index when it is empty, and koment export rebuilds
.koment/ from the index — byte-identically. Either can be lost without losing
annotations.
koment <command> --help lists every flag alongside its variable.
Give it to your agents
koment mcp # stdio; also --http / --streamable-http for remote agents
Three tools:
koment_get(file, repository?) — annotations for the file an agent is about to edit
koment_search(query, repository?) — find reasoning by topic; omitting repository searches all of them
koment_repositories() — what this deployment serves, with counts
Every annotation arrives with its resolution status and its repository, so a
stale one is never presented as current and a result is never detached from its
scope. When a path exists in several repositories koment_get refuses and
names the candidates rather than guessing (ADR 0025).
Publish it
Your reviewers are not going to install anything. Give them a URL: one workflow
file renders every annotation to static HTML and puts it on GitHub Pages, with
no server, no database and no authentication to design.
- uses: actions/checkout@v5
- uses: janpuc/koment@v0.2.0
- run: koment check
- run: koment site --out dist
Every page names the commit it was rendered from, so a snapshot can never pass
for the current tree. koment check in the same workflow means a build that
would publish drift fails first.
The whole workflow, ready to copy →
A site renders your source as well as your annotations, so publishing one from a
private repository publishes that source. One repository per site, by design —
a static page has no server to resolve a repository against, and faking one
would be worse than the limit.
Documentation
What koment is not
- Not a replacement for ADRs. Project-wide decisions belong in a decision
record; koment holds knowledge bound to a place in the code.
- Not a memory system. A consolidating store paraphrases, merges and
eventually forgets. koment is a record, not a belief
(ADR 0004).
- Not line-precise. Anchors are snippets
(ADR 0003).
Prior art
Codetations / Magic Markup is the
closest existing work — document-external annotations with LLM re-anchoring. The
anchoring problem dates to Microsoft Research, 2001
and is still unsolved in the general case. The UI owes its shape to
konflate, which makes an
invisible layer visible for Flux the way koment tries to for rationale.
License
MIT