Knowledge Base Harvest
You are a cross-source knowledge harvester. Your job is to pull documentation from external sources — other git repos, arbitrary local directories, individual files, or web URLs — and distill their content into the project's KB system (docs/kb/). This fills the gap that /kb-ingest (single-project files) and /kb-absorb (current-project docs/) leave: bringing institutional knowledge from across an enterprise multi-repo codebase or external documentation into one centralized knowledge base.
Frontmatter Schema
Every KB file MUST have valid YAML frontmatter. This skill adds a source field for provenance tracking:
---
tags: [topic-tag-1, module:module-name] # Required: lowercase tags for discovery. Auto-add module tag.
related: [[other-kb-file]] # Optional: cross-references to related KB files
created: YYYY-MM-DD # Required: date created
last-updated: YYYY-MM-DD # Required: date last modified (update on every write)
pinned: false # Optional: true = always loaded. Default false
scope: "src/api/**" # Optional: glob pattern(s) for auto-matching. String or array.
source: "C:/Source/billing-module/docs/api-conventions.md" # Required for harvested content: original source path or URL
---
The source field is what distinguishes harvested KB entries from organically captured ones. It enables future re-harvesting if source docs are updated.
Resolving today's date (cross-platform, CRITICAL): Never guess, infer, or increment prior dates. When this skill writes created / last-updated, resolve today's date once at the start of the write phase, then reuse that single value for every write. Try these commands in order and use the first that returns a YYYY-MM-DD string:
- macOS / Linux / WSL / Git Bash (bash, zsh, sh):
date +%Y-%m-%d
- Windows PowerShell / pwsh:
Get-Date -Format 'yyyy-MM-dd'
- Windows cmd.exe:
powershell -NoProfile -Command "Get-Date -Format 'yyyy-MM-dd'"
- Portable fallback (Node or Python available):
node -e "console.log(new Date().toISOString().slice(0,10))" or python -c "import datetime; print(datetime.date.today().isoformat())"
Only update last-updated when the file's content actually changed. If an edit would leave the file byte-identical, do not rewrite it or bump the date.
Obsidian-Compatible Related Links
When a KB file has related entries in its frontmatter, you MUST also include a ## Related section at the end of the file body with the same references as [[wiki-links]]. This enables Obsidian graph view and link navigation. Always keep the related frontmatter AND the body ## Related section in sync. If there are no related files, omit the section entirely.
Instructions
Step 1: Determine Input Sources
Check if the user provided source(s) after the command. Sources can be mixed — any combination of:
- Directory paths (local): e.g.,
C:/Source/billing-module/docs/ or /repos/auth-service/docs
- File paths (local): e.g.,
C:/Source/billing-module/docs/api-guide.md
- Glob patterns (local): e.g.,
C:/Source/*/docs/**/*.md
- Web URLs: e.g.,
https://wiki.internal.company.com/billing/api-patterns
If source(s) provided: Parse and categorize each as directory, file, glob, or URL.
If no source provided: Ask the user using AskUserQuestion:
- Header: "KB Harvest — Sources"
- Question: "What would you like to harvest? You can provide any mix of:\n- Directory paths to scan for markdown files (e.g.,
C:/Source/billing/docs/)\n- File paths for specific files (e.g., C:/Source/billing/docs/api-guide.md)\n- Glob patterns (e.g., C:/Source/*/docs/**/*.md)\n- Web URLs to fetch and distill (e.g., https://wiki.example.com/some-page)\n\nEnter one or more sources (space-separated or one per line):"
Step 2: Prerequisite Check
- Check for KB section in CLAUDE.md: Read the project's CLAUDE.md and look for the Knowledge Base table. If it doesn't exist, inform the user to run
/kb-init first and stop.
- Check for
docs/kb/ directory: If it doesn't exist, inform the user to run /kb-init first and stop.
Step 3: Discovery
Process each source and build a discovery report:
3a: Local Directories
- Use Glob to find all
.md files recursively within the directory.
- Exclude common non-documentation files:
CHANGELOG.md, LICENSE.md, node_modules/, .git/, dist/, build/, coverage/.
- For each file found, read the first ~30 lines to get a title/summary.
- Infer module name from the directory structure:
- If the path looks like
{base}/{module-name}/docs/..., use {module-name} as the module tag.
- If the path looks like
{base}/{module-name}/..., use {module-name}.
- If ambiguous, use the immediate parent directory of the docs folder.
3b: Individual Files
- Verify the file exists and is readable.
- Read the first ~30 lines for title/summary.
- Infer module name from the file's directory path (same logic as 3a).
3c: Glob Patterns
- Execute the glob pattern using the Glob tool.
- Apply the same exclusions as 3a.
- For each matched file, read first ~30 lines.
- Infer module name per file.
3d: Web URLs
- Use WebFetch to retrieve the page content for each URL.
- If the fetch fails, report the error and mark the URL as FAILED in the discovery report.
- Extract the page title and a brief summary from the fetched content.
- Infer a topic name from the URL path segments and page title.
Step 4: Present Discovery Report
Display a grouped report. Use AskUserQuestion after the report:
KB Harvest — Discovery Report
==============================
## Local Sources
### module-name (C:/Source/module-name/docs/) — {count} files
1. [x] api-conventions.md — "API Conventions and Patterns"
2. [x] deployment.md — "Deployment Procedures"
3. [x] troubleshooting.md — "Common Issues and Fixes"
### other-module (C:/Source/other-module/docs/) — {count} files
4. [x] data-model.md — "Data Model Reference"
5. [ ] README.md — "Module README" (likely not KB material)
## Web Sources — {count} URLs
6. [x] https://wiki.example.com/billing/api — "Billing API Integration Guide"
7. [ ] https://wiki.example.com/onboarding — FAILED: 404 Not Found
Total: {count} sources ready for harvest
Pre-check files that look like they contain actionable knowledge. Pre-uncheck files that are likely not useful (READMEs, changelogs, auto-generated content, failed URLs). The user can toggle selections.
- Header: "KB Harvest — Select Sources"
- Question: "Which sources would you like to harvest? Enter the numbers to toggle (e.g.,
1,3,5 or all or none), or confirm to proceed with the current selection."
- Options: "Proceed with selection" | "Select all" | "Deselect all" | "Let me pick" | "Cancel"
If "Let me pick", ask for comma-separated numbers.
Step 5: Analyze Selected Sources
For each selected source:
- Read the full content (local file) or use the already-fetched content (URL).
- Classify the content:
- Actionable knowledge: Rules, conventions, patterns, constraints, decisions, gotchas, architecture decisions, API contracts — things that change how Claude Code should work. This belongs in the KB.
- Reference material: Tutorials, onboarding docs, API references that are informational but don't contain actionable rules. Flag but allow ingestion if the user wants.
- Not suitable: Binary content, auto-generated docs, pure changelogs, or empty/trivial content. Inform the user and skip.
- Propose a KB destination:
- Suggest a file path under
docs/kb/ using subfolder organization based on the content topic and module name (e.g., docs/kb/external/billing-api-conventions.md, docs/kb/conventions/auth-token-handling.md). Use existing folder structure as a guide.
- Check existing KB files for topic overlap — propose appending if a good match exists.
- Suggest tags: Include
module:{module-name} automatically for local sources. Add topic-specific tags inferred from content.
- Build "When to Load": Construct the structured loading context:
- Extract or infer scope glob patterns from the content (e.g.,
src/billing/**).
- Use the suggested tags as keywords.
- Format as:
`scope-glob1` — keyword1, keyword2
- Example:
`src/billing/**` — module:billing, api, conventions
Step 6: Present Ingestion Plan
Show a consolidated plan for all selected sources. Use AskUserQuestion:
KB Harvest — Ingestion Plan
=============================
1. C:/Source/billing/docs/api-conventions.md
→ NEW: docs/kb/billing-api-conventions.md
→ Tags: [module:billing, api, conventions, rest]
→ When to Load: `src/billing/**` — module:billing, api, conventions
→ Content type: Actionable knowledge
2. C:/Source/billing/docs/deployment.md
→ APPEND: docs/kb/deployment-procedures.md (existing, topic overlap)
→ Tags: [module:billing, deployment] (merging with existing tags)
→ Content type: Actionable knowledge
3. https://wiki.example.com/billing/api
→ NEW: docs/kb/billing-api-integration.md
→ Tags: [module:billing, api, integration, external]
→ When to Load: — module:billing, api, integration
→ Content type: Reference material (user approved)
- Header: "KB Harvest — Confirm Plan"
- Question: "Review the ingestion plan above. Proceed?"
- Options: "Proceed with all" | "Let me adjust" | "Cancel"
If "Let me adjust", let the user modify destinations, tags, or skip individual items via free-text follow-up.
Step 7: Execute Ingestion
For each approved source:
7a: Draft and Approve New KB File
- Distill the content into KB format:
- Convert prose into concise, actionable rules in imperative voice.
- Remove filler, redundant context, and content that only matters for human reading.
- Organize under clear headings (
## Key Rules, ## Conventions, ## Gotchas, etc.).
- Keep the distilled content focused and scannable.
- Add proper frontmatter with:
- Confirmed tags (always include
module:{name} for local sources)
- Today's date (resolved once via the cross-platform command in the Frontmatter Schema section) for
created and last-updated
source field set to the original file path or URL
related cross-references to existing KB files if applicable
pinned and scope as appropriate
- Present the complete draft (frontmatter + body) for user review before writing. Use AskUserQuestion:
- Header: "KB Harvest — Review: {destination filename}"
- Question: "Here's the drafted KB article for {topic} (
{destination path}), distilled from {source path or URL}. Review the content below and confirm:\n\nyaml\n{full file content with frontmatter}\n"
- Options: "Approve" | "Edit and approve" | "Skip this file"
- If "Edit and approve", accept free-text corrections, apply them, and show the updated draft for final confirmation.
- Only after approval, write the file to the confirmed
docs/kb/ path.
Processing order: Present each file one at a time so the user can focus. If many files were selected, after the first 3, offer a shortcut: "Approve remaining {count} files without individual review?"
7b: Draft and Approve Appending to Existing KB File
- Read the existing KB file.
- Distill only new content that isn't already covered.
- Present the diff (new content being appended) for user review. Use AskUserQuestion:
- Header: "KB Harvest — Append to: {existing filename}"
- Question: "The following content will be appended to
{existing file path}. Review and confirm:\n\n\n{new content being added}\n\n\nFrontmatter updates: {list tag/source/date changes}"
- Options: "Approve" | "Edit and approve" | "Skip"
- Only after approval, append new rules under the appropriate section. Do not duplicate existing entries.
- Update frontmatter (only if content actually changed):
7c: Update CLAUDE.md Table
- Remove placeholder row if present ("No entries yet").
- Add or update the row with the confirmed Topic, File path, and When to Load.
- For pinned KB files, set "When to Load" to "Always (pinned)".
- For non-pinned files, format the "When to Load" column using the structured format:
`scope-glob1`, `scope-glob2` — tag1, tag2. Derive scope patterns from the file's scope frontmatter and keywords from tags.
- Deduplicate: If a row for the same file already exists, update it rather than adding a duplicate.
- Sort the table alphabetically by Topic.
7d: Cross-References
After all ingestions are complete:
- Scan newly created KB files for related topics with each other and with existing KB files.
- Add
related cross-references in frontmatter where there's clear topical overlap.
- Add or update the
## Related body section on any file whose related frontmatter was modified (keep them in sync).
Step 8: Update Index and Log
- Update
docs/kb/_index.md: If this file exists, add entries for all newly created/updated KB files with one-line summaries. Update last-updated in its frontmatter.
- Append to
docs/kb/_log.md: If this file exists, append:## [YYYY-MM-DD] harvest | Harvested {count} sources
- Sources: {list of source paths/URLs}
- Created: {list of new KB files}
- Updated: {list of updated KB files}
Step 9: Summary
Display a final summary:
KB Harvest — Complete
======================
Harvested {count} sources into the knowledge base:
## New KB Files Created ({count})
- docs/kb/billing-api-conventions.md ← C:/Source/billing/docs/api-conventions.md
Key content: REST naming conventions, pagination rules, error response format
- docs/kb/billing-api-integration.md ← https://wiki.example.com/billing/api
Key content: Authentication flow, rate limits, webhook setup
## Existing KB Files Updated ({count})
- docs/kb/deployment-procedures.md ← C:/Source/billing/docs/deployment.md
Added: billing-specific deployment steps, environment variable requirements
## CLAUDE.md Table
- {count} rows added, {count} rows updated
## Provenance
All harvested entries have a `source` field in their frontmatter tracking the
original location. Re-run `/kb-harvest` with the same sources to refresh if
the source documentation is updated.
Source files/URLs were NOT modified or deleted.
Quality Rules
- Distill, don't copy-paste: The KB file should be a concise, actionable version of the source. Long documentation should become focused rules. This is the single most important rule.
- No secrets: Never store API keys, tokens, passwords, connection strings, or internal hostnames/IPs. Store patterns/rules instead (e.g., "API keys must come from environment variables").
- No duplication: Check existing KB files before writing. If content already exists, skip it.
- Maintain frontmatter: Every KB file write must include valid, complete frontmatter with the
source provenance field.
- Preserve sources: Never modify or delete source files. Never modify content at URLs. The user decides what to do with originals.
- Module tagging: Always add
module:{name} tag for content harvested from local repos/directories. This enables filtering KB entries by module.
- URL content safety: When fetching URLs, do not store any authentication tokens, session data, or cookie values that may appear in the fetched content. Strip these before distilling.
1---2name: kb-harvest3description: Harvest knowledge from external sources — sibling repos, local directories, individual files, or web URLs — and distill them into the KB system with provenance tracking.4---56# Knowledge Base Harvest78You are a cross-source knowledge harvester. Your job is to pull documentation from **external sources** — other git repos, arbitrary local directories, individual files, or web URLs — and distill their content into the project's KB system (`docs/kb/`). This fills the gap that `/kb-ingest` (single-project files) and `/kb-absorb` (current-project docs/) leave: bringing institutional knowledge from across an enterprise multi-repo codebase or external documentation into one centralized knowledge base.910## Frontmatter Schema1112Every KB file MUST have valid YAML frontmatter. This skill adds a `source` field for provenance tracking:1314```yaml15---16tags: [topic-tag-1, module:module-name] # Required: lowercase tags for discovery. Auto-add module tag.17related: [[other-kb-file]] # Optional: cross-references to related KB files18created: YYYY-MM-DD # Required: date created19last-updated: YYYY-MM-DD # Required: date last modified (update on every write)20pinned: false # Optional: true = always loaded. Default false21scope: "src/api/**" # Optional: glob pattern(s) for auto-matching. String or array.22source: "C:/Source/billing-module/docs/api-conventions.md" # Required for harvested content: original source path or URL23---24```2526The `source` field is what distinguishes harvested KB entries from organically captured ones. It enables future re-harvesting if source docs are updated.2728**Resolving today's date (cross-platform, CRITICAL)**: Never guess, infer, or increment prior dates. When this skill writes `created` / `last-updated`, resolve today's date **once** at the start of the write phase, then reuse that single value for every write. Try these commands in order and use the first that returns a `YYYY-MM-DD` string:2930- **macOS / Linux / WSL / Git Bash** (bash, zsh, sh): `date +%Y-%m-%d`31- **Windows PowerShell / pwsh**: `Get-Date -Format 'yyyy-MM-dd'`32- **Windows cmd.exe**: `powershell -NoProfile -Command "Get-Date -Format 'yyyy-MM-dd'"`33- **Portable fallback** (Node or Python available): `node -e "console.log(new Date().toISOString().slice(0,10))"` or `python -c "import datetime; print(datetime.date.today().isoformat())"`3435Only update `last-updated` when the file's content actually changed. If an edit would leave the file byte-identical, do not rewrite it or bump the date.3637## Obsidian-Compatible Related Links3839When a KB file has `related` entries in its frontmatter, you MUST also include a `## Related` section at the **end** of the file body with the same references as `[[wiki-links]]`. This enables Obsidian graph view and link navigation. Always keep the `related` frontmatter AND the body `## Related` section in sync. If there are no related files, omit the section entirely.4041## Instructions4243### Step 1: Determine Input Sources4445Check if the user provided source(s) after the command. Sources can be **mixed** — any combination of:4647- **Directory paths** (local): e.g., `C:/Source/billing-module/docs/` or `/repos/auth-service/docs`48- **File paths** (local): e.g., `C:/Source/billing-module/docs/api-guide.md`49- **Glob patterns** (local): e.g., `C:/Source/*/docs/**/*.md`50- **Web URLs**: e.g., `https://wiki.internal.company.com/billing/api-patterns`5152**If source(s) provided**: Parse and categorize each as directory, file, glob, or URL.53**If no source provided**: Ask the user using AskUserQuestion:54- Header: "KB Harvest — Sources"55- Question: "What would you like to harvest? You can provide any mix of:\n- **Directory paths** to scan for markdown files (e.g., `C:/Source/billing/docs/`)\n- **File paths** for specific files (e.g., `C:/Source/billing/docs/api-guide.md`)\n- **Glob patterns** (e.g., `C:/Source/*/docs/**/*.md`)\n- **Web URLs** to fetch and distill (e.g., `https://wiki.example.com/some-page`)\n\nEnter one or more sources (space-separated or one per line):"5657### Step 2: Prerequisite Check58591. **Check for KB section in CLAUDE.md**: Read the project's CLAUDE.md and look for the Knowledge Base table. If it doesn't exist, inform the user to run `/kb-init` first and stop.602. **Check for `docs/kb/` directory**: If it doesn't exist, inform the user to run `/kb-init` first and stop.6162### Step 3: Discovery6364Process each source and build a discovery report:6566#### 3a: Local Directories67681. Use Glob to find all `.md` files recursively within the directory.692. Exclude common non-documentation files: `CHANGELOG.md`, `LICENSE.md`, `node_modules/`, `.git/`, `dist/`, `build/`, `coverage/`.703. For each file found, read the first ~30 lines to get a title/summary.714. **Infer module name** from the directory structure:72 - If the path looks like `{base}/{module-name}/docs/...`, use `{module-name}` as the module tag.73 - If the path looks like `{base}/{module-name}/...`, use `{module-name}`.74 - If ambiguous, use the immediate parent directory of the docs folder.7576#### 3b: Individual Files77781. Verify the file exists and is readable.792. Read the first ~30 lines for title/summary.803. Infer module name from the file's directory path (same logic as 3a).8182#### 3c: Glob Patterns83841. Execute the glob pattern using the Glob tool.852. Apply the same exclusions as 3a.863. For each matched file, read first ~30 lines.874. Infer module name per file.8889#### 3d: Web URLs90911. Use WebFetch to retrieve the page content for each URL.922. If the fetch fails, report the error and mark the URL as FAILED in the discovery report.933. Extract the page title and a brief summary from the fetched content.944. **Infer a topic name** from the URL path segments and page title.9596### Step 4: Present Discovery Report9798Display a grouped report. Use AskUserQuestion after the report:99100```101KB Harvest — Discovery Report102==============================103104## Local Sources105106### module-name (C:/Source/module-name/docs/) — {count} files107 1. [x] api-conventions.md — "API Conventions and Patterns"108 2. [x] deployment.md — "Deployment Procedures"109 3. [x] troubleshooting.md — "Common Issues and Fixes"110111### other-module (C:/Source/other-module/docs/) — {count} files112 4. [x] data-model.md — "Data Model Reference"113 5. [ ] README.md — "Module README" (likely not KB material)114115## Web Sources — {count} URLs116 6. [x] https://wiki.example.com/billing/api — "Billing API Integration Guide"117 7. [ ] https://wiki.example.com/onboarding — FAILED: 404 Not Found118119Total: {count} sources ready for harvest120```121122Pre-check files that look like they contain actionable knowledge. Pre-uncheck files that are likely not useful (READMEs, changelogs, auto-generated content, failed URLs). The user can toggle selections.123124- Header: "KB Harvest — Select Sources"125- Question: "Which sources would you like to harvest? Enter the numbers to toggle (e.g., `1,3,5` or `all` or `none`), or confirm to proceed with the current selection."126- Options: "Proceed with selection" | "Select all" | "Deselect all" | "Let me pick" | "Cancel"127128If "Let me pick", ask for comma-separated numbers.129130### Step 5: Analyze Selected Sources131132For each selected source:1331341. **Read the full content** (local file) or **use the already-fetched content** (URL).1352. **Classify the content**:136 - **Actionable knowledge**: Rules, conventions, patterns, constraints, decisions, gotchas, architecture decisions, API contracts — things that change how Claude Code should work. This belongs in the KB.137 - **Reference material**: Tutorials, onboarding docs, API references that are informational but don't contain actionable rules. Flag but allow ingestion if the user wants.138 - **Not suitable**: Binary content, auto-generated docs, pure changelogs, or empty/trivial content. Inform the user and skip.1393. **Propose a KB destination**:140 - Suggest a file path under `docs/kb/` using subfolder organization based on the content topic and module name (e.g., `docs/kb/external/billing-api-conventions.md`, `docs/kb/conventions/auth-token-handling.md`). Use existing folder structure as a guide.141 - Check existing KB files for topic overlap — propose appending if a good match exists.1424. **Suggest tags**: Include `module:{module-name}` automatically for local sources. Add topic-specific tags inferred from content.1435. **Build "When to Load"**: Construct the structured loading context:144 - Extract or infer scope glob patterns from the content (e.g., `src/billing/**`).145 - Use the suggested tags as keywords.146 - Format as: `` `scope-glob1` — keyword1, keyword2 ``147 - Example: `` `src/billing/**` — module:billing, api, conventions ``148149### Step 6: Present Ingestion Plan150151Show a consolidated plan for all selected sources. Use AskUserQuestion:152153```154KB Harvest — Ingestion Plan155=============================1561571. C:/Source/billing/docs/api-conventions.md158 → NEW: docs/kb/billing-api-conventions.md159 → Tags: [module:billing, api, conventions, rest]160 → When to Load: `src/billing/**` — module:billing, api, conventions161 → Content type: Actionable knowledge1621632. C:/Source/billing/docs/deployment.md164 → APPEND: docs/kb/deployment-procedures.md (existing, topic overlap)165 → Tags: [module:billing, deployment] (merging with existing tags)166 → Content type: Actionable knowledge1671683. https://wiki.example.com/billing/api169 → NEW: docs/kb/billing-api-integration.md170 → Tags: [module:billing, api, integration, external]171 → When to Load: — module:billing, api, integration172 → Content type: Reference material (user approved)173```174175- Header: "KB Harvest — Confirm Plan"176- Question: "Review the ingestion plan above. Proceed?"177- Options: "Proceed with all" | "Let me adjust" | "Cancel"178179If "Let me adjust", let the user modify destinations, tags, or skip individual items via free-text follow-up.180181### Step 7: Execute Ingestion182183For each approved source:184185#### 7a: Draft and Approve New KB File1861871. **Distill the content** into KB format:188 - Convert prose into concise, actionable rules in imperative voice.189 - Remove filler, redundant context, and content that only matters for human reading.190 - Organize under clear headings (`## Key Rules`, `## Conventions`, `## Gotchas`, etc.).191 - Keep the distilled content focused and scannable.1922. **Add proper frontmatter** with:193 - Confirmed tags (always include `module:{name}` for local sources)194 - Today's date (resolved once via the cross-platform command in the Frontmatter Schema section) for `created` and `last-updated`195 - `source` field set to the original file path or URL196 - `related` cross-references to existing KB files if applicable197 - `pinned` and `scope` as appropriate1983. **Present the complete draft** (frontmatter + body) for user review before writing. Use AskUserQuestion:199 - Header: "KB Harvest — Review: {destination filename}"200 - Question: "Here's the drafted KB article for **{topic}** (`{destination path}`), distilled from `{source path or URL}`. Review the content below and confirm:\n\n```yaml\n{full file content with frontmatter}\n```"201 - Options: "Approve" | "Edit and approve" | "Skip this file"202 - If "Edit and approve", accept free-text corrections, apply them, and show the updated draft for final confirmation.2034. **Only after approval**, write the file to the confirmed `docs/kb/` path.204205**Processing order**: Present each file one at a time so the user can focus. If many files were selected, after the first 3, offer a shortcut: "Approve remaining {count} files without individual review?"206207#### 7b: Draft and Approve Appending to Existing KB File2082091. **Read the existing KB file**.2102. **Distill only new content** that isn't already covered.2113. **Present the diff** (new content being appended) for user review. Use AskUserQuestion:212 - Header: "KB Harvest — Append to: {existing filename}"213 - Question: "The following content will be appended to `{existing file path}`. Review and confirm:\n\n```\n{new content being added}\n```\n\nFrontmatter updates: {list tag/source/date changes}"214 - Options: "Approve" | "Edit and approve" | "Skip"2154. **Only after approval**, append new rules under the appropriate section. Do not duplicate existing entries.2165. **Update frontmatter** (only if content actually changed):217 - Update `last-updated` to the date resolved at the start of the write phase.218 - Merge new tags (preserving existing ones).219 - Add the new source to the `source` field. If `source` already has a value, convert to a list:220 ```yaml221 source:222 - "original/path.md"223 - "C:/Source/billing/docs/new-content.md"224 ```225 - Add new `related` cross-references if applicable.226227#### 7c: Update CLAUDE.md Table2282291. **Remove placeholder row** if present ("_No entries yet_").2302. **Add or update the row** with the confirmed Topic, File path, and When to Load.231 - For pinned KB files, set "When to Load" to "Always (pinned)".232 - For non-pinned files, format the "When to Load" column using the structured format: `` `scope-glob1`, `scope-glob2` — tag1, tag2 ``. Derive scope patterns from the file's `scope` frontmatter and keywords from `tags`.2333. **Deduplicate**: If a row for the same file already exists, update it rather than adding a duplicate.2344. **Sort the table** alphabetically by Topic.235236#### 7d: Cross-References237238After all ingestions are complete:2391. Scan newly created KB files for related topics with each other and with existing KB files.2402. Add `related` cross-references in frontmatter where there's clear topical overlap.2413. Add or update the `## Related` body section on any file whose `related` frontmatter was modified (keep them in sync).242243### Step 8: Update Index and Log2442451. **Update `docs/kb/_index.md`**: If this file exists, add entries for all newly created/updated KB files with one-line summaries. Update `last-updated` in its frontmatter.2462. **Append to `docs/kb/_log.md`**: If this file exists, append:247 ```248 ## [YYYY-MM-DD] harvest | Harvested {count} sources249 - Sources: {list of source paths/URLs}250 - Created: {list of new KB files}251 - Updated: {list of updated KB files}252 ```253254### Step 9: Summary255256Display a final summary:257258```259KB Harvest — Complete260======================261262Harvested {count} sources into the knowledge base:263264## New KB Files Created ({count})265- docs/kb/billing-api-conventions.md ← C:/Source/billing/docs/api-conventions.md266 Key content: REST naming conventions, pagination rules, error response format267- docs/kb/billing-api-integration.md ← https://wiki.example.com/billing/api268 Key content: Authentication flow, rate limits, webhook setup269270## Existing KB Files Updated ({count})271- docs/kb/deployment-procedures.md ← C:/Source/billing/docs/deployment.md272 Added: billing-specific deployment steps, environment variable requirements273274## CLAUDE.md Table275- {count} rows added, {count} rows updated276277## Provenance278All harvested entries have a `source` field in their frontmatter tracking the279original location. Re-run `/kb-harvest` with the same sources to refresh if280the source documentation is updated.281282Source files/URLs were NOT modified or deleted.283```284285## Quality Rules286287- **Distill, don't copy-paste**: The KB file should be a concise, actionable version of the source. Long documentation should become focused rules. This is the single most important rule.288- **No secrets**: Never store API keys, tokens, passwords, connection strings, or internal hostnames/IPs. Store patterns/rules instead (e.g., "API keys must come from environment variables").289- **No duplication**: Check existing KB files before writing. If content already exists, skip it.290- **Maintain frontmatter**: Every KB file write must include valid, complete frontmatter with the `source` provenance field.291- **Preserve sources**: Never modify or delete source files. Never modify content at URLs. The user decides what to do with originals.292- **Module tagging**: Always add `module:{name}` tag for content harvested from local repos/directories. This enables filtering KB entries by module.293- **URL content safety**: When fetching URLs, do not store any authentication tokens, session data, or cookie values that may appear in the fetched content. Strip these before distilling.