/ai-knowledge:kb-migrate [--dry-run] [auto=off] [agents=off]from ai-knowledge
Migrates a 1.x knowledge base (CLAUDE.md table + docs/kb/) to Claude Code rules with pinned, scoped, and indexed articles. Supports --dry-run, auto-capture, AGENTS.md export, and stale command reference fixes.
Ships in ai-knowledge. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Read kb-format.md first. It defines the target layout, the frontmatter and the checks used below. The command check (see Command references, at the end) also uses command-map.md.
Arguments (may be empty): $ARGUMENTS
--dry-run means: build and show the plan, change nothing, and don't ask to proceed. auto=off means: don't turn on auto-capture at the end (Step 7). agents=off means: leave the AGENTS.md section out (kb-format.md, The AGENTS.md pointer). Ignore any other text.
This command moves files and edits CLAUDE.md. Nothing changes until the user approves the plan.
git status --porcelain -- CLAUDE.md .claude/CLAUDE.md docs/kb .claude/rules/kb .claude/kb. If anything there is uncommitted, the plan warns that the migration is easiest to review and undo as one commit on a clean tree, and the approval question in Step 4 mentions it.Knowledge Base section of CLAUDE.md or .claude/CLAUDE.md, from its heading to the next heading of the same or higher level. Inside it: the preamble, the table (Topic, File, When to Load), an inline ### Global Learnings subsection (layouts before 1.3), the kb-auto block (<!-- kb-auto: enabled --> and the blockquote after it), and anything else the user wrote there. Also search the whole file for a kb-auto block outside the section.docs/kb/, recursively, including non-markdown files such as images..claude/rules/kb/ and .claude/kb/, from /kb-init or an earlier, interrupted run.Parse each table row:
Always (pinned) means pinned.—) are scope patterns.packages/api/**) and keywords from the rest, and mark the row "inferred" so the user checks it.Read every .md file under docs/kb/ and every file a row points to. For each article, record:
tags, related, created, last-updated, pinned, scope (a string or a list), source, discovered-from, type, query, sources, and any other field;# heading) and its length in lines;related and sources, and every [[name]] link in the body, each resolved to the article whose file name is name.md;tags, created or last-updated; YAML that won't parse (often a 1.x related line, which goes away anyway); @path text outside backticks that names a real file.Map the special files:
| 1.x | 2.x |
|---|---|
docs/kb/_global-learnings.md | .claude/rules/kb/_global-learnings.md (pinned) |
Inline ### Global Learnings in CLAUDE.md | Merged into .claude/rules/kb/_global-learnings.md, without duplicates |
docs/kb/_index.md | Not moved. Its summaries seed the new _index.md, then it's deleted. |
docs/kb/_log.md | .claude/kb/_log.md |
docs/kb/README.md | .claude/kb/README.md, rewritten from the template in kb-format.md |
| Non-markdown files (images, PDFs) | .claude/kb/assets/, keeping their subpath; relative links to them in moved articles are updated |
docs/kb/.obsidian/ and other editor or system files (.DS_Store) | Not knowledge. Deleted with docs/kb/, and listed in the plan so the user approves it |
Edge cases:
docs/kb/ (1.x /kb-import allowed any path): plan to move the file into the knowledge base like the others, and in Step 4 let the user keep it where it is instead, which drops it from the knowledge base.docs/kb/ without a row is migrated from its frontmatter like any other.[[name]] link that matches no article, or more than one, can't be turned into a path. List it under "Needs your call".Apply the first rule that matches:
Always (pinned), the frontmatter has pinned: true, or it's _global-learnings.md. It goes to .claude/rules/kb/{same subpath} without paths.scope, the row, or both (merged, without duplicates). It goes to .claude/rules/kb/{same subpath} with paths..claude/kb/{same subpath}.Every article keeps its row's keywords: they're added to its tags, whatever its mode. Scoped and on-demand articles get a line in _index.md with those keywords, so a scoped article still loads when a task matches its topic and no file matches its globs, as the 1.x row allowed.
Keep each article's subfolder (docs/kb/conventions/api.md becomes .claude/rules/kb/conventions/api.md or .claude/kb/conventions/api.md). Don't reorganize during the migration; /kb-prune organize does that afterward.
Turn scope patterns into paths:
/, such as *.controller.ts, becomes **/*.controller.ts.src/api or src/api/, becomes src/api/**../ is dropped.docs/kb/** or anything under docs/kb/) is dropped and flagged, not rewritten to .claude/rules/kb/** or .claude/kb/**. In 2.x it would load the article whenever Claude reads any article (kb-format.md). If no patterns are left, offer to make the article on-demand.Check the budget in kb-format.md (Layout). If the pinned articles total more than about 100 lines or there are more than five, say so and suggest which ones to make scoped (if their content is about specific folders) or on-demand. If the new _index.md would pass about 150 lines, suggest articles to merge with /kb-prune afterward. The 1.x _index.md catalog is replaced, not carried over.
Then look for stale command references, as Command references (at the end) describes.
KB migration plan
=================
Pinned (load every session): {n} articles, {lines} lines
docs/kb/_global-learnings.md → .claude/rules/kb/_global-learnings.md
docs/kb/security/auth.md → .claude/rules/kb/security/auth.md
Scoped (load when Claude reads or edits matching files, or a task matches the index line): {n} articles
docs/kb/conventions/api.md → .claude/rules/kb/conventions/api.md
paths: src/api/**, **/*.controller.ts (was *.controller.ts)
index line: API error format (api, rest; loads with src/api/**, **/*.controller.ts)
On-demand (listed in .claude/rules/kb/_index.md): {n} articles
docs/kb/tools/deploy.md → .claude/kb/tools/deploy.md
index line: release steps and rollback rules (deploy, release, rollback)
Other files
docs/kb/_log.md → .claude/kb/_log.md
docs/kb/_index.md → deleted (replaced by .claude/rules/kb/_index.md)
docs/kb/README.md → .claude/kb/README.md (rewritten)
docs/kb/.obsidian/ → deleted with docs/kb/ (editor settings, not knowledge)
Frontmatter and links
conventions/api.md: scope → paths, pinned removed, tags + rest (row keyword),
related removed; Related section: .claude/rules/kb/security/auth.md, .claude/kb/tools/deploy.md
CLAUDE.md
Remove "## Knowledge Base" (lines {a}-{b}): preamble, table ({n} rows), kb-auto block
Stale rows dropped: "{Topic}" → {path} (file missing)
AGENTS.md
Add the ai-knowledge section so Codex and Cursor read the knowledge base {or: skipped, agents=off}
Command references (inside the knowledge base: applied with the migration; outside it: asked after)
rename
docs/kb/_global-learnings.md:12 `/ai-writing:writing-humanize` → `/ai-slop:slop-rewrite`
CLAUDE.md:9 (outside) `ai-geo@claude-code-plugins-dev` → `ai-seo@ai-agent-plugins`
changed
docs/kb/_global-learnings.md:14 → see Needs your call
.gitignore:4 (outside) keep docs/geo-audit/ and add docs/seo-audit/ on the next line
removed
CLAUDE.md:22 (outside) → see Needs your call
left as history
docs/kb/tools/seo.md:8 "On 2026-05-01 we ran /geo-audit" (dated)
Needs your call
{inferred rows, globs that match nothing, budget, links that match no article, extra text in the section}
docs/kb/_global-learnings.md:14 (changed)
now: Commit with `/ai-git:git-commit-push` once tests pass.
proposed: Commit with `/ai-git:git-commit-push-pr --no-pr` once tests pass.
CLAUDE.md:22 (removed)
now: Load an article with /kb-load when Claude misses it.
proposed: To pull in an article Claude missed, @-mention its file, such as @.claude/kb/tools/release.md.
docs/kb/tools/seo.md:3 (ambiguous: history or instruction?)
now: We moved to /geo-audit after the March review.
Warnings
{uncommitted changes, ignored paths}
Moves use git mv, so history follows each file. Nothing has changed yet.
With --dry-run, end with "Dry run: nothing changed. Run /kb-migrate to apply this plan." and stop.
Otherwise ask with AskUserQuestion:
changed or removed command references inside the knowledge base, replace "Migrate" with two options: "Migrate, with the proposed rewrites" | "Migrate, leave those references for me"With "Let me adjust", take free-text changes (a different mode, other paths or keywords, a new name, an article to leave out of the knowledge base, a different rewrite or a reference to leave alone), show the updated plan, and ask again. An article left out moves to docs/ (or a path the user names), so docs/kb/ ends up empty. With "Cancel", stop without changes.
Get today's date once (kb-format.md, Dates). Use it for the log and _index.md only: the knowledge in the articles hasn't changed, so their last-updated stays as it is.
Run no git commands that change state other than git mv and git rm: don't git add, commit or stash. The user reviews and commits the result.
Folders. Create every destination folder.
Moves. Move each file as kb-format.md describes (git mv for tracked files). If the destination already exists from an earlier run: when the content is the same, delete the 1.x copy; when it differs, show both and ask which to keep, or merge them.
Frontmatter. In each moved article:
paths first, as a list of the quoted patterns from Step 3;scope, pinned, related and sources;tags from the content and path; take created from git log --diff-filter=A --follow --format=%as -- {path} | tail -1 and last-updated from git log -1 --format=%as -- {path}, or today's date when git has no history for the file;tags lacks (lowercase), for every article, pinned and scoped included. Index lines read keywords from tags, so a keyword left out here is lost;Command references. In each moved article, apply the rename hits from the plan, and the proposed changed and removed rewrites if the user chose them. Change nothing else, and don't touch files outside the knowledge base yet (Step 8 asks about them).
Links. In each moved article, turn the targets of the removed related and sources fields into repo-relative paths at their new locations, in backticks, listed in a ## Related section at the end of the body (kb-format.md, Related articles). Merge them with an existing Related section, replacing its [[name]] entries, and drop duplicates. A [[name]] link in running text becomes the target's path in backticks. Leave links listed under "Needs your call" as plain text without brackets, and report them.
@path text that names a real file in backticks.Global learnings. Merge an inline ### Global Learnings subsection into .claude/rules/kb/_global-learnings.md, creating it if needed (frontmatter tags: [global, cross-cutting], created, last-updated; heading # Global learnings; rules under ## Key rules). Drop duplicates and placeholder text such as "No global learnings captured yet...".
Assets. Move non-markdown files and fix relative links to them in the moved articles.
Index. Write .claude/rules/kb/_index.md from the template in kb-format.md, with a line for each scoped and on-demand article. Take summaries from the old _index.md where it has them, otherwise from the article's title and opening sentence. Then delete docs/kb/_index.md (git rm if tracked).
README. Write .claude/kb/README.md from the template in kb-format.md. If a 1.x README existed, move it there first and then replace its content, so its history carries over.
CLAUDE.md. Remove the Knowledge Base section (heading, preamble, table, inline global learnings, kb-auto block) and any kb-auto block elsewhere. Keep the text the user chose to keep in Step 4. Leave everything else as it was, and collapse any run of three or more blank lines left behind into one blank line. Don't add a pointer: _index.md tells Claude about the knowledge base.
AGENTS.md. Add the pointer section from kb-format.md, creating the file if needed, unless the arguments include agents=off. Change nothing outside its marker comments.
docs/kb/. Delete what's left in it that the plan listed, such as .obsidian/ and .DS_Store (git rm -r for tracked files, a plain delete for the rest), then the folder itself. Leave docs/ alone, and don't recreate it if it ends up empty: git doesn't keep empty folders.
Log. Append to .claude/kb/_log.md:
## [{date}] migrate | Moved the 1.x knowledge base to Claude Code rules
- Pinned: {n}, scoped: {n}, on-demand: {n}
- Removed the Knowledge Base section{ and the kb-auto block} from CLAUDE.md
- {Added the AGENTS.md pointer | Skipped the AGENTS.md pointer (agents=off)}
- Frontmatter fixes: {n}; links turned into paths: {n}; command references updated: {n}
git status --short and confirm the moves show as renames.paths; no article has scope, pinned, related or sources; no [[ is left in any article; every Related entry is a path that exists; nothing under .claude/rules/kb/ is a README, log or note._index.md with its tags as keywords, and every line points at a file that exists.docs/kb/ is gone, and CLAUDE.md has no Knowledge Base table or kb-auto marker, so the 1.x check now passes.Fix anything that fails before reporting.
After a real run, turn on auto-capture for this developer without asking, unless the arguments include auto=off, in which case set it off (kb-format.md, Auto-capture). A dry run changes nothing; its plan says whether auto-capture would be turned on or left off.
AGENTS.md section: added, so Codex, Cursor and other agents that read AGENTS.md use the knowledge base, or skipped with agents=off./kb-auto is gone. Auto-capture replaces it: Claude saves team knowledge as it comes up, without being asked. It's now on for you; turn it off any time with /kb-init auto=off, or back on with /kb-init auto=on. Claude Code's auto memory is a separate option that keeps personal notes on one machine, and auto-capture works whether it's on or off.".git/, dependency folders and the knowledge base itself) for files that still mention docs/kb/, and add the command references the plan found outside the knowledge base. If there are any, list each file with its proposed changes and ask one question (Header: "Other files"; Question: "Update these files outside the knowledge base as proposed?"; Options: "Update all" | "Let me pick" | "Leave them"). Apply only what the user approves. In .gitignore, add the new line after the old one and keep the old one. If you can't ask, end the report with the list and the question./context to see _index.md and the pinned articles among the loaded rules. Then ask Claude to read a file that matches a scoped article; the article loads with it.git add -A docs/kb .claude CLAUDE.md AGENTS.md). Don't commit for the user. Once it's committed, Claude Code loads the knowledge base for every teammate, with or without the plugin; teammates who use the /kb-* commands should update ai-knowledge to 2.x.With no 1.x pieces left, check the 2.x format instead. This is also how to repair a knowledge base edited by hand or moved by an older version of this skill.
If .claude/rules/kb/_index.md doesn't exist and there's no other .md file under .claude/rules/kb/ or .claude/kb/, say "There's no knowledge base to migrate. Run /kb-init to start one." and stop.
Check:
.claude/rules/kb/ that aren't articles, such as a README, a log or notes (they'd load every session): move them to .claude/kb/;scope becomes paths; an article in .claude/kb/ with pinned: true moves to .claude/rules/kb/; an article in .claude/rules/kb/ without paths that has pinned: false is probably pinned by mistake, so ask whether to scope it, make it on-demand, or pin it;related or sources fields and [[name]] links anywhere in an article. Convert them as Step 5 does (paths in a Related section);paths that match the knowledge base's own folders (.claude/rules/kb/**, .claude/kb/**): propose dropping them, and making the article on-demand if no patterns are left, because the article would load with every knowledge base read;paths: patterns in a form Step 3 would rewrite, and patterns that match no file;_index.md against the budget in kb-format.md;_index.md: scoped or on-demand articles without a line, lines pointing at missing files or at pinned articles, lines whose keywords or "loads with" globs don't match the article's tags and paths, and a header that differs from the template in kb-format.md;@path imports in articles;AGENTS.md pointer: missing, or different from the template in kb-format.md (with agents=off, a section that should be removed);Show the findings in the format of Step 4, including its Command references section. With --dry-run, stop there. Otherwise ask (Header: "KB Format Check"; Options: "Fix all" | "Let me pick" | "Cancel"; when there are proposed changed or removed rewrites inside the knowledge base, replace "Fix all" with "Fix all, with the proposed rewrites" | "Fix all, leave those references for me"). Apply what was approved the way Step 5 does, then ask about files outside the knowledge base the way Step 8 does. Append a migrate | Format check entry to the log, and report what changed. If nothing needs fixing, say "The knowledge base already matches the 2.x format."
Notes written for an older version of this marketplace can send Claude to commands that no longer exist. command-map.md lists every command, skill, subagent, plugin, marketplace name and report path that was renamed, merged or removed, with its replacement and how to match it. Read it before scanning.
Where to look:
.claude/rules/kb/ and .claude/kb/ (Step 9);CLAUDE.md, .claude/CLAUDE.md, CLAUDE.local.md and AGENTS.md;.claude/rules/**/*.md outside .claude/rules/kb/;.gitignore;docs/**/*.md outside docs/kb/.Skip history: _log.md, changelogs and release notes (CHANGELOG*, HISTORY*, RELEASES*, files named for a release or date), and dependency or build folders. Also skip text the migration removes anyway, such as the CLAUDE.md Knowledge Base section and the kb-auto block.
How: for each row, search for every form the map's matching rules list, and read the whole sentence around each hit. Then sort the hit:
rename: swap the old text for the new, in the same form (/x, /plugin:x, $plugin:x or the bare name), keeping New's arguments.changed and removed: in the same form as the old text, propose a rewrite of the whole sentence, so it still reads correctly with the new command and its arguments, or with the built-in alternative. If nothing replaces an instruction, propose removing it. These go under "Needs your call". In CLAUDE.md, AGENTS.md and rule files, put any @path example in backticks: a bare @path there is an import that loads the file at every session start..gitignore: for a report folder that moved, propose adding the new folder on the line after the old one and keeping the old one, since old reports may still be there. Never remove the old line.Applying: inside the knowledge base, rename hits are part of the approved migration or format check, and changed and removed rewrites apply only when the user chose them. Files outside the knowledge base change only after the separate question in Step 8.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub charlesjones-dev/ai-agent-plugins --plugin ai-knowledge7 skills in this plugin
/kb-addAdd knowledge to the team knowledge base from a note, project files or folders, another repo, a URL, or the project's own CLAUDE.md and docs/. Distills it into articles, picks how each one loads, records where it came from, and shows every draft before writing./kb-discoverRead the source code to find knowledge nobody wrote down (architecture, naming, API contracts, data models, error handling, configuration, testing patterns) and save it as knowledge base articles scoped to the code they describe. Shows each draft before writing./kb-initSet up a team knowledge base as Claude Code rules: .claude/rules/kb/ for articles Claude Code loads by itself and .claude/kb/ for on-demand articles. Turns auto-capture on for you unless you pass auto=off. On an existing knowledge base it doesn't redo setup: it turns auto-capture on if you never set it, keeps your earlier choice otherwise, and auto=on|off switches it. Also adds a short section to AGENTS.md so Codex and Cursor read the knowledge base (agents=off to skip). Points to /kb-migrate when the project has a 1.x knowledge base./kb-learnSaves team knowledge (corrections, rules, decisions, codebase gotchas) to the project's knowledge base in .claude/rules/kb/. Invoke it yourself in only two cases: (1) your context holds the instruction 'ai-knowledge auto-capture is on for this project' and such a learning just came up; pass `auto` and the learning. (2) The user explicitly asks you to save or add something to the knowledge base, KB or team rules; pass `auto` and that thing. A user stating a rule, convention or correction is not a request to save it: without the auto-capture instruction, don't invoke this skill for it. Typed as /kb-learn, it reviews the whole conversation and asks before saving./kb-pruneClean up the team knowledge base: find duplicates, contradictions, broken links, stale articles, scoped globs that match nothing and pinned articles that cost too much context, then merge, fix or remove with your approval. Also removes a single article, or sorts articles into category folders./kb-queryAnswer a question from the team knowledge base with cited articles and offer to file the answer back as an article. Also searches by keyword or tag:name and lists every article with how it loads.Other plugins' skills for the same job