| name | analyze |
| description | Analyze a repo's patterns and generate a tailored Claude Code config |
| when_to_use | Use when a repo needs its patterns extracted into a tailored Claude Code config — CLAUDE.md, agents, rules, and skills generated and committed straight to main — the config-generator lane, distinct from /learn which mines org-wide conventions into memory. Triggers on: analyze <repo>, generate config for this repo, repo config generator. |
| argument-hint | [repo-path] [--dry-run] |
Analyze — Repo Config Generator
Analyze any repo's patterns and generate a complete .claude/ configuration, committed straight to main.
Usage
/analyze hogwarts — analyze hogwarts, commit config to main
/analyze databayt/souq — analyze from GitHub
/analyze . — analyze current directory
/analyze hogwarts --dry-run — preview without committing
/analyze hogwarts --update — refresh existing config
/analyze hogwarts --profile core — generate for specific profile
Argument: $ARGUMENTS
Instructions
Parse arguments:
- First arg = repo (name, path, or GitHub URL)
--dry-run = output to stdout, no commit
--update = diff against existing .claude/, update stale config
--profile <name> = generate for specific profile (core, security, developer, full)
The Clean GitHub Cycle
Work directly on main — no branches, no worktrees, no PRs. Every analyze run follows this workflow:
Issue (opt.) → Analyze → Commit → Push `main` → Verify → Close
Step 1: Resolve Repo
if [ -d "/Users/abdout/$REPO" ]; then
cd /Users/abdout/$REPO
elif echo "$REPO" | grep -q "/"; then
gh repo clone $REPO /tmp/analyze-$REPO
cd /tmp/analyze-$REPO
fi
Step 2: Create Tracking Issue (optional)
gh issue create \
--repo databayt/$REPO \
--title "chore: generate repo config from pattern analysis" \
--body "Automated analysis of repository patterns to generate \`.claude/\` configuration.
## What will be generated
- \`CLAUDE.md\` — project instructions
- \`agents/\` — relevant agent subset
- \`rules/\` — extracted conventions
- \`commands/\` — mapped skills
Triggered by \`/analyze\` command."
Step 3: Verify Branch
Work happens directly on main — there is no branch step. Just confirm you are on main and up to date:
git branch --show-current
git pull --rebase origin main
Step 4: Run Analysis Pipeline
4a. Stack Detection
cat package.json | jq '{
name: .name,
deps: (.dependencies // {} | keys),
devDeps: (.devDependencies // {} | keys)
}'
Map to technologies:
next → Next.js (check version)
react → React (check version)
prisma → Prisma (check version)
tailwindcss → Tailwind
@radix-ui/* → Radix/shadcn
next-auth → Auth.js
zod → Zod validation
4b. Structure Detection
ls app/ 2>/dev/null && echo "App Router" || echo "Pages Router"
ls src/ 2>/dev/null && echo "src/ prefix"
find . -path '*/components/*' -name '*.tsx' -not -path '*/node_modules/*' | head -20
cat prisma/schema.prisma 2>/dev/null | head -30
4c. Convention Sampling
Read 10 representative files and extract patterns:
- 3 page files → how routes are structured
- 2 server actions → auth/validation/execution pattern
- 2 components → naming, structure, imports
- 1 form → validation approach
- 1 middleware → auth/routing logic
- 1 layout → metadata, providers, guards
For each file, note:
- Imports (barrel vs direct, package choices)
- Patterns (auth checks, error handling, data fetching)
- Naming (files, variables, functions, components)
- Structure (export style, organization)
4d. Git Pattern Analysis
git log --oneline -20
git log --format=format: --name-only -100 | sort | uniq -c | sort -rn | head -10
git log --oneline --since="2 weeks ago"
Step 5: Generate Config
Create .claude/ directory and files:
CLAUDE.md
# <Repo Name>
## Stack
<detected technologies with versions>
## Conventions
<extracted patterns — only what's actually observed>
## Structure
<directory layout conventions>
## Keywords
<relevant subset from Kun's keyword map>
Keep under 200 lines. Concise beats comprehensive.
agents/ (selective)
Only include agents the repo needs. Use this mapping:
| Detected | Agents |
|---|
| Next.js | nextjs, react, middleware |
| TypeScript | typescript, build |
| Prisma | prisma, architecture |
| Tailwind/shadcn | tailwind, shadcn, semantic |
| Auth.js | authjs, guardian |
| i18n | internationalization |
| Tests | test |
| Components dir | atom, template, block |
| Vercel deploy | deploy, ops |
| Git/GitHub | git, github |
Create a minimal _index.md listing selected agents with reasons.
rules/ (from observations)
Each rule = one observed convention worth enforcing:
# rules/<convention>.md
<what the convention is>
<evidence: "observed in N/M sampled files">
Only create rules for patterns with >80% consistency. Inconsistent patterns get flagged as suggestions, not rules.
commands/ (relevant subset)
Only commands that match the repo's workflow. Always include: dev, build. Conditionally include based on detected stack.
Step 6: Commit + Push to main
Commit straight to main — no branch, no PR. Put the analysis summary in the commit body.
git add .claude/
git commit -m "chore: generate repo config from pattern analysis
Auto-generated .claude/ configuration from repository pattern analysis.
Analysis scope: <N> commits analyzed, <M> files sampled, <P> conventions extracted.
Generated config:
- CLAUDE.md — project instructions (<lines> lines)
- agents/ — <N> agents selected (of 44 available)
- rules/ — <N> rules from observed patterns
- commands/ — <N> skills mapped to workflow
Recommended profiles: core (<list>) / security (<list>) / full (<list>).
Review each file — a starting point, not gospel.
Closes #<issue-number>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>"
git push origin main
--dry-run Mode
Skip steps 2 and 6. Output generated config to stdout with clear section headers. No files written, no commit.
--update Mode
- Read existing
.claude/ config
- Run analysis pipeline
- Diff generated vs existing
- Commit only the changes to
main (new conventions, removed stale rules, updated agents)
- Commit title:
chore: update repo config — N conventions added, M stale removed
--profile Mode
Filter generated config to only include agents, rules, and commands relevant to the specified profile.
Quality Gates
Before committing to main:
Rule: The best config is the one the team was already following. Analyze just makes it explicit, reviewable, and enforceable.