Project Setup
Trigger
- Keywords: project setup, init, initialize, configure project, setup CLAUDE.md, customize placeholders
When NOT to Use
- CLAUDE.md placeholders are already fully replaced (no
{...}remaining) - Non Node.js/TypeScript project without a recognized manifest file -- run with
--detect-onlyto see what can be auto-detected. Manual configuration may be needed for: {FRAMEWORK}, {CONFIG_FILE}, {BOOTSTRAP_FILE}. Script commands ({TEST_COMMAND}, etc.) can often be detected from manifest files - Only want to modify a single placeholder -- just Edit CLAUDE.md directly
Workflow
Phase 1: Detect project environment
│
├─ Read package.json (dependencies, devDependencies, scripts)
├─ Detect lockfile (pnpm-lock.yaml / yarn.lock / package-lock.json)
├─ Detect entrypoints (glob src/)
└─ Compile results
│
Phase 2: Confirm detection results
│
├─ Present detection results table
└─ Wait for user confirmation or corrections
│
Phase 3: Write to .claude/CLAUDE.md (unless --detect-only)
│
├─ Read CLAUDE.template.md, filter ecosystem blocks
└─ Replace placeholders, write to .claude/CLAUDE.md
│
Phase 4: Verify CLAUDE.md
│
├─ Read .claude/CLAUDE.md to confirm no remaining placeholders
└─ Output placeholder summary
│
Phase 5: Install Rules + Backfill CLAUDE.md (unless --no-rules or --lite)
│
├─ Locate plugin rules dir (3-level fallback)
├─ mkdir -p .claude/rules/ → copy 11 managed rules + 1 override template
├─ Backfill: ensure .claude/CLAUDE.md has @rules/ references
└─ Output rules install report
│
Phase 6: Install Hooks (unless --no-hooks or --lite)
│
├─ Locate plugin hooks dir (3-level fallback)
├─ mkdir -p .claude/hooks/ → copy 5 hooks + chmod +x
├─ Merge hook definitions into .claude/settings.json
└─ Output hooks install report
│
Phase 6.5: Install Scripts (unless --lite or --detect-only)
│
├─ Locate plugin scripts dir (3-level fallback)
├─ mkdir -p .claude/scripts/lib → copy 3 scripts
├─ Update manifest .sd0x/install-state.json
└─ Output scripts install report
│
Phase 6.7: Configure Environment Variables (unless --detect-only or --lite)
│
├─ Detect model context size (1M → recommend auto-compact window)
├─ Build env var catalog (STOP_GUARD_MODE + model-aware vars)
├─ Present recommendations, wait for user confirmation
├─ Merge into .claude/settings.json env object
└─ Output env config report
│
Phase 7: Final Verification Report
│
├─ Summarize all phases
├─ Closed-loop check (CLAUDE.md + rules + hooks + env)
└─ Output next steps
Flag Short-Circuit Semantics
| Flag | Phase 1-2 | Phase 3-4 | Phase 5-6.5 | Phase 6.7 | Phase 7 | |------|-----------|-----------|-----------|-----------|---------| | (none) | Execute | Execute | Execute | Execute | Full report | | --detect-only | Execute | Skip | Skip | Skip | Detection results only | | --lite | Execute | Execute | Skip | Skip | CLAUDE.md only | | --no-rules | Execute | Execute | Skip rules | Execute | Report | | --no-hooks | Execute | Execute | Skip hooks | Execute | Report | | --env-only | Skip | Skip | Skip | Execute | Env report only (skill-level directive) | | --guard-mode warn | Execute | Execute | Execute | Execute (STOP_GUARD_MODE=warn) | Report |
Phase 1: Detect Project Environment
Execute the following detections in order; see references/detection-rules.md for detailed rules:
Detection Steps
- Detect Ecosystem — Glob for manifest files (
package.json,pyproject.toml,Cargo.toml,go.mod,build.gradle,pom.xml,Gemfile). Priority order inreferences/detection-rules.md. - Read manifest — Extract project name, dependencies, scripts (Node.js:
package.json; others: ecosystem manifest) - Detect Package Manager — Lockfile detection (Node.js only):
pnpm-lock.yaml→ pnpm,yarn.lock→ yarn, else npm (priority order perreferences/detection-rules.md) - Detect Framework — From dependencies. See
references/detection-rules.md#framework - Detect Database — From dependencies. See
references/detection-rules.md#database - Detect Entrypoints — Glob framework-specific candidates. See
references/detection-rules.md#entrypoints - Detect Scripts — From manifest scripts field. See
references/detection-rules.md#scripts. Missing scripts →# N/A (no script found)
For non-Node.js ecosystems, skip Node-specific steps and use ecosystem-specific detection from references/detection-rules.md.
Phase 2: Confirm Detection Results
Present a table of all 9 auto-detected placeholders with | Placeholder | Detected Value | Source | columns. Additional manual placeholders ({TICKET_PATTERN}, {ISSUE_TRACKER_URL}, {TARGET_BRANCH}) may remain if not auto-detectable — these are acceptable and should be noted as "manual" in Phase 4 verification. Wait for user confirmation before proceeding to Phase 3.
Phase 2.5: Select Ecosystem Blocks
Based on detected manifest (from Phase 1.0):
| Manifest | Ecosystem tag | |----------|--------------| | package.json | node-ts | | pyproject.toml | python | | go.mod | go | | Cargo.toml | rust | | Gemfile | ruby | | pom.xml / build.gradle | java |
Phase 3: Write to .claude/CLAUDE.md
Prerequisite: User has confirmed, and not in --detect-only mode.
- Read
CLAUDE.template.md(if not found, fallback toCLAUDE.md) - Remove
<!-- block:X -->...<!-- /block -->sections NOT matching detected ecosystem - Remove remaining block markers (
<!-- block:... -->,<!-- /block -->) - Execute
Editfor each placeholder (usingreplace_all: true) - Write to
.claude/CLAUDE.md(create directory if needed)
If .claude/CLAUDE.md does not exist, create it from the rendered template.
Phase 4: Verify CLAUDE.md
- Read
.claude/CLAUDE.md Grep: \{[A-Z_]+\}— confirm no remaining auto-detected placeholders. Exclude${...}shell variable matches (e.g.,${CLAUDE_PLUGIN_ROOT}) from the count — these are intentional env var references, not unfilled placeholders.- Output summary table with all placeholder values and remaining count
If --detect-only or --lite, skip to Phase 7.
Phase 5: Install Rules + Backfill CLAUDE.md
Skip if: --no-rules or --lite or --detect-only.
5.1 Locate Plugin Rules Directory
Find the plugin's rules/ directory using this priority (short-circuit on first match):
- Glob search — search known Claude plugin locations:
`` Glob: ~/.claude/plugins/**/sd0x-dev-flow/rules/auto-loop.md Glob: ${REPO_ROOT}/node_modules/sd0x-dev-flow/rules/auto-loop.md ``
- Plugin-relative fallback — try reading
@rules/auto-loop.mdto confirm accessibility. If readable, derive the rules directory. - Not found → hard error for this phase (do not silently skip). Output explicit failure with remediation steps:
``` ⛔ Rule source not found. Auto-loop rules cannot be installed.
Remediation (choose one):
- Install the plugin: /plugin marketplace add sd0xdev/sd0x-dev-flow && /plugin install sd0x-dev-flow@sd0xdev-marketplace
- Copy rules manually from a machine that has the plugin installed
- Re-run with --no-rules to skip (rules layer will be missing)
```
Then skip Phase 5 and continue to Phase 6. Phase 7 will report this as ⚠️ Partial.
5.2 Copy Rules
mkdir -p ${REPO_ROOT}/.claude/rules/- Copy all 11 managed rules:
| Rule | Purpose | |------|---------| | auto-loop.md | Auto review loop enforcement | | codex-invocation.md | Codex independent research requirement | | fix-all-issues.md | Zero tolerance for unfixed issues | | framework.md | Framework conventions | | testing.md | Test structure and requirements | | security.md | OWASP security checklist | | git-workflow.md | Git branch and commit conventions | | `l