description: Scaffolds a context-aware .claude/ directory for any project. Detects language, framework, monorepo layout, and existing conventions, then generates CLAUDE.md, settings.json, path-scoped rules, a code-reviewer subagent, and stack-relevant skills. Asks before clobbering existing files. argument-hint: [--minimal | --skip-skills | --dry-run]
/claude-setup
Scaffold a working .claude/ directory for the current project. Read the codebase, detect context, write only what earns its keep on this stack.
The hard rule of this skill: don't generate cargo-cult. No empty folders. No generic placeholders. If a rule, skill, or agent doesn't have a real reason to exist for THIS project, skip it.
Phase 1: Detect
Run these in parallel and study the output:
!pwd && echo "---" && ls -la
!cat README.md 2>/dev/null | head -120
!cat package.json Cargo.toml pyproject.toml go.mod Gemfile pom.xml build.gradle build.gradle.kts deno.json bun.lockb 2>/dev/null | head -300
!ls .claude/ 2>/dev/null && echo "---existing claude config above---"
!cat .gitignore 2>/dev/null | head -60
!ls docs/ docs/rfcs/ docs/adr/ docs/architecture/ 2>/dev/null
From that output, decide:
- Stack: Rust (Cargo.toml), Node/TS (package.json), Python (pyproject.toml/requirements.txt), Go (go.mod), Ruby (Gemfile), Java/Kotlin (pom.xml/build.gradle), Deno (deno.json), Bun, or mixed. If multiple, pick the dominant one and note the secondary.
- Layout: monorepo (
workspaces/turbo/nx/lerna/cargo[workspace]/Go workspace) vs. single project. - Existing
.claude/: if present, this is a merge — never overwrite without per-file confirmation. - Hard rules scraped from README/RFCs/ADRs: words like "locked", "banned", "no ", "must ", "RFC", "ADR-NNN", "invariant" are signals. Encode the real ones — invent none.
- Test framework, linter, formatter, package manager — extract from configs and scripts so commands in
CLAUDE.mdare real.
If detection is genuinely ambiguous (multiple lockfiles, no clear primary language, no README), STOP and ask the user one focused question to resolve. Don't ask for things you can detect.
Phase 2: Read the matching template
Templates bundled with this skill describe what to generate per stack. Read whichever applies (use ${CLAUDE_SKILL_DIR}/templates/<name>.md):
rust-workspace.md— Cargo[workspace]rust-single.md— single Cargo.tomlnode-monorepo.md— npm/yarn/pnpm workspaces, turbo, nx, lernanode-single.md— single package.json (Next.js, Vite, Express, etc.)python.md— Poetry, pip+venv, uv, hatchgo.md—go.modprojectsgeneric.md— fallback for anything else
Each template lists what CLAUDE.md should include, which permissions matter, which path-scoped rules earn their keep, how to tune the code-reviewer subagent, and which skills are typically useful for that stack.
The templates are references, not boilerplate to paste. Use them to decide what to generate; phrase the output in terms of THIS project.
Phase 3: Plan and confirm
Print a plan to the user before writing anything:
Detected: <stack> (<layout>)
Project name: <name>
Primary commands: build=<cmd>, test=<cmd>, lint=<cmd>
Will create:
CLAUDE.md (NEW | MERGE | SKIP)
.worktreeinclude (NEW | SKIP)
.claude/settings.json (NEW)
.claude/rules/<n>.md (NEW, path: <glob>)
.claude/agents/<lang>-reviewer.md (NEW)
.claude/skills/<n>/SKILL.md (NEW)
Will skip (no clear use case): output-styles/, commands/, agent-memory/
Existing files: <list with action: keep/replace/merge>
Hard rules detected from README/RFCs:
- <quote 1> → encoded in rules/<file>.md
- <quote 2> → encoded in CLAUDE.md
Proceed? [y/N/preview/edit-plan]
If --dry-run: stop here.
If a file already exists, default action is keep. Ask before replace.
If --minimal: plan only CLAUDE.md + .claude/settings.json.
If --skip-skills: omit skills/ from the plan.
Phase 4: Generate
Write files according to the plan. Per-file rules:
CLAUDE.md
- Top: stack one-liner.
## Commandsblock: real commands extracted from package.json scripts / Makefile / Cargo aliases / pyproject scripts. Don't list commands that don't exist.## Repo mapblock: only the directories that matter. Skipnode_modules,target,dist,.next,__pycache__.## Hard rules: only what came from README/RFCs/ADRs. If nothing's there, omit the section — don't pad.## Behavioral principles: keep the user's existing principles ifCLAUDE.mdalready has them; otherwise omit (their global~/.claude/CLAUDE.mdlikely covers it).
.claude/settings.json
permissions.allow: stack-tuned. For Rust:cargo *,git diff *,gh *. For Node:npm test *,npm run *,pnpm *. Don't allow blanketBash(*).permissions.deny: minimumrm -rf *,git push --force *,git reset --hard *. Add stack-specific destructive ones (e.g.npm publish *for libraries).- No hooks unless the project has a clear pre/post-tool need.
.claude/rules/<name>.md
Path-scoped rules ONLY for directories with real conventions. Heuristic:
- Monorepos: one rule per workspace member that has distinct rules.
- Test conventions: one rule scoped to
**/*test*patterns IF the project has non-obvious test conventions. - Infra/IaC: one rule scoped to
infra/**IF the project has IaC. - API design: one rule scoped to API routes IF there's a clear shape contract.
Don't generate a rule just because the docs example had one. If the conventions are obvious from CLAUDE.md, no rule needed.
.claude/agents/<lang>-reviewer.md
- Tools:
Read, Grep, Globonly (read-only). - Body: language-tuned checklist (see template).
- Description must be specific enough that Claude auto-invokes for review tasks: "Reviews changes for ..." — list the specific checks.
.claude/skills/<n>/SKILL.md
Generate ONLY skills that have a clear, repeatable workflow:
/release— if the project has a version file (Cargo.toml, package.json, pyproject.toml) AND a CHANGELOG.md./test— if there's a non-trivial test command (e.g. matrix, multiple suites). Singlecargo testdoesn't need a skill./lint— same logic.- Stack-specific (e.g.
/db-migratefor Django/Rails,/deploy-previewfor Next.js).
Don't generate placeholder skills with TODO bodies. Working or skipped, no in-between.
.worktreeinclude
- List gitignored files that worktrees need:
.env,.env.local. - If
CLAUDE.mdor.mcp.jsonare gitignored (check.gitignore), include them so worktrees aren't blind. - If
.claude/settings.local.jsonis gitignored, include it.
Phase 5: Verify and report
After writing:
echo "=== generated tree ==="
find .claude -type f | sort
echo "=== line counts ==="
find .claude -type f -exec wc -l {} \;
Print:
- Final tree.
- Line counts (target: each file ≤ 100 lines; flag if any exceed 150).
- One concrete verification step (e.g. "open a session, run
/permissions, confirmcargo *shows as committed"). - Reminder: add
.claude/settings.local.jsonto.gitignoreif not already.
Anti-goals (re-stated for clarity)
- No empty folders. No
output-styles/unless there's a real style. Nocommands/(skills supersede per Anthropic docs). - No copy-paste from the docs example.
testing.mdandapi-design.mdfrom the canonical tree are examples — only generate something analogous if THIS project actually has those conventions. - No clobbering. Always per-file confirm before replacing.
- No hard rules from thin air. Pull from README/RFCs/ADRs. If they don't exist, the project doesn't have hard rules — say so, move on.
- No skills with TODOs. Working or skipped.
- No global wildcards in permissions.
Bash(cargo *)notBash(*).
Flags reference
--minimal:CLAUDE.md+.claude/settings.jsononly.--skip-skills: omit skills/.--dry-run: print plan, write nothing.
(All flags optional. Default is full canonical layout, stack-aware, with confirmation.)