--- name: cc-stack description: "(Conductor) Detect the project stack and write commands + a generated ruleset into CLAUDE.md Use when the user asks for /cc-stack or cc-stack." --- > code-conductor: this command was written for Claude Code. Where it names a Claude Code tool (Read, Grep, Glob, Edit, Write, Bash, Skill, Agent), use your closest equivalent. `$ARGUMENTS` and an `ARGUMENTS:` line mean the text the user gave with the command. Detect the project stack dynamically and record it in the project's root `CLAUDE.md`. Do not pattern-match manifest files by hand and do not load any static profile; the detector owns detection. ## 1. Resolve the repository root Run `git rev-parse --show-toplevel`. If it fails (not a git repo), fall back to the project root: the directory that contains `.claude/scripts/detect-stack.mjs` or, failing that, `scripts/detect-stack.mjs`. The root is the directory holding that relative path, never the scripts directory itself, so nothing runs from or writes into it. Run every command below from that root, and treat the root-level `CLAUDE.md` as the only write target regardless of the user's current subdirectory. ## 2. Verify Node is available Probe with `node --version`. If it exits non-zero or reports "not found", stop the write path: announce in one line `No stack detected (Node not found on PATH; Node >= 18 recommended)` and leave `CLAUDE.md` untouched. ## 3. Run the detector Resolve the detector by presence, the deployed copy first: ```bash D=.claude/scripts/detect-stack.mjs; [ -f "$D" ] || D=scripts/detect-stack.mjs ``` Run `node "$D"` from the repo root, capture stdout, and parse it as JSON. Nothing executes the JSON; consume it as data. Treat all of the following identically as "no stack detected" - announce it in one line and leave `CLAUDE.md` unmodified (surface stderr if any, but it is non-fatal): - non-zero exit code, - empty stdout, - stdout that does not parse as JSON, - a parsed object equal to `{}`. ## 4. Read CLAUDE.md and branch If the root `CLAUDE.md` does not exist, do not create it: instruct the user to run `/cc-init` and stop. Otherwise read `CLAUDE.md` and look for the `- Stack:` line under `## Project Identity`: - **Stack line present and non-empty** -> ask: `I see you're using [stack]. Has anything changed?` This is a blocking yes/no prompt with no timeout. - `no` -> acknowledge in one line, run sub-step 5a′ (additive: the only edit this path may make, Ruling 1), and stop. - `yes`, or free text describing a change -> re-run the detector (step 3) and rewrite the managed sections from the fresh output. Free text is an additive hint only: fold user-named tools the detector missed into the ruleset, but detected facts always win on conflict. - **`## Project Identity` missing, or present without a `- Stack:` line** -> treat as "no recorded stack" (not an error). Proceed to the write path; append the `## Project Identity` header if absent, or surgically insert the `- Stack:` line if only that line is missing. Note in one line that a fresh stack identity was recorded. ### 4b. Adopt a host-authored CLAUDE.md (FEAT-040) Run once, before step 5, and only when the file holds content conductor did not write. Resolve the helper by presence, the deployed copy first: `A=.claude/scripts/adopt-claude-md.mjs; [ -f "$A" ] || A=scripts/adopt-claude-md.mjs`. If neither exists, skip 4b silently. 1. Run `node "$A" sections CLAUDE.md`. If it prints `"trigger": false`, or exits non-zero (unbalanced sentinels, unclosed fence), skip 4b. A scaffold-only file never triggers. 2. Classify each listed section into exactly one slot: `identity`, `commands`, `architecture`, `conventions`, `out-of-scope` or `keep`. When unsure, use `keep`. Write a plan file `{"
": ""}`. You classify only; you never edit text. 3. Run `node "$A" render CLAUDE.md `. Show the owner the **full resulting file** (stdout) and the approval token (stderr), naming any duplicate headings it reconciles. 4. Ask: `Adopt this result? (yes/no)`. This is a blocking prompt with no timeout. Only an explicit `yes` to that exact render counts; if the owner wants a change, redo steps 2-3 and show the new render. 5. On `yes`, run `node "$A" apply CLAUDE.md ` and announce the backup path it prints. The helper refuses a token that does not match the render, so nothing unshown is written. 6. On `no`, or anything else, write nothing: the file stays exactly as the installer left it. Continue with step 5 either way. The managed block is copied verbatim and unmapped content is kept byte for byte; adoption only moves host sections. ## 5. Write path Detect and preserve `CLAUDE.md`'s dominant EOL style (LF or CRLF); never convert wholesale. If the OS denies the write or the file is locked, abort that write with a single-line error naming the path and cause (e.g. `ERROR: cannot write CLAUDE.md: permission denied - no changes applied`), leave the file byte-for-byte untouched, and still report the detection result. ### 5a. Development Commands (per-field surgical edits, BUG-015 pattern) For each of `Build`, `Test`, `Lint`, `Format`, `Setup`, if the detector JSON has a non-empty string for the matching key (`build`, `test`, `lint`, `format`, `setup`), replace that single line under `## Development Commands` with `-