/ai-knowledge:kb-learn [auto <learning> | focus]from ai-knowledge
Saves team knowledge (corrections, rules, decisions, codebase gotchas) to the project's knowledge base in .claude/rules/kb/. Supports quick save and review modes.
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: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Read kb-format.md first. It defines the layout, frontmatter, load modes, writing rules and the auto-capture setting used below.
Arguments (may be empty): $ARGUMENTS
| Arguments | Path |
|---|---|
First word is auto | Quick save: save one learning without questions, then report it in one line |
| Anything else, or nothing | Review: go through the conversation (or the focus the arguments name) and ask before saving |
Use quick save in two situations only:
A user who states a rule, convention or correction ("a rule for this team: ...") hasn't asked you to save it. Without the auto-capture instruction, that's not a reason to save. If you invoked this skill yourself and neither situation applies, stop: write nothing and don't mention the knowledge base.
When the user asks to go through everything the conversation taught, use the review path instead.
Claude Code's auto memory saves personal notes on one machine. This skill is for knowledge the team should share: rules a teammate's session would also need.
Run the checks from kb-format.md without printing their details. If there's a 1.x knowledge base, write nothing and reply with one line: 📖 Not saved to KB: this project has a 1.x knowledge base. Run /kb-migrate first. If there's no knowledge base, reply 📖 Not saved to KB: there's no knowledge base here. Run /kb-init first.
Use the text after auto. If there's none, take the most recent correction, rule, decision or gotcha in the conversation. Save exactly one learning per call.
Under auto-capture, skip it without writing or printing anything if it's:
CLAUDE.local.md);When the user asked, save it even if it looks personal. In both cases, never store a secret value: keep the rule and drop the value.
Search .claude/rules/kb/ and .claude/kb/ for the learning's key terms (Grep), and read the articles that match and _global-learnings.md.
📖 Already in KB: {path}.paths, when the learning is tied to specific folders or file types. Check the globs with Glob before writing;.claude/kb/ when it's about a topic or task rather than files;_global-learnings.md only for a short rule that applies to nearly every task in the project, and only while that file stays under about 40 lines. It loads every session.Never create any other pinned article in a quick save.
Get today's date once (kb-format.md, Dates).
Add the learning as one imperative bullet under ## Key rules, with a short reason if it isn't obvious. When replacing a rule, edit that bullet instead.
A new article gets the frontmatter and body from kb-format.md: a title, a one-sentence description and ## Key rules, with no Context or Related section. If _global-learnings.md doesn't exist yet, create it with tags: [global, cross-cutting], created, last-updated, the heading # Global learnings and ## Key rules.
Update last-updated, and add a tag if the learning brings a new topic.
Add a line to _index.md for a new scoped or on-demand article, from kb-format.md (The index rule). If a tag was added to an existing article that has a line, update its keywords.
Append to the log:
## [{date}] learn | {Auto-saved | Saved on request}: {the rule, shortened}
- {Created | Updated}: {path}
End your reply with exactly one line, using the path relative to .claude/rules/kb/ or .claude/kb/:
📖 Saved to KB: conventions/api-errors.md (scoped to src/api/**). Say "undo" to remove it.📖 Saved to KB: tools/release.md (on demand). Say "undo" to remove it.📖 Saved to KB: _global-learnings.md (loads every session). Say "undo" to remove it.📖 Updated KB: conventions/api-errors.md (replaced the old rule on status codes). Say "undo" to restore it.Under auto-capture, then carry on with the user's task.
When the user says "undo", or asks to remove what was just saved, reverse the most recent quick save exactly, unless they name a different one:
_index.md line;_index.md line: restore it;_global-learnings.md: delete the file;last-updated and tags values it had;Use edits rather than git checkout, so other uncommitted changes in those files stay. Change nothing else, and reply in one line: 📖 Removed from KB: {path}. or 📖 Restored KB: {path}.
This is the path for a typed /kb-learn. Arguments that aren't auto name a focus ("the deploy fix", "testing"): extract only learnings about it. Otherwise review the whole conversation.
Run the checks from kb-format.md: stop if there's a 1.x knowledge base (point to /kb-migrate) or no knowledge base (point to /kb-init), and pass on any git warning.
Review the conversation from start to finish (or the focus) and collect:
Leave out:
CLAUDE.local.md);Never record secrets. Record the rule about them ("Service X's key comes from an environment variable"), and describe sensitive endpoints generically ("the internal staging API").
For each learning, decide:
Read the articles that touch the same topics, and _global-learnings.md if it exists. Drop learnings they already state. When a learning contradicts an existing rule, plan to replace the old rule: the conversation is newer.
Proposed knowledge base updates
===============================
New articles
1. .claude/rules/kb/testing/integration-tests.md (scoped: tests/integration/**)
tags: testing, database
- "Reset the test database with the fixture loader, not migrations"
- "Integration tests need the local queue running"
Updates
2. .claude/kb/tools/release.md (on-demand)
- "Tag releases from main only" (new)
- "Bump the API version in openapi.yaml" (replaces "Bump it in package.json")
Global learnings (load every session)
3. "Use the shared logger; never console.log in server code"
Links
- integration-tests ↔ release
Ask with AskUserQuestion:
With "Let me pick", go through the learnings one by one and ask whether to include each, and whether its destination or load mode should change.
Get today's date once (kb-format.md, Dates) and use it for every date below.
New articles: use the frontmatter and body from kb-format.md, in the folder that matches the load mode (paths only for scoped articles).
Existing articles: add the learnings under the right section without duplicating entries, and replace rules they contradict. Update last-updated only if the content changed, and add new tags and links.
Global learnings: if .claude/rules/kb/_global-learnings.md doesn't exist, create it (frontmatter tags: [global, cross-cutting], created, last-updated; heading # Global learnings; rules under ## Key rules). Add each learning as a bullet, merge near-duplicates, replace contradicted entries, and remove placeholder text. Keep the file short: it loads every session. If it passes about 40 lines, suggest moving area-specific rules into scoped articles with /kb-prune.
Related: where a new article and an existing one bear on the same tasks, list each in the other's ## Related section as a path (kb-format.md, Related articles). Update last-updated on any article whose content changed.
Index: add a line to _index.md for each new scoped or on-demand article, and update the keywords on the line of any article whose tags changed.
Log: append
## [{date}] learn | Conversation learnings saved
- Created: {paths}
- Updated: {paths}
- Global learnings: {n} added
Show how many articles were created and updated, how many global learnings were added, the links added, and each new article's load mode. Remind the user that the knowledge reaches teammates once it's committed.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
7 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.npx claudepluginhub charlesjones-dev/ai-agent-plugins --plugin ai-knowledgeOther plugins' skills for the same job