A Versioned AI Context Knowledge Base for Every Repo
When an AI coding assistant opens a repository it has never seen, it starts from zero. It reads a few files, guesses at the architecture, and often misses conventions that are obvious to anyone who has worked in the code. Multiply that by every side project I keep, and the same re-learning happens over and over. ir-context-discovery is my attempt to fix that: a protocol for scanning repositories once, writing down what matters, and keeping that knowledge current as the code changes.
Why I built it
I maintain a lot of repositories under the ikppramesh account: web apps, games, AI tools and Android apps. Each one has its own stack, structure and quirks. Whenever I opened one in Claude Code, I had to either re-explain it or let the assistant rediscover it from raw files.
I wanted three things. First, a structured, repeatable way to describe a repository, not an ad hoc summary. Second, a knowledge base that lives in git so changes are reviewable and reversible. Third, a way to keep it from going stale, because documentation that is out of date is worse than none.
What it does
The repository holds two things: the protocol, and the knowledge base the protocol produces.
- The protocol is defined in
CLAUDE.md, which lays out the rules, phases, dimensions and coverage. Supporting pieces are agents in.claude/agents/, slash commands in.claude/commands/and phase prompts inprompts/. - The knowledge base lives in
discovery-output/. The foldersphase-0throughphase-8hold the current merged artifacts, andversions/vNholds immutable snapshots.
A first-time discovery is run by hand in Claude Code with the repos cloned under ../repos/. You run /discovery-start and give it the anchor repository URL or URLs. Then /next-phase begins scanning, and after each phase you run /phase-verify followed by /checkpoint. That repeats through all nine phases, numbered 0 to 8. If you need to stop, /discovery-summary saves progress and /discovery-resume picks it back up.
Keeping it current
A one-time scan is not enough, so a set of commands handles maintenance:
/scan-statusshows the context version and the scan history per repository./staleness-dashboardshows what needs a rescan./incremental-scandetects git changes, rescans only the affected dimensions, merges them into phases 4 to 7, and writes a new version with deltas and a changelog./scan-diff v1 v3compares two versions.
There is also a Context Keeper agent that updates the knowledge base on its own after pushes, rollbacks, agent runs, new repositories and deleted repositories. Its guardrails are documented in .claude/agents/context-keeper.md.
How it works
The project is written mostly in Shell, and that fits what it is. There is no application server here. The protocol is a set of Markdown instructions that Claude Code follows, and git is the storage layer.
The nine phases split the work so that no single pass has to understand everything. The output of each phase is saved as a merged artifact in discovery-output/phase-N. Because phases 4 to 7 are the ones merged by incremental scans, an update can touch only the dimensions affected by a change instead of redoing the whole job.
Every completed discovery or incremental scan produces a new snapshot in versions/vN, and the snapshot is immutable. The top-level phase folders always show the current state, while the version folders give a history you can diff. Versions are also tagged vN in git.
Discovery runs can also be driven from OpenClaw. Its Discovery tab, at openclaw-ir.vercel.app, runs full discoveries and incremental scans on the Mac worker and commits each version to this repository.
Consuming the output from another repo
The knowledge base is only useful if the assistant can read it where it is working. The script scripts/setup-submodule.sh <path-to-repo> adds this repository as a git submodule at .context/ inside the target repository. From there, Claude Code can read discovery-output/phase-6/context/<repo>.ai.md, the per-repository context file written for AI consumption.
What I learned
- Separate current state from history. Keeping merged artifacts in one place and immutable snapshots in another means readers always know where to look, and nothing gets silently overwritten.
- Make updates incremental. Rescanning everything after each commit is slow and noisy. Detecting what changed in git and rescanning only the affected dimensions is the difference between a system you actually use and one you abandon.
- Verification belongs between phases. Having
/phase-verifyand/checkpointas explicit steps makes a long, multi-phase task resumable and checkable instead of a single opaque run. - Use git as the database. Tags, diffs and submodules gave me versioning, comparison and distribution without building any of them.
- Guardrails for automation. An agent that edits the knowledge base on its own needs written limits. That is why the Context Keeper has its guardrails in a file you can read and review.
Conclusion
ir-context-discovery turns the question of what a repository is and how it works into a versioned, diffable artifact that an AI assistant can read on arrival. The pattern is not specific to my repositories: define phases, store current and historical output separately, scan incrementally, and distribute through a submodule. If you work across many codebases with an AI assistant, that structure may save you the repeated explaining.