Claude Code skill that generates structured product knowledge bases from codebase scanning
SaferSkills independently audited codewiki (Agent Skill) and scored it 87/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 3 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 3 flagged
The text {match} tells the agent to skip the normal "ask the user first" gate. Used adversarially it removes the human-in-the-loop check before destructive or sensitive actions, turning a normally-gated agent into a fire-and-forget executor.
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Scan code, fetch product context, discover user flows, and generate a structured codewiki/ knowledge base.
Output templates are in this skill's templates/ directory. Read each template only when generating that specific file — do NOT load all templates at once.
_scratch/ → Carry 30-line summary → Next. This is how you survive large multi-repo projects.STOP. You MUST complete Phase 1 before scanning any code. Do not runls,grep, or read any files until Phase 1 is done. If the user says "just scan the code" or tries to skip, explain that the wiki quality depends heavily on product context and ask them to answer at least questions 1–3 before proceeding.
Ask all of these in a single message. Mark which are required vs. optional:
Code-first fallback: If user says they can't answer 1–3, say: "No problem — I'll scan the code first and come back with my best guess for you to correct." Infer product name from package.json name field or README title, one-liner from package.json description or README first paragraph, users from UI/API patterns (admin dashboard = internal ops, public signup = consumers, API-only = developers). Present guesses for confirmation before continuing to Phase 2.
For multi-repo products, all repos MUST be cloned into a single parent folder. This is how CodeWiki discovers cross-repo relationships.
Expected structure:
<product-name>/ ← master folder
├── backend/ ← git clone <backend-url>
├── frontend/ ← git clone <frontend-url>
├── mobile-app/ ← git clone <mobile-url>
├── comms-service/ ← git clone <comms-url>
├── shared-libs/ ← git clone <shared-url>
└── infra/ ← git clone <infra-url>If repos are not yet organized this way, give the user exact commands:
mkdir -p ~/projects/<product-name> && cd ~/projects/<product-name>
git clone <url-1> <folder-name-1>
git clone <url-2> <folder-name-2>
# ... etcThen ask the user to cd into the master folder and run CodeWiki from there.
Verify the setup:
ls -la
for dir in */; do echo "$dir: $(git -C "$dir" remote get-url origin 2>/dev/null || echo 'not a git repo')"; doneIf any repos are missing, tell the user which ones and provide the clone command. Do NOT proceed to Phase 2 until the workspace is verified.
For each URL provided, use WebFetch to extract product context.
Error handling: If a URL fails (auth wall, 404, timeout), tell the user which URL failed and why, then continue with the rest. Do not silently skip.
For each successful fetch, extract:
Present a short summary back to the user:
"Here's what I understand about [Product Name] before I look at the code: ..."
Ask: "Is this accurate? Anything to correct or add?"
Only after the user confirms, proceed to Phase 2.
After confirmation, estimate scope:
"Based on [N repos/components], this will take [several phases]. I'll report progress after each repo/component."
CRITICAL: Do NOT scan all repos at once. Scanning multiple repos simultaneously will exhaust the context window. Instead, use the Scan → Summarize → Flush → Next pattern described below.
Scan in this order. The goal is top-down: infrastructure first (the "map"), then entry points, then services behind them.
Priority 1 — Infrastructure & contracts (scan first)
infra/, deploy/, platform/ — docker-compose, k8s manifests, terraformWhy first: Gives you the full service map, ports, dependencies, and contracts before any individual service. It's the table of contents.
Priority 2 — API gateway / BFF (Backend-for-Frontend)
gateway, api-gateway, bff, proxyWhy second: Shows all user-facing endpoints and which internal service handles each one.
Priority 3 — Frontend(s)
Why third: Now you can map screens → gateway endpoints → internal services.
Priority 4 — Core business services
Priority 5 — Supporting services
For each repo/service, follow this cycle:
1. SCAN Read the repo: tech stack, endpoints, models, events, env vars
2. WRITE Write findings to codewiki/_scratch/<repo-name>.md (on disk)
3. SUMMARIZE Create a compact summary (max 30 lines) of:
- What this service does (1-2 sentences)
- Endpoints it exposes (list)
- Events it produces/consumes (list)
- Data models it owns (list)
- How it connects to other services (list)
4. CARRY Keep ONLY the compact summary in working memory
5. NEXT Move to the next repo — raw scan data is on disk, not in contextThe `_scratch/` folder:
codewiki/
├── _scratch/ ← temporary, per-repo scan notes
│ ├── backend.md
│ ├── frontend.md
│ ├── comms-service.md
│ └── ...
├── overview.md ← final output files (generated in Phase 5)
├── architecture.md
└── ...Compact summary format (carried between repo scans):
## <service-name> | <tech stack> | <port>
Purpose: <one sentence>
Endpoints: GET /users, POST /users, GET /users/:id, ...
Produces: user.created, user.updated
Consumes: payment.completed
Models: User, Role, Session
Calls: payment-service (gRPC), notification-service (HTTP)
DB: postgres (users, roles, sessions tables)After scanning each repo, tell the user:
"✓ Scanned backend (3/6 repos done). Found 14 endpoints, 3 event topics, 5 models. Next up: comms-service. Continuing..."
Do NOT ask for permission between each repo — just report progress and continue.
Single-repo projects:
ls -la
find . -maxdepth 2 -type f -name "*.json" -o -name "*.toml" -o -name "*.yaml" -o -name "*.yml" -o -name "*.mod" -o -name "*.lock" | head -50Multi-repo master folder:
ls -la
for dir in */; do
echo "=== $dir ==="
ls "$dir"/*.json "$dir"/*.toml "$dir"/*.yaml "$dir"/*.yml "$dir"/*.mod "$dir"/Dockerfile 2>/dev/null
echo ""
doneIdentify:
For multi-repo, present the inventory:
"I found [N] repos in this workspace: | Folder | Likely role | Stack signals | |--------|------------|---------------| | backend/ | API server | go.mod, Dockerfile | | frontend/ | Web app | package.json (next), tsconfig.json | | ...
>
I'll scan them in this order: [list in priority order]. Starting now."
#### Architecture Classification
Classify the project:
Detection signals for microservices:
docker-compose.yml defining multiple services with separate build contextsDockerfilego.mod, package.json, requirements.txt)State your classification to the user before proceeding.
#### Scoping Gate
If microservices or multi-service architecture: Do NOT ask the user to skip services. Instead, use a two-tier scan:
"This is a microservices project with [N] services. I found: [list them]. I'll do a lightweight scan of all services first to map the full topology, then a deep scan of the [3–4] most critical ones. Which services are most critical to document in depth?"
Lightweight scan (ALL services): tech stack, exposed endpoints/topics/events, data models owned, env vars, Dockerfile/deployment config. Deep scan (user-selected): internal code structure, handler logic, error handling, full file mapping, test coverage.
If monolith or single app with many modules:
"This is a large project with [N] components. I found: [list them]. Which ones should I focus on? I recommend starting with [top 3–4 by importance], and I can document the rest in a follow-up pass."
Wait for user to confirm scope before continuing.
#### Infrastructure-as-Architecture (Microservices only)
Before scanning individual services, read the infrastructure layer — it IS the architecture map:
# Docker compose — shows service dependencies, ports, networks
cat docker-compose*.yml 2>/dev/null
# Kubernetes — shows deployments, services, ingress
find . -path "*/k8s/*" -o -path "*/helm/*" -o -path "*/kubernetes/*" | head -30
# API gateway config
find . -name "nginx.conf" -o -name "kong.yml" -o -name "traefik.*" -o -name "envoy.*" | head -10
# Message broker config
find . -name "*.proto" -o -name "asyncapi.*" -o -name "*.avsc" | head -20From this, build an initial service topology before looking at any service code:
Present this topology to the user for confirmation before deep-scanning individual services.
For each component in scope, analyze:
Tech stack — Read dependency/config files:
If none of the above exist, check for other indicators (Gemfile, pom.xml, build.gradle, mix.exs, etc.) and adapt accordingly. Don't assume a fixed set of languages.
Entry points — Find main files:
main.*, index.*, app.*, server.* in src/ or rootmain/bin fields, or [tool.poetry.scripts], etc.Routes/Screens — Discover user-facing paths:
app.get, etc.)API endpoints — Find all route/handler definitions:
@Get, @Post, app.get(, router., etc.)Data models — Find schemas and types:
migrations/, db/migrate/, alembic/Environment variables — Find config:
.env.example, .env.sample, .env.templateprocess.env, os.environ, os.Getenv, etc.Build/run/test commands — Find all dev commands:
#### Additional Fields for Microservices
If the project was classified as microservices, also capture for EACH service:
Service identity:
Data ownership:
Events & messages (produced and consumed):
publish(, emit(, produce(, subscribe(, consume(, on(, queue/topic name strings in config filesSynchronous service-to-service calls:
localhost:<port> in dev configs)depends_on to find call directionService contracts:
.proto) — who defines them, who consumes themDiscover how components connect:
#### Additional mapping for microservices:
Service dependency graph — Build a complete picture of which service calls which:
| Source Service | Target Service | Protocol | Purpose |
|---|---|---|---|
| api-gateway | user-service | REST | Auth, user lookup |
| user-service | notification-service | Kafka | Send welcome email on signup |
| billing-service | user-service | gRPC | Validate user plan |
To build this table:
depends_on and kubernetes service definitionsData ownership map — Which service owns which data:
| Data Entity | Owner Service | Shared With | Access Method |
|---|---|---|---|
| User | user-service | all services | REST API / JWT claims |
| Invoice | billing-service | admin-dashboard | REST API |
Async flow chains — For event-driven patterns, trace the full chain:
Example: User signs up → user-service publishes user.created → notification-service sends welcome email → billing-service creates free trialDocument every async chain by matching published topics to consumed topics across services. These are invisible in HTTP-only tracing and often the most poorly documented part of any system.
Present a structured summary of what you discovered in Phase 2:
Then propose flows you inferred from code:
"Based on what I found, I think the main user flows are: 1. User signup/onboarding 2. Create a project 3. Invite a teammate 4. ...
>
Add, remove, or reorder these, then I'll document each one."
The user confirms the list in one pass.
For each confirmed flow, generate documentation from code analysis first. Then present your draft and ask:
For each flow, also:
#### Multi-Service Flow Tracing (microservices only)
For each step in a flow, trace the full service chain:
Also ask: "After [step], does anything happen in the background that the user doesn't see? (e.g., emails sent, records synced, jobs queued)"
Confirm traced chains with the user — async flows are the hardest to discover from code alone.
For each flow, generate user stories:
As a [user type], I want to [action] so that [benefit].
Present all stories for validation.
Ask: "Are there other flows I should document? If not, I'll confirm the architecture and start generating the wiki."
Before generating any files, present a brief architecture summary to the user:
"Here's the architecture I'm about to document: - Architecture type: [single app / microservices / monorepo / etc.] - Components: [list] - Communication: [how they connect] - Auth: [method] - Key data models: [list]
>
Does this look right? Any corrections before I generate the wiki?"
For microservices, also present:
Service dependency summary: | Service | Calls (sync) | Publishes events | Consumes events | Owns DB | |---------|-------------|-----------------|----------------|---------| | api-gateway | user-svc, payment-svc | — | — | No | | user-svc | — | user.created | — | users-db | | payment-svc | user-svc | payment.completed | — | payments-db | | notification-svc | — | — | user.created, payment.completed | No |
>
"Does this service map look right? Are there connections I'm missing?"
Wait for confirmation. This prevents errors from propagating across all output files.
codewiki/
├── overview.md
├── architecture.md
├── service-map.md (microservices only)
├── events.md (microservices only)
├── user-flows/
│ ├── index.md
│ └── <flow-name>.md (one per flow)
├── api-reference.md
├── data-models.md
├── frontend-map.md (skip if no frontend)
├── mobile-map.md (skip if no mobile app)
├── commands.md
├── env-vars.md
└── glossary.mdFor each file:
templates/ directorycodewiki/_scratch/ files for source datacodewiki/Read templates one at a time — do not load all templates simultaneously.
Glossary detection: Scan READMEs, doc comments, and UI strings for capitalized multi-word terms that appear to be domain concepts. Also check for existing glossary/terminology sections. Focus on product-specific terms only — not general programming terms.
Important: Only generate files that are relevant. Skip service-map.md and events.md for single apps. Skip mobile-map.md if no mobile app. Skip frontend-map.md if no frontend.
After all files are generated:
rm -rf codewiki/_scratch/Check if CLAUDE.md exists in the project root.
Read the template from templates/claude-md.md and generate. Remove links for any files that were skipped (e.g., mobile-map.md if no mobile app).
Ask the user:
"CLAUDE.md already exists. Would you like me to: 1. Fresh scan — back up the existing file and replace it entirely 2. Rescan & merge — preserve your manual additions and merge in new findings"
CLAUDE.md.bak, then generate new.Always run this phase — do not skip.
rm -rf codewiki/_scratch/Ask all in a single message:
"The knowledge base is ready. Let me set up the repo:
>
1. Where should the wiki live? - a) Inside this project repo (add codewiki/ folder here) - b) Its own dedicated repo (I'll create a new folder next to this project)>
2. Want me to create a GitHub repo for it? - If yes: What should the repo be named? (default: <product-name>-codewiki) - Should it be public or private? - Which GitHub org/account? (default: your personal account)>
3. Any custom repo description? (default: 'Product knowledge base for <Product Name>')"
Option A — Inside project repo:
git add codewiki/ CLAUDE.md
git commit -m "docs: add codewiki product knowledge base
Generated by CodeWiki. Contains:
- Product overview and architecture docs
- User flow documentation
- API reference and data models
- Service map and environment variable reference"Option B — Dedicated repo:
mkdir -p ../<repo-name>
cp -r codewiki/ ../<repo-name>/codewiki/
cp CLAUDE.md ../<repo-name>/
cd ../<repo-name>
git init
git add -A
git commit -m "Initial codewiki generation"For Option B, also generate README.md using the template from templates/readme.md. Only include rows/sections for files that were actually generated.
Check if gh CLI is available and authenticated:
gh auth status 2>/dev/nullIf `gh` is available and authenticated:
cd ../<repo-name>
gh repo create <org-or-user>/<repo-name> \
--description "<repo description>" \
--<public|private> \
--source . \
--pushIf `gh` is not available: Tell the user:
"I can't create the GitHub repo automatically because the gh CLI isn't installed or authenticated. Here's what to do:>
1. Go to https://github.com/new 2. Create a repo named<repo-name>(<public/private>) 3. Then run: ``bash cd ../<repo-name> git remote add origin [email protected]:<org>/<repo-name>.git git push -u origin main``"
Present to the user:
CodeWiki generation complete!
>
Files created: <list all files in codewiki/>
>
CLAUDE.md: <created new / merged / replaced>
>
Repo: <committed to project repo / created at ../<repo-name>/> <if GitHub: "Pushed to https://github.com/<org>/<repo-name>">
>
Repos scanned: | Repo | Endpoints | Models | Events | Scan depth | |------|-----------|--------|--------|------------| | backend | 14 | 5 | 3 | deep | | frontend | 12 routes | — | — | deep | | comms-service | 4 | 2 | 6 | lightweight |
>
Next steps: - Share the repo URL with your team - Copy CLAUDE.md into whichever repo you're working in for Claude Code context - Run CodeWiki again anytime to update — I'll detect existing files and offer to merge~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.