/claude-init:claude-init [repo-path]from claude-init
Analyzes any codebase and generates a complete .claude/ configuration including CLAUDE.md, agents, skills, rules, and hooks. Use when setting up Claude Code for a new or existing repo.
Ships in claude-init. 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.
None: SKILL.md is the whole skill.
You are an expert at configuring Claude Code for maximum effectiveness on any codebase.
Given a target repository, you will analyze it thoroughly and generate a complete .claude/ configuration.
If $ARGUMENTS is provided, use that as the target repo path.
Otherwise, use the current working directory.
Confirm the target repo path with the user before proceeding.
Run these analyses IN PARALLEL using subagents:
Detect and document:
This is critical. Without tests, Claude can't verify its own work. The entire "AI-native" setup collapses — no QA agent, no /test skill, no /refactor safety net, no /review verification. Tests are the trust layer.
1. Pick the right framework for the stack — see the stack→framework table in reference/test-bootstrap.md (Vitest for modern TS/JS, pytest for Python, built-in runners for Rust/Go/Elixir/Flutter, etc.)
2. Install the test framework:
npm install -D vitest, pip install pytest)3. Write a baseline test suite:
Use subagents in parallel to write tests per layer — unit (Subagent A), API integration (Subagent B, NOT optional when routes exist), frontend components (Subagent C). Full subagent briefs are in reference/test-bootstrap.md.
4. Run the suite and fix failures:
5. Add test commands to package.json / Makefile:
test — run full suitetest:watch — watch mode for developmenttest:coverage — with coverage reporting (if framework supports it)/test skill to match existing patterns exactlyFollow the quality bar in reference/test-bootstrap.md — descriptive names, independent + deterministic tests, behavior over implementation, mocks only at system boundaries, exact expected values (never bare ranges/truthiness), and one consistent import style. It includes BAD vs GOOD assertion examples; read it before writing any test.
If the repo has no ARCHITECTURE.md (or equivalent like docs/architecture.md), generate one at the repo root.
This is the AI-facing documentation layer. CLAUDE.md is the quick reference (loaded every conversation), but ARCHITECTURE.md is the deep context that /plan, /onboard, and the architect agent read on demand — keeping CLAUDE.md lean while giving Claude full project understanding when it needs it.
Use the section-by-section template in reference/architecture-template.md (Overview, System Map, Directory Structure, Data Flow, Key Design Decisions, Module Boundaries, External Dependencies, Entry Points).
Based on the analysis, generate these files in the target repo. Use the templates as starting points, but CUSTOMIZE everything to the specific codebase.
Template resolution: Check these paths in order and use the first that exists:
${CLAUDE_SKILL_DIR}/../../../templates/ (running from cloned repo)~/.claude/claude-init-templates/ (global install via install script)
If neither exists, generate config from scratch using the analysis — templates are helpful but not required.Generate at the repo root. Every always-loaded line either changes behavior or teaches the agent to skim, so place each piece of material in one of three tiers (the write-agent-docs template skill carries the full reasoning):
gate.conf), and git config core.hooksPath .githooks for new clones.## Changing the schema or writing a migration, ## Adding an API route, ## Before pushing. The heading is the relevance signal: an agent doing that work reads it, one doing other work skims past. Put architecture patterns, commit style, stack-specific anti-patterns, and these workflow rules under the narrowest heading that fits:
Write rules at normal volume with their reason: no ALL-CAPS, no IMPORTANT/MUST markers, no <important if> wrappers (urgency makes a rule fire outside the case it was written for), and no blanket lines like "be concise" or "always ask".
Also generate CODING_STANDARDS.md at the repo root from templates/docs/CODING_STANDARDS.md (fill <CHECK_CMD>; add any stack-specific rule found in a CONTRIBUTING guide) and import it from CLAUDE.md with @CODING_STANDARDS.md so /code-review reads it as its standards.
Do NOT restate content Claude can derive by reading the codebase itself — full dependency/version lists already in package.json/Cargo.toml/etc., directory trees ls would show, or verbatim README paragraphs. Every line must save Claude a lookup or encode tribal knowledge it can't get elsewhere (Claude Code's own /doctor flags exactly this anti-pattern in checked-in CLAUDE.md files as of 2.1.206).
Keep it under 80 lines. Every line must earn its place.
Include this line in the CLAUDE.md: Read ARCHITECTURE.md for detailed architecture context before planning or making structural changes.
Include a brief note: Claude automatically follows a development workflow (clarify → plan → implement → test → self-review) scaled to task size. You don't need to invoke /plan or /test manually.
AGENTS.md interop: If the repo already has an AGENTS.md (used by other coding agents), don't create a competing CLAUDE.md — symlink one to the other (ln -s CLAUDE.md AGENTS.md, or the reverse if AGENTS.md is the richer file) so every tool reads the same instructions. If the repo has neither, generate CLAUDE.md and add the AGENTS.md symlink.
.claude/agents/)Generate these agent personas, tuned to the detected stack:
Conditionally include based on detected stack: 6. devops.md — Only if Docker, CI workflows, Terraform, or deployment configs detected. Model: sonnet. 7. writer.md — Only if the project has docs/, README needs work, or API specs exist. Model: haiku.
Each agent must:
memory: project for architect and developer agents (subagent memory persists learnings across sessions — this is the highest-value frontmatter field for repeat work).claude/rules/" in their instructionsModel field options: the aliases opus, sonnet, haiku, fable and full model IDs all work, as does model: inherit (use the main session's model). The tiering above is a default; inherit is the right call for agents whose difficulty tracks the session (e.g. reviewer).
Other frontmatter worth using where the role calls for it (never speculatively): background: true for long-running exploration/research agents, effort: low|medium|high for cheap mechanical agents, isolation: worktree for agents that mutate files and could conflict with the main session, and memory: project when an agent benefits from remembering across sessions (e.g., researcher building up a codebase map).
.claude/rules/)Only generate rules with project-specific content. Generic advice like "validate user input" or "write clean code" is stuff Claude already knows. Every rule must capture something Claude CAN'T infer from reading the code — deployment gotchas, team conventions, architectural decisions, domain-specific constraints.
Always generate:
Conditionally generate (only if project-specific content found):
4. code-style.md — Only if there are non-obvious conventions (unusual import ordering, specific naming patterns, etc.). Skip if the project just uses a standard linter config.
5. api.md — Only if API routes detected. Must reference actual response shapes, error patterns, auth middleware found in the code. Scope with paths:.
6. database.md — Only if ORM/migrations detected. Must reference actual migration patterns, schema conventions. Scope with paths:.
7. frontend.md — Only if frontend components detected. Must reference actual component patterns, state management conventions. Scope with paths:.
8. security.md — Only if the project has specific security patterns (auth middleware, input sanitization, CSP headers). Don't generate generic OWASP advice.
9. performance.md — Only if specific performance patterns found (caching, connection pooling, lazy loading).
The test: for each rule file, ask "would removing this cause Claude to make a mistake on THIS project?" If no, don't generate it.
paths: scoping trades reload guarantees for context savings. Per https://code.claude.com/docs/en/memory ("Instructions seem lost after /compact"): after /compact, the project-root CLAUDE.md is always re-read and re-injected, but a paths:-scoped rule only reloads when Claude subsequently reads a file matching its glob — not automatically. If a rule carries something that must hold no matter what file Claude is touching (a safety-critical constraint, a hard "always/never" rule), put it in CLAUDE.md even if it's project-specific, rather than scoping it with paths: for the context savings.
When updating existing rules (via /update): Never remove project-specific information that was already there. If the existing rule says "React Query staleTime is 5 minutes", keep it — that's a real project detail Claude can't infer. You may restructure, clarify, or add to existing rules, but don't drop specific values, thresholds, or patterns.
Team-shared rule libraries: .claude/rules/ supports symlinks (resolved normally, circular links detected and handled), so an org with a standards repo used across multiple projects can link it in instead of copying:
ln -s ~/shared-claude-rules .claude/rules/shared
ln -s ~/company-standards/security.md .claude/rules/security.md
Separately, ~/.claude/rules/ holds personal rules that apply to every project on the machine (loaded before project rules, so project rules win on conflict) — the right place for an individual's cross-project preferences, distinct from the team-shared symlink case above. Only mention or set these up if the user's setup implies multi-repo rule sharing or personal cross-project rules already exist — never generate symlinks speculatively.
.claude/skills/)Skills are detailed playbooks for specific development activities. They are auto-triggered by the workflow.md rule — Claude follows the development workflow automatically without the user typing slash commands. Users CAN still invoke them manually (e.g., /plan to force just a planning step), but the default is automatic.
Only generate skills that add value beyond what Claude already does. A skill must change Claude's behavior, not just describe a process Claude would follow anyway.
Always generate (auto-triggered by workflow rule):
plan/SKILL.md — Bite-sized implementation planning with devil's advocate challenge. Tasks should be 2-5 minutes each with exact file paths and TDD steps. Auto-triggered for medium+ tasks.
tdd/SKILL.md (in skills/test/) — RED-GREEN-REFACTOR cycle with rationalization prevention. Must reference the project's actual test framework and commands. Auto-triggered during implementation. This replaces a generic "write tests" skill — it enforces test-FIRST, not test-after.
review/SKILL.md — Two-stage review: spec compliance first (does it match what was requested?), then code quality (bugs, security, conventions). Auto-triggered after implementation.
verify/SKILL.md — Verification before completion. No success claims without fresh evidence. Auto-triggered before any "done"/"fixed"/"passing" claim.
clarify/SKILL.md — Collaborative design through structured dialogue. Explores intent, proposes approaches, writes testable specs. Auto-triggered when requirements are ambiguous.
subagent-dev/SKILL.md — Subagent-driven development. Fresh subagent per task + two-stage review (spec compliance → code quality). Auto-triggered for plans with 3+ independent tasks.
finish/SKILL.md — Land completed work. Verify tests, present options (merge/PR/keep/discard), execute with safety checks. Auto-triggered after implementation and review pass.
live-verify/SKILL.md — Reproduce-first plus the adversarial live pass across every path that reaches a behavior. Fill in the project's real surfaces (UI routes, API, jobs, bots) and how to run the app as the production database role.
deslop/SKILL.md (with references/prose-tropes.md) and write-agent-docs/SKILL.md — copy as-is; they keep future CLAUDE.md, skill and doc edits lean.
what-happened/SKILL.md and wait-what/SKILL.md — user-invoked (disable-model-invocation: true), so they cost no context until typed. Copy as-is.
Conditionally generate:
11. push-and-watch/SKILL.md — Only when a push deploys (a host watching the default branch, or a CI deploy job). Fill every <PLACEHOLDER>: the deploy trigger, how to watch the deploy (gh run watch, the host CLI), the live URL, and the rollback lever for code-only pushes (redeploy the previous build, or revert and push). Migrations always fix forward.
12. devils-advocate/SKILL.md — Only for projects with complex architecture or multiple contributors. Overkill for simple apps.
Do NOT generate by default (Claude already does these well without a skill):
/fix — Claude's default debugging is already "reproduce → locate → fix"/debug — Same as above, Claude naturally investigates systematically/refactor — Claude already runs tests before/after when asked to refactorThese can be added later via /update if the user wants the structured process.
Every generated skill must be project-specific. Reference the actual test framework and commands (pytest -x, vitest run, etc.), not generic npm test. Reference actual file patterns, conventions, and tools detected during analysis. This is the advantage over generic workflow plugins — every skill is tailored to THIS project.
Skill description = the discovery trigger (write it carefully):
description is the only part loaded at startup (progressive disclosure), so it's what Claude matches against to decide whether to invoke the skill. Make it earn that.Auto-triggered when …, Use when …, or Use before …. A description with no trigger won't fire reliably.Every generated skill body must carry three sections (this is what makes skills robust under pressure):
| Thought | Reality | table of the exact excuses Claude uses to skip the process ("it's just a small change", "tests pass so it's fine"), each paired with a rebuttal. Seed it with the detected stack's footguns.Keep SKILL.md focused; push detail into reference files (progressive disclosure):
reference.md, examples.md, scripts/) and link to them from SKILL.md. Claude reads those only when needed, so bundled-but-unread content costs nothing at startup.Path-scope project-specific skills. Workflow skills (plan, tdd, verify, review, clarify, subagent-dev) apply everywhere — no paths: needed. Any project-specific skill you generate (e.g., a Supabase RLS skill, a Prisma migrations skill, an API-conventions skill) MUST include a paths: frontmatter entry so it only loads when Claude is working in the relevant directory. Example:
---
name: api-conventions
description: "Response shapes, error handling, and auth middleware patterns for this project's REST API. Auto-loads when editing API routes."
paths: src/api/**, src/routes/**, app/api/**
allowed-tools: Read, Grep, Glob
---
Use dynamic shell context where it helps — !`git diff --stat` in review/verify preloads fresh state without a tool-call round-trip. Do NOT use !`cmd` for commands that write, delete, or take long to run.
context: fork skills must set background explicitly. Since Claude Code 2.1.218, skills with context: fork run in the background by default (opt out with background: false) — a Claude Code version bump silently changes any generated skill that omits the field. Decide the right value at generation time instead of inheriting the default: background: false for skills that gate a decision the user is waiting on (e.g. devils-advocate, used right before committing to a plan), background: true for skills whose output the user will check on later (long research/exploration). Always write the field, don't rely on the platform default.
Split the settings into a committed file and a personal file. This mirrors how real teams actually use Claude Code: everyone shares the safety net, each dev adds their own approve-without-prompting shortcuts.
.claude/settings.json — committed, team-wide safety and the quality gate. Start from templates/hooks/settings.json, which already wires everything below. Read reference/harness.md before this step: it explains each piece, the install order, and the payload-pipe proof.
The hook chain (templates/hooks/scripts/ into .claude/scripts/): pre-edit block for generated and append-only files, post-edit and post-bash (mtime) markers, session-start stamp, and the Stop gate that runs the project's single gate command once per turn and blocks until green. Customize only gate.conf: CHECK_CMD is the project's whole gate (npm run check, make check), never a hand-picked subset of checks.
Git hooks (templates/githooks/ into .githooks/): pre-push (refuse when behind the default branch, then the gate), post-merge and post-checkout (run MIGRATE_CMD when migrations changed), prepare-commit-msg (the Claude-Session: trailer). Run git config core.hooksPath .githooks before writing settings.json, since settings deny that command.
PreToolUse (Bash): Regex-block git push --force, npm publish, docker push, terraform destroy, kubectl delete namespace, rm -rf / / rm -rf ~. Use word-boundaries (\b) so rm -rf ./dist doesn't match.
PreToolUse (Write|Edit): Hard-block writes to .env*, *.pem, *.key, *.cert, *.p12, ~/.ssh/, ~/.aws/, ~/.gnupg/ based on the basename (not full path — so src/env.ts stays allowed, only .env / local.env / .env.production match).
permissions.ask (not deny) for .claude/settings.json and .claude/hooks/** (both project and ~/.claude/): prompts the user before Claude edits the safety layer, but doesn't hard-block. Hard-block would kill /update — ask gives the user control without the friction. This is slavaspitsyn's "hook self-protection" pattern softened for real-world UX.
PostToolUse (Write|Edit): Auto-format the file that was just written (prettier for JS/TS/JSON/MD/CSS, ruff/black for Python, gofmt for Go, rustfmt for Rust). Non-blocking — || true if the formatter isn't installed. This is Boris Cherny's #1 tip: tight feedback loops are the single biggest Claude Code quality lever.
PreCompact: Snapshot the branch name, git status --short, and last 10 commits into .claude/checkpoints/checkpoint-<ts>.md before compaction. Survives context loss.
permissions.deny: ~/.ssh/**, ~/.aws/**, ~/.gnupg/**, .env*, the dangerous-bash patterns in duplicate (belt + suspenders — permission rules catch what hook regex might miss), and git push --force-with-lease, --no-verify on commit and push, git commit -n, and git config core.hooksPath so the git hooks cannot be skipped. File rules are always Edit(path): Edit rules cover every file-writing tool, and Write(path) rules match nothing.
MCP deny patterns (only if .mcp.json or mcp_servers detected): add regex entries like mcp__.*__write.*, mcp__.*__delete.*, mcp__.*__create.* so MCP side effects need explicit approval. Remember MCP matchers use JS regex — mcp__memory alone matches nothing; you need mcp__memory__.*.
.claude/settings.local.json.example — committed, acts as onboarding, NOT loaded by Claude Code:
permissions.allow with project-relevant entries (Bash(npm test:*), Bash(pytest:*), Bash(git status:*), Bash(gh pr view:*)) so a new dev can cp settings.local.json.example settings.local.json and have sensible personal approvals on day one.// comment explaining: "copy to settings.local.json for PERSONAL overrides — gitignored, your teammates won't see it.".claude/settings.local.json is gitignored — each dev maintains their own. Do NOT generate it; just generate the .example so they know the shape.
Skip for solo dev projects:
rm -rf ./dist get false positives and will disable hooks entirely. Keep the credential-file Write|Edit block (universal value) and the hook self-protection block (always valuable).Hook decision schema (get this right — the old form is silently ignored):
PreToolUse command hook controls the call via hookSpecificOutput, NOT a top-level decision field. The legacy {"decision": "allow"|"block"} shape does NOT work for PreToolUse.{"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": "<why>"}}. Valid permissionDecision values: allow, deny, ask, defer.exit 0. Don't emit an "allow" object on the happy path — silence already lets the call proceed through the normal permission flow."if" field on a hook entry (e.g. "if": "Bash(git *)") to scope a hook to matching tool arguments instead of running it on every Bash call — cheaper and fewer false positives than regex-matching inside the script."type": "prompt" for single-turn LLM evaluation, "type": "agent" for multi-turn judgment, "type": "http"). For SAFETY gates, still generate deterministic command hooks only — an LLM-in-the-loop safety check can be argued out of its job. Prompt/agent hooks are fine for advisory checks (e.g. "does this commit message match the convention?") if the user asks for them.templates/hooks/tdd-guard.md (references nizos/tdd-guard) for teams that want a hard test-first gate, not just the instruction-level /tdd skill..claude/output-styles/)Output styles inject rules into Claude's system prompt, not just CLAUDE.md. That makes them stronger than rules for anything that must never be skipped — Claude sees them earlier and can't "forget" them under pressure.
Generate tdd.md automatically when tests exist (or were bootstrapped in Step 1.5). The template at templates/output-styles/tdd.md enforces the RED-GREEN-REFACTOR loop and the verification gate at the system-prompt level. Copy it as-is — do not inline-edit with project-specific commands (the TDD skill already handles commands). The user enables it by running /config → Output style → TDD, or by adding "outputStyle": "TDD" to .claude/settings.json.
Mention it in the final report so the user knows it exists and how to activate it.
Do NOT generate additional output styles speculatively. They're powerful — one is plenty unless the user asks.
If a monorepo is detected:
CLAUDE.md with shared conventionsARCHITECTURE.md with the system-level view (how packages/services connect, shared infrastructure, deployment topology)CLAUDE.md files with package-specific commands and architectureARCHITECTURE.md covering that package's internal architecturepaths: frontmatter@../../CLAUDE.mdGenerate a standing, project-wide "Definition of Done" at docs/definition-of-done.md — the fixed quality gate that complements per-task acceptance criteria (acceptance criteria answer "did we build the right thing?"; DoD answers "is it ready?").
Structure: short checklists under Correctness (tests pass, edge cases covered), Quality (lint clean, no debug artifacts, follows conventions), Integration (full suite passes, no broken imports), Documentation (CLAUDE.md/README updated if commands or architecture changed). Populate each from the ACTUAL detected stack — real commands, real linter, real conventions. Keep it under 40 lines.
Wire it in: the verify and finish skills must reference it as their final gate ("run through docs/definition-of-done.md before landing").
Ensure the following are gitignored:
.claude/settings.local.json (personal overrides).claude/agent-memory-local/ (per-session memory).claude/checkpoints/ (PreCompact hook drops checkpoint files here — regenerable, no value in git).claude/.cache/ (per-session gate markers and mtime stamps)Do NOT gitignore .claude/settings.local.json.example — that's the onboarding artifact, must be committed.
After generation:
reference/harness.md, "Proving it works") and show the exit codes. Reading a hook is not evidence it runs./config → Output style → TDD)settings.local.json.example was generated, tell them to cp .claude/settings.local.json.example .claude/settings.local.json to get personal allow-lists on day one/onboard to get oriented", "Run /doctor to validate the config", "Customize CLAUDE.md further").claude/ files without asking. Merge with existing config.paths: scoped rules over global rules — except for content that must hold unconditionally, which belongs in CLAUDE.md since paths: rules don't reliably reload after /compact.@imports in CLAUDE.md to keep it lean (e.g., @docs/architecture.md).What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub yash-gadodia/claude-init --plugin claude-init4 skills in this plugin
/doctorValidate your .claude/ configuration. Checks that commands work, paths exist, hooks are valid, and agents are well-formed. Use after /claude-init or /update to catch issues./onboardQuick onboarding to an existing codebase. Generates a mental model of the architecture, key patterns, and how things connect. Use when joining a new repo or when a teammate needs to get up to speed fast./updateRe-analyze a repo and update its existing .claude/ configuration. Detects stack changes, new dependencies, and config drift without overwriting customizations. Use when the codebase has evolved since initial /claude-init.