kb command line¶
The kb command is the tooling of a knowledge base, installed in its
.venv by uv on the first uv run. Run it from anywhere inside the
repository:
The tasks (uv run poe …) are short names for the commands
used most.
With the global launcher installed, kb <command>
works inside any knowledge base, and elsewhere with -C, $KB_DIR or a
configured default.
Finding the knowledge base¶
kb looks for the repository root, the nearest directory at or above the
current one that contains schema/vocabulary.yaml. KB_REPO_ROOT, when
set, overrides the search.
The bundle is the knowledge-base folder: <root>/<folder>, where <folder>
is bundle in the [tool.kb] table of pyproject.toml. It is named after
kb_name by default, and is kb when the table or the key is missing, as in
knowledge bases created before v0.5.0. --bundle overrides it. See
Repository layout.
| Global option | Meaning |
|---|---|
--bundle PATH |
Bundle root (default: the knowledge-base folder, <repo>/<folder>). Goes before the command. |
--tracked |
Read only the files git tracks or has staged, that is what a commit contains. The pre-commit hooks use it. Goes before the command. |
The bundle's files are the ones git would commit: in a git repository, the
files of the knowledge-base folder that are tracked, or untracked and not
ignored; outside a repository, all of them. Files below a dot-folder
(.obsidian/, .trash/) are never part of the bundle. Every command reads
the same set of files.
Paths given to check and fix-links may be relative to the current
directory, to the repository root, or to the bundle (with or without a
leading <folder>/ or /). new, mv, merge, unlinked,
import --into and zotero --path take bundle paths only (a leading
<folder>/ or / is accepted), and so do find --folder and the
links: values of an import mapping. With a
knowledge-base folder named my-kb, my-kb/ai/llm.md, /ai/llm.md and
ai/llm.md name the same page. Bundle paths are normalized: ./ai/llm.md,
ai//llm.md and ai\llm.md name it too, and a path that leaves the
bundle (../README.md) is refused.
A leading <folder>/ is stripped only when the path does not also exist
inside the bundle: if the path, or its parent folder, exists inside the
knowledge-base folder, it is read as a bundle path. So when the bundle
holds a folder with the same name as itself, such as a domain my-kb/ in
the knowledge-base folder my-kb/, my-kb/page.md means the page in that
domain. Copier and kb rename-bundle refuse such
names, but a domain added later can still create one.
Messages show pages as the repository sees them, <folder>/<path>, for
example my-kb/ai/llm.md:12: W030 … or wrote my-kb/index.md. With
--bundle pointing outside the repository, <folder> is the name of that
directory.
Exit status: 0 on success, 1 on failure. kb check and kb index --check
use 1 for "problems found". Usage errors (an unknown option, a missing
command) and the hooks' blocking results use 2 (see kb hook).
Every command loads .env from the repository root first; variables already
set in the environment take precedence.
The programs kb runs (git, qmd, node, markitdown, uvx) are looked up only
in the absolute directories of the PATH, never in the current directory or
in an empty or relative PATH entry, so a git.exe or qmd.cmd committed
to a knowledge base never runs in its place. On Windows, kb setup runs
cmd.exe by its full path.
Commands¶
| Command | Purpose |
|---|---|
check |
Validate OKF conformance and house rules |
index |
Regenerate every index.md |
fix-links |
Rewrite internal links as bundle-absolute /paths |
mv |
Move or rename a page or file and rewrite inbound links |
merge |
Fold a duplicate page into another |
new |
Create a page skeleton with valid frontmatter |
log |
Add an entry to the bundle's log.md |
find |
List pages by frontmatter |
folders |
Print the indexed folders and their descriptions |
search |
Search the pages: qmd when set up, otherwise text search |
eval |
Retrieval evaluation: do the search tiers reach the expected pages? |
report |
Health report |
graph |
Link-graph analytics |
dupes |
Near-duplicate candidates |
unlinked |
Unlinked mentions of other pages |
zotero |
Read-only Zotero access |
karakeep |
Archive a web page in KaraKeep |
fetch |
Text of an external resource into .cache/sources/ |
open |
Open an external resource |
import |
Convert an Obsidian vault or Logseq graph |
obsidian setup |
Install the pinned Obsidian plugins and open the vault |
setup |
First-time setup of a clone |
rename-bundle |
Rename the knowledge-base folder |
hook |
Agent hook entry points (Claude Code, Codex, Gemini CLI) |
kb check¶
Validate OKF v0.2 conformance and the house rules. Prints one line per
diagnostic, path:line: CODE message, then a summary on stderr.
| Argument or option | Meaning |
|---|---|
PATHS |
Only check these .md files. Only they are read, so the check is fast on a large bundle; links to other pages are checked against the list of files. Bundle-level checks (folders in the taxonomy, index freshness, resources.yaml) are skipped. A file outside the bundle (ignored, or below a dot-folder) is refused. |
--strict |
Exit 1 on warnings too. |
--errors-only |
Print errors only (warnings still count in the summary). |
Exits 1 when there is at least one error. The codes are listed in Check codes.
kb index¶
Regenerate every index.md from frontmatter and schema/taxonomy.yaml, and
delete the ones left in folders that no longer hold pages. Prints
wrote <path> or deleted <path> for each change. Titles and folder titles
are written on one line: line breaks and runs of spaces become one space.
| Option | Meaning |
|---|---|
--check |
Write nothing; print each index that kb index would change (out of date: <path> or orphaned: <path>) and exit 1 if there is any. |
kb fix-links¶
Rewrite internal links as bundle-absolute /paths. A link is resolved
relative to the linking file first, then relative to the bundle root; a
link that resolves to nothing is left as it is. Generated index.md files
are skipped.
The links it reads, and kb mv and kb merge rewrite:
- inline links and images of the body;
- reference definitions,
[label]: /path.md; - frontmatter values that are exactly one link,
[text](/path.md), under any key and at any depth, in block or flow collections (relations); - frontmatter
resourcevalues that are not URLs, such assources[].resource.
Only the changed values are edited, so the rest of the frontmatter keeps its
layout, comments, anchors (&name) and tags (!!str). A changed value
written as a block scalar (| or >) becomes a double-quoted one. The file
keeps its byte order mark and its line ends; a file with mixed line ends
gets \r\n everywhere.
Not rewritten: HTML attributes (<img src="../…">, <a href="../…">), and
paths in other frontmatter keys, such as image: /attachments/x.png.
| Argument | Meaning |
|---|---|
PATHS |
Only fix these files (default: every page). |
kb mv¶
Move or rename a page, or another file of the knowledge base such as an
image, rewrite every link to it, and regenerate the indexes. A moved page's
own relative links are rewritten as /paths. An expected entry for the
page in tools/retrieval-eval/questions.yaml is renamed too, keeping the
file's comments.
It refuses:
- a source outside the knowledge base, ignored by git, in a hidden folder,
or reserved (
index.md,log.md); - a destination that exists, is reserved, is outside the knowledge base, is
in a hidden folder, or that git ignores. On a disk that ignores case
(macOS, Windows), an existing file whose name differs only in case counts
as existing, except for the file being moved:
kb mv Foo.md foo.mdis a case-only rename; - an empty
NEW("",/,.); - a change of file extension.
kb mv and kb merge change files all or nothing. They compute every edit
first, back up the originals in .cache/kb-backup/, and write each file
through a temporary file. If a step fails, they put the originals back and
exit with an error; the backup is removed. If putting them back fails too,
the message names the backup folder, whose MANIFEST lists each copy's
number and its original path, relative to the repository root and with /
on every system: copy the files back, then delete the folder. Only a
process killed outright (not Ctrl-C) can leave a hidden .NAME.….tmp file
next to a page; delete it.
| Argument | Meaning |
|---|---|
OLD |
Bundle-relative path of the page or file, e.g. ai/llm.md. |
NEW |
New bundle-relative path. Without an extension, OLD's is added (ai/llms means ai/llms.md). An existing folder, or a path that ends with /, keeps the file name (kb mv ai/llm.md ml/ moves it to ml/llm.md); end a new folder whose name has a dot with / (releases/v1.2/). |
kb merge¶
Fold a duplicate page into another, after you have merged the body text by hand. It:
- merges
OLD's frontmatter intoINTO: aliases (plusOLD's title), tags, sources and relations; - drops
INTO'sverified(the merged page needs a new review) and sets itsgeneratedto the actor and the current time; - rewrites
OLD's relative relation and resource values as/paths, so they keep working fromINTO's folder; - deletes
OLDand points every link to it atINTO, and itsexpectedentries intools/retrieval-eval/questions.yaml(a question that already expectsINTOloses the entry); - regenerates the indexes and prints the ones it wrote or deleted.
It refuses files that are not pages of the knowledge base, reserved files,
merging a page into itself, pages without valid frontmatter, and two
sources with the same id but different resources. Like kb mv, it changes
files all or nothing.
| Argument or option | Meaning |
|---|---|
OLD |
Page to remove. |
INTO |
Page that absorbs it. |
--dry-run |
Print what would change; write nothing. |
--by ACTOR |
Actor for generated.by (default: $KB_ACTOR). |
kb new¶
Create a page with valid frontmatter and the body sections of its type
(from schema/vocabulary.yaml). Prints the path of the new file.
uv run kb new TYPE PATH --title TITLE --description TEXT [--tags a,b] [--status draft] [--resource URL] [--by ACTOR]
| Argument or option | Meaning |
|---|---|
TYPE |
A type from schema/vocabulary.yaml, e.g. Concept. Quote types with spaces: "Decision Record". |
PATH |
Bundle-relative path, e.g. ai/llm-wiki.md. .md is added if missing. |
--title |
Required. |
--description |
Required. One sentence. |
--tags |
Comma-separated kebab-case tags. |
--status |
draft (default), stable or deprecated. |
--resource |
Canonical URL. Source pages need it: kb new does not enforce it, but kb check reports H013 without it. |
--by |
Actor for generated.by, e.g. claude-code/<model> or human:<id> (default: $KB_ACTOR; one of the two is required). See below. |
Example:
uv run kb new Source sources/rfc-9110.md --title "RFC 9110: HTTP Semantics" \
--description "The IETF standard that defines the semantics of HTTP." \
--resource https://www.rfc-editor.org/rfc/rfc9110 --tags http,standards
The actor must match the actor pattern of schema/frontmatter.schema.json:
<tool>/<model> (letters, digits, ., _, -; the model may also contain
:), human:<id> or process:<id> (<id> in [a-z0-9._-]). A bracketed
suffix on the model, such as the context-window marker in Claude Code's
claude-opus-5-5[1m], is dropped: generated.by becomes
claude-code/claude-opus-5-5. Any other actor is refused, with a message
that names --by or KB_ACTOR, before a file is written. kb merge checks
its actor the same way.
kb log¶
Add * **Op**: message to <folder>/log.md under today's ## YYYY-MM-DD
heading (UTC), creating the heading if needed, newest first.
| Argument | Meaning |
|---|---|
OP |
The operation: one word (letters and -), capitalized on output. Usual values: Ingest, Query, Lint, Update, Creation, Deprecation, Refactor, Initialization. |
MESSAGE |
Entry text. Link pages as [Title](/path.md). Several words are joined with spaces. |
An entry is one line. Line breaks in the message are replaced by spaces, so a message cannot start a heading or another entry. An empty message is refused.
kb find¶
List pages whose frontmatter matches every given filter, one per line as
/path<TAB>type<TAB>title.
| Option | Meaning |
|---|---|
--type |
Exact type, e.g. Concept. |
--tag |
Repeatable; the page must have all given tags. |
--status |
draft, stable or deprecated. A page without status counts as stable. |
--folder |
Bundle-relative folder prefix, e.g. ai. |
--trust |
unverified, machine-confirmed or human-reviewed. |
kb folders¶
Print folder<TAB>title: description for every folder that gets an index.
kb search --setup creates a qmd context for each of them.
kb search¶
New in v0.6.0. Search the pages of the knowledge base, and set up or refresh its qmd index. See Enable search.
| Argument or option | Meaning |
|---|---|
QUERY |
Words to search for, joined with spaces. Required unless --setup or --reindex is given. |
--setup |
One-time qmd setup: create the collection over <folder>/**/*.md, add a context for the knowledge base and one per indexed folder (the title and description from schema/taxonomy.yaml, as kb folders prints them), then compute the embeddings (qmd embed). |
--reindex |
Refresh the qmd index after changes: qmd update, then qmd embed. |
The qmd collection is named after the knowledge base: $KB_QMD_COLLECTION
when set, otherwise kb_name (read from the project name <kb_name>-tools
in pyproject.toml), or kb if that cannot be read.
With a query, kb search:
- runs
qmd query QUERY -c <collection>when qmd is on thePATHand the collection exists, and exits with qmd's status; - otherwise runs a built-in text search: it keeps the words of the query
that have 3 characters or more (letters, digits,
_and-), counts their case-insensitive matches in each page, skipsindex.mdfiles, and prints the 20 pages with the most matches as<folder>/path:count. When no word is long enough, it searches for the whole query. No output means no match; the exit status is 0 either way.
--setup and --reindex stop with "qmd is not installed" when qmd is
not on the PATH.
kb eval¶
New in v0.7.0. Measure whether each retrieval tier reaches the pages a
question needs, from the questions in tools/retrieval-eval/questions.yaml.
See Enable search.
| Option | Meaning |
|---|---|
--questions FILE |
Question file (default tools/retrieval-eval/questions.yaml). |
--k K |
Cut-off for recall@k (default 10). |
--json |
Print the full result as JSON: per question and tier, the status, the rank of the first expected page, the expected pages found in the top K, recall@K and the top K pages; then a summary per tier. |
--min-recall R |
Exit 1 when the mean index+text recall@K is below R (0 to 1). For CI. |
--no-qmd |
Skip the qmd tier even when qmd is set up. |
The question file holds a list under questions. Each entry has:
| Key | Meaning |
|---|---|
question |
Required. The question, as you would ask it. |
expected |
Required. Bundle-absolute paths of the pages a good answer uses, e.g. /systems/dns.md, each listed once. Each must be an existing page, with the exact case; generated index.md files are not allowed. |
filters |
Optional. kb find filters: type (a type of schema/vocabulary.yaml), tag (a tag or a non-empty list of tags, all must match), status, folder (an existing folder of the knowledge base), trust. |
kb eval checks the whole file first and stops with one line per problem
(unknown keys, missing, malformed or repeated values, pages, types or
folders that do not exist). kb mv and kb merge rename the expected
entries of the page they move or merge. After deleting an expected page,
update or remove its entries by hand.
For each question it ranks the pages with each tier:
- index+text: index navigation first, then text search. Index
navigation ranks the pages whose index entry (title and description)
contains whole words of the question, most distinct words first. It
ignores words under 3 characters and common question words such as
what,theordoes. When 3 or more words remain, an entry must contain at least 2 of them. The text search ofkb searchthen adds the pages the index did not surface, in its order. Pages in.and_folders get no index entry. - filters: the pages
kb findprints for the question'sfilters, in path order. Skipped (-) when the question has nofilters. - qmd:
qmd query -c <collection> --json -n N -- QUESTION, when qmd is on thePATHand the collection exists; otherwiseskipped. qmd's local models rank these results; the other tiers are fully deterministic.kb evalprints one line on stderr before the first call, because the first run of qmd downloads its models. Aqmd querythat fails or takes more than 10 minutes is reported aserrorfor that question.
The output is one line per question and tier: found/expected @rank, the
number of expected pages in the top K, and the rank of the first expected
page anywhere in the tier's ranking (@- when it holds none). The
last line gives, per tier, the mean recall@K over the questions it ran on
and the number of questions with at least one expected page in the top K.
The exit status is 0 unless --min-recall fails or the question file is
invalid. With no questions, kb eval says so and exits 0.
kb report¶
Print a markdown health report: pages by type, trust tiers of knowledge
pages, status counts, stale pages, uncited knowledge pages, unused sources,
broken links (wanted pages) and drafts. It counts the same pages as the
analytics commands (see
which pages), so
Templates and pages below _ folders are left out.
kb graph¶
Link-graph analytics over knowledge pages. Generated indexes, log.md,
_-prefixed folders and, by default, personal areas are excluded; links to
Source pages count as citations. See
Maintenance analytics.
| Option | Meaning |
|---|---|
--scope |
knowledge (default) or all, which includes personal areas such as projects/ and journal/. |
--top |
Length of the ranked lists (default 15). |
--json |
Print JSON instead of markdown. |
kb dupes¶
Print near-duplicate candidate pairs, score /a <-> /b [signals], and
a count on stderr. Read-only.
| Option | Meaning |
|---|---|
--min-score |
Lowest score to report (default 0.6). |
--body |
Also compare page text (slower). |
--scope |
knowledge (default) or all. |
--json |
Print JSON. |
kb unlinked¶
Print mentions of other pages' titles and aliases that are not linked, as
page:line "text" -> target with a snippet, then names shared by several
pages. Read-only.
| Argument or option | Meaning |
|---|---|
PAGES |
Only scan these pages (bundle paths). |
--min-len |
Ignore names shorter than this (default 4); all-caps aliases are exempt. |
--all |
Also scan personal areas. |
--json |
Print JSON. |
kb zotero¶
Read-only Zotero access: the local API, then the web API, then a snapshot of the database. See Connect Zotero.
uv run kb zotero search WORDS… [--limit N]
uv run kb zotero show KEY
uv run kb zotero new-source KEY [--path PATH] [--tags a,b] [--by ACTOR]
| Action or option | Meaning |
|---|---|
search WORDS… |
Print key<TAB>citekey<TAB>year<TAB>title for matching items. |
show KEY |
Print the item as JSON. KEY is an item key or a citation key. |
new-source KEY |
Create a draft Source page with the item's metadata and a zotero pointer. |
--limit |
search: maximum results (default 20). |
--path |
new-source: bundle path (default sources/<slug>.md, the kebab-case citation key). |
--tags |
new-source: comma-separated tags. |
--by |
new-source: actor (default $KB_ACTOR). |
kb karakeep¶
Archive a web page in KaraKeep. Prints already saved: <id> or
saved: <id>. See Connect KaraKeep.
kb fetch¶
Write the text of an external resource to .cache/sources/ and print the
file's path.
REF form |
Resolved through |
|---|---|
zotero:<key or citekey> |
Zotero (full text) |
file:<root>/<path> |
The root's local path from KB_ROOT_<ROOT>; non-text files converted with markitdown |
https://… or karakeep:<url> |
KaraKeep, archiving the page first if it has no bookmark |
Denied paths are refused. A karakeep: reference must be an http:// or
https:// URL with a host.
Non-text files are converted with markitdown when it is installed, and
otherwise with uvx --from markitdown[all]==0.1.8 (set KB_MARKITDOWN for
another version). The converter runs without the variables loaded from
.env and without secrets such as *_API_KEY or *_TOKEN (see
environment variables), and is
stopped after 5 minutes.
kb open¶
Open an external resource with the desktop's default handler (xdg-open,
open on macOS, the file association on Windows), and print what was
opened.
| Argument or option | Meaning |
|---|---|
REF |
Same forms as kb fetch. Zotero items open as zotero://select/…. |
--print |
Only print what would be opened. |
kb open only hands three kinds of target to the desktop: http:// and
https:// URLs with a host, zotero://select/… URLs that it builds from a
checked item key, and absolute paths of files under a declared root. Other
schemes (smb:, file: URLs, custom ones) and anything starting with -
are refused. So are files the desktop would run rather than show: programs
and shortcuts by their extension (.exe, .bat, .lnk, .app,
.command, …) and, on macOS and Linux, files with the executable bit that
have no extension or start like a program (#!, ELF, Mach-O, MZ). A PDF
with the executable bit, as on SMB, WSL /mnt/c or FAT mounts, still opens.
kb open file:<folder> opens the file's folder instead.
kb import¶
Convert an Obsidian vault or Logseq graph into bundle pages. The source is never modified. See Import a vault and the import mapping reference.
| Argument or option | Meaning |
|---|---|
SOURCE |
Vault or graph directory. |
--into |
Required. Bundle folder that relative to paths start from. |
--map |
Required. Mapping file (YAML). |
--dry-run |
Print the plan and issues; write nothing. |
--by |
Actor for generated.by (default: actor in the mapping). It must match the schema's actor pattern: human:<id>, process:<id> or <agent>/<model>. A context-window suffix on the model is dropped: claude-code/claude-opus-5-5[1m] is written as claude-code/claude-opus-5-5. |
--redirects |
Where to write the source → bundle path table (default .cache/import/<vault>-redirects.tsv). |
Exits 1 when the plan has errors; a real run then writes nothing. A real
run writes every file to a staging folder in .cache/import/ first and
moves them into place at the end. If anything fails, it removes what it
had moved, so no partial import remains.
kb obsidian setup¶
New in v0.4.0. Install the pinned Obsidian community plugins listed in
<folder>/.obsidian/community-plugins.json and, optionally, open the vault. See
Set up Obsidian.
| Option | Meaning |
|---|---|
--add |
Also install these plugin IDs and add them to community-plugins.json. Each must be pinned in tools/obsidian-plugins.json; otherwise the command stops with "no pin for …". The required plugins are always added back to the list. |
--force |
Download plugins again even when the pinned version is installed. |
--open |
Open the knowledge-base folder in Obsidian through obsidian://open?path=… (a vault Obsidian already knows; the first time, use Open folder as vault). |
Plugins are downloaded from their GitHub releases, as pinned in
tools/obsidian-plugins.json, into <folder>/.obsidian/plugins/<id>/, and their
SHA-256 checksums are verified. Listed IDs without a pin are reported. The
command ends by printing the two manual steps, trusting the vault and
turning on Templater's trigger on new file creation, and the folder to open
as the vault.
kb setup¶
New in v0.6.0. First-time setup of a clone, run by uv run poe setup.
uv run has already created .venv and installed the tooling. It:
- runs
git initif the repository root is not inside a git repository; - installs the pre-commit hook (
pre-commit install); - repairs
.claude/skillswhen git checked the symlink out as a small text file (Git for Windows without symlink support); see below; - regenerates every
index.md, printing each file it writes.
Safe to run again.
.claude/skills on Windows¶
.claude/skills is a symlink to ../.agents/skills, so Claude Code and the
other agents read the same skills. Git for Windows without symlink support
(core.symlinks=false) checks it out as a text file that holds the target,
and Claude Code then finds no skills. kb setup replaces that file with the
first of these that works:
- a symlink (Windows with Developer Mode, or an elevated shell);
- a directory junction, which needs no privileges;
- a copy of
.agents/skills, marked with a.kb-copy-of-agents-skillsfile. Each laterkb setuprefreshes the copy, so runuv run poe setupagain after the skills change.
It then hides the difference from git (git update-index --skip-worktree
on .claude/skills, and /.claude/skills/ in .git/info/exclude). A
broken link or junction, such as a junction that still points at the old
location after the repository moved, is replaced the same way. It leaves a
working link, an unrelated file and a folder you made alone.
kb rename-bundle¶
New in v0.6.0; the just rename-bundle recipe of v0.5.0, with the same
behaviour. Rename the knowledge-base folder from <folder> to NEW: move
it, re-render the template-managed files that name it, and stage the
result. Close Obsidian first. The task-oriented guide is
Rename the knowledge-base folder.
| Argument | Meaning |
|---|---|
NEW |
New folder name, lowercase kebab-case. |
It refuses to run, and changes nothing, when:
NEWis not lowercase kebab-case;NEWisschema,tools,docs,imports,template,launcherorsite(folders of the repository), orsources,syntheses,entities,projectsorjournal(standard folders inside the knowledge base);<folder>/does not exist, orNEWalready exists;<folder>/NEWexists, for example a domain folder of that name;_commitin.copier-answers.ymlis empty, so the template version to re-render is unknown;- tracked files outside
<folder>/, or in<folder>/_templates/, have uncommitted changes: the re-render may overwrite them. It lists them. Changes to pages and vault settings, and untracked files, are fine: they move with the folder.
If NEW is already the name, it says so and exits 0. Otherwise it:
- moves
<folder>/toNEW/withgit mvwhen the folder has tracked files (with a plain move otherwise).git mvstages the renames and keeps the history. Untracked notes and the installed plugins move along but stay untracked, and modified pages stay unstaged; - runs
uvx copier recopy --trust --defaults --overwrite --skip-tasks --vcs-ref=<_commit> --data bundle_dir=NEW, which re-renders the template-managed files at the template version recorded in.copier-answers.ymland records the new answer. This needs access to the template repository. Copier validatesNEWas it validates thebundle_dirquestion, so it also refuses the slug of a domain in the recordeddomainsanswer. If the recopy fails, it moves the folder back, restores the managed files and<folder>/_templates/toHEAD, reports that everything was put back as it was, and exits 1; - compares each re-rendered managed file with
HEAD, ignoring the folder name. Files that differ in more than the name had committed local edits that the re-render reverted, for example a hand-editedKB_ACTORin.claude/settings.json; it lists them in aWARNING; - stages the changes to tracked files outside the folder and in
NEW/_templates/(git add -u). It never stages untracked files; - replaces the folder name in
.cache/kb-touched.txt, wherekbcommands run by an agent record the pages they change until the session's next hook collects them (the session state in.cache/kb-hooks/holds paths relative to the folder and needs no change); - regenerates the indexes (the next
uv runsyncs the tooling with the re-renderedpyproject.toml), and prints what it staged, theWARNINGif any, the next steps (reviewgit diff --cached, commit), what to fix by hand (mentions of the old folder inREADME.mdand in the comments ofschema/*.yaml), and the Obsidian and qmd steps.
If a step after the re-render fails, it stops with a message that asks you
to run uv run kb index, then review git diff --cached.
It does not commit, and does not touch files owned by the knowledge base,
such as README.md.
kb hook¶
Entry points for the agent hooks in .claude/settings.json,
.codex/hooks.json and .gemini/settings.json. They read the hook payload
(JSON) on stdin. See Agents and hooks.
uv run kb hook EVENT [--agent claude|codex|gemini]
uv run python -m kbtools.hooks EVENT [--agent claude|codex|gemini]
The second form is the same command without loading the rest of kb; the
hook configurations use it because the shell hooks run on every command.
| Event | When | What it does |
|---|---|---|
pre-tool |
Before a shell command (Codex: also before a patch) | Records the digest of log.md if this is the session's first event, and a listing of the knowledge base's .md files (path, modification time, size, content hash; dot-folders skipped). Always exits 0, even on errors, so it never blocks a command. |
post-tool |
After it, also when it failed (Claude Code: PostToolUseFailure) |
Compares the listing: pages whose content was created, changed or deleted are recorded for the session, and those that exist are checked with kb check. |
post-edit |
After a file tool wrote tool_input.file_path (Claude Code: Write, Edit, MultiEdit; Gemini CLI: write_file, replace) |
If it is a .md file in the knowledge-base folder: records it and runs kb check on it. |
stop |
Before the agent finishes (Gemini CLI: AfterAgent) |
Every page recorded this session passes kb check, the indexes above them are fresh, and if knowledge pages changed, log.md differs from its digest at the session's start. |
--agent selects how problems reach the agent:
--agent |
post-tool, post-edit |
stop |
|---|---|---|
claude (default) |
exit 2, problems on stderr | exit 2, problems on stderr |
codex |
exit 0, problems as hookSpecificOutput.additionalContext JSON on stdout |
exit 2, problems on stderr |
gemini |
the same as codex; {} on stdout when there is nothing to say |
exit 2, problems on stderr; {} otherwise |
Codex and Gemini CLI replace the output of a tool with the stderr of a
hook that exits 2, so the post-tool problems come as added context there
instead, and the agent still sees what its command printed. For the same
reason, with --agent codex or --agent gemini the post-tool and
post-edit events exit 0 even on errors (bad arguments, no knowledge
base), like pre-tool.
The session state lives in .cache/kb-hooks/<session id>/, keyed by the
payload's session_id (default without one). A clean stop deletes it;
the state of other sessions is removed at the next clean stop of any
session once it is 7 days old. .cache/kb-hooks/hashes.json caches the
content hashes of the listings.
The global launcher¶
New in v0.4.0. The optional kb launcher (package okf-kb) is installed
once per machine and runs the kb of the right knowledge base. See
Install the kb launcher.
| Option | Meaning |
|---|---|
-C, --kb (also --kb=…) |
Use this knowledge base: a directory inside it, or a name from the configuration file. Must come first. |
--list |
Print the registered knowledge bases: name and path, * before the default, (missing) after paths that are not knowledge bases. |
--which |
Print the knowledge base root that would be used. |
--help-launcher |
Print the launcher's usage. kb -h is passed to the knowledge base's tool. |
Without -C, the launcher uses $KB_DIR (a path or a name), then the nearest parent of the
current directory that contains schema/vocabulary.yaml, then the default
entry of $XDG_CONFIG_HOME/okf-kb/config.toml (default ~/.config/okf-kb/config.toml). A knowledge-base root is a folder with schema/vocabulary.yaml and pyproject.toml. Without arguments, the launcher prints its usage and exits 2. It runs
uv run --project <root> --quiet kb ARGS… with KB_REPO_ROOT=<root>, in
the current directory. The configuration file is read only for a name, the
default or --list; a broken file does not stop a call that gives a path
or runs inside a knowledge base.