---
description: "Select the active stack(s) for this repo by enabling the matching marketplace plugin(s) in .claude/settings.json. Multi-select: pass several stacks (ios backend) or pick them in the native picker. Use when a repo's stack changed or the wrong plugins are enabled for it."
description-tr: "Bu repo için aktif stack'leri seçer: eşleşen marketplace plugin'lerini .claude/settings.json'da etkinleştirir. Çoklu seçim: birden fazla stack yazılabilir (ios backend) ya da native picker'dan seçilir."
argument-hint: "[ios|android|web|frontend|backend|mobile|fullstack|all ...]"
parameters: [{"name":"stacks","kind":"enum","repeat":true,"enum":["ios","android","web","frontend","backend","mobile","fullstack","all"]}]
gui: form
destructive: false
confirm: none
allowed-tools: Bash, Read, Edit, Write, AskUserQuestion
---

# multi-agent stack  -  Select Stack(s) via Plugin Enablement

> **Pickers follow** `$HOME/.claude/multi-agent-refs/picker-contract.md`: never a one-option call, and branch on the option selected, not on its text.

Stack skills ship as plugins in the `{owner}/multi-agent-plugins` marketplace. Selecting a stack = **enabling the matching plugin(s)** in the current repo's `.claude/settings.json` `enabledPlugins`. Two toolkits are stack-independent and always enabled alongside the stack plugin(s): `ai-common-toolkit` (accessibility audit, humanizer, Firebase) and `ai-analyst-toolkit` (GitHub and package-registry evidence, community signal for analysis work).

Claude Code reads stack skills only from the enabled plugins; Copilot CLI and Codex CLI get a local copy filtered at install time (step 5). Host details, usage examples, a preview snippet and why the map is derived: `$HOME/.claude/multi-agent-refs/stack/background.md`. Read it when the user asks what an argument enables or how selection works.

## Stack -> plugin map

Derived, not listed: `pluginsForStacks()` in `scripts/_stack-routing.mjs` owns it (aliases `frontend`, `mobile`, `fullstack`, `all` expand there too). Never write the map out by hand. `ai-common-toolkit` and `ai-analyst-toolkit` are in every answer.

## Behaviour

1. **No arg → native multi-select picker.** Read `.claude/settings.json` (repo) + `~/.claude/settings.json` (global) to learn the current state, then ask with `AskUserQuestion` (`multiSelect: true`) - NEVER a numbered text menu:
   - `question` (in `outputLanguage`): which stacks should be active in this repo, noting the currently enabled ones
   - `header`: "Stacks" (English, UI contract)
   - `options` (4): `ios` / `android` / `web` / `backend`, each `description` (in `outputLanguage`) naming the plugin it enables and marking the ones already enabled with "(currently on)" / "(şu an açık)"
   - Map each selected label back to its canonical arg before step 2: the token before any parenthesis.
   - Empty selection or cancel → **status mode**: print the currently enabled `@multi-agent-plugins` plugins and exit without modifying anything. Status mode never runs the Implementation block below - that block is enable-mode only.
2. **Arg(s) present → enable mode.** Accept multiple space-separated stacks. Resolve each through the alias table (`frontend`→`web`, `mobile`→`ios android`, `fullstack`→`web backend`, `all`→every stack), union the plugin sets, then write the **current repo's** `.claude/settings.json`.
3. **Write rules:**
   - every plugin in the union is set to `true`
   - every stack toolkit **not** in the union is set to `false` (leave non-`@multi-agent-plugins` entries untouched)
   - `ai-common-toolkit@multi-agent-plugins` and `ai-analyst-toolkit@multi-agent-plugins` are always `true`
   - **legacy-key cleanup**: delete any `ai-*-engineering-toolkit@multi-agent-plugins` keys - those plugin names were retired by the `ai-<stack>-toolkit` rename and a stale `true` there enables a plugin that no longer exists in the marketplace
   - **Apple's Xcode skills**: when `~/.claude/xcode-apple-marketplace` exists, set `xcode-integration@xcode-apple` to `true` if `ios` is in the selection and `false` otherwise. Without that directory leave the key absent
4. **Unknown arg** → show the known stacks; do not guess.
5. **Engine-host refresh offer.** Every host that keeps its own skill copies filters them to the enabled stacks at install time, so after a change ask (single `AskUserQuestion`, not silent): "Refresh the other hosts' local copies now?" - Yes runs `node <pipelineRepo>/install.js` with one flag per host tree that already exists (`--copilot` for `~/.copilot`, `--codex` for `~/.codex`, `--local` for `~/.codex-local`), No leaves them stale with a one-line warning naming the command to run later. A flag for a tree that is not there would install a host the user never asked for, so the flags follow the trees rather than the registry. Skip this question entirely when none of those trees exists.

## Implementation

```bash
REPO_SETTINGS=".claude/settings.json"
MP="multi-agent-plugins"

# --- ensure the marketplace is known (idempotent) -------------------------
bash "$HOME/.claude/scripts/plugin-refresh.sh" {owner} --add-only \
  || echo "note: add the marketplace once with: claude plugin marketplace add {owner}/$MP"

# Enable-mode only: with zero args the write rules below would set every stack
# toolkit to false (nothing but the always-on pair is in $ON), silently wiping the repo's
# selection. No args belongs to the picker / status path (Behaviour step 1).
if [ "$#" -eq 0 ]; then
  echo "No stack given - nothing changed. Pass stacks (ios backend ...) or use the picker."
  exit 0
fi

# resolve every arg and derive the ON set; the suffix is appended inside node
ON=$(MP="$MP" node -e 'import(process.env.HOME+"/.claude/scripts/_stack-routing.mjs").then(m=>{
  const st=process.argv.slice(1).flatMap(a=>m.expandStackArg(a));
  if(!st.length){console.error("Unknown stack. One of: "+m.KNOWN_STACKS.join(" ")+" mobile fullstack all");process.exit(1);}
  const r=m.pluginsForStacks(st);
  if(r.dropped.length) console.error("not in the marketplace, dropped: "+r.dropped.join(" "));
  console.log(r.plugins.map(p=>p+"@"+process.env.MP).join(" "));
})' "$@") || exit 1
```

Then write it with the one writer of these rules:

```bash
node "$HOME/.claude/scripts/stack-toggle.mjs" set --repo "$PWD" "$@" --json
```

`stack-toggle.mjs` applies the write rules above atomically and refuses an
empty selection and an unknown stack (exit 1). Never hand-edit the JSON.
`stack-toggle.mjs status --repo "$PWD" --json` is the read for status mode.
Then print the resulting `enabledPlugins` block and run step 5 (Copilot/Codex refresh offer).

Last, show what else this repo could use. The script is read-only and skips anything already set up:

```bash
node "$HOME/.claude/scripts/repo-recommend.mjs" --repo "$PWD"
```

It prints at most two hooks, MCP servers, LSP plugins and subagents, each with the file that triggered it. Offer to apply one only when the user picks it; under autopilot, report and apply nothing.

## Notes

- Enablement is per-repo and declarative - commit `.claude/settings.json` so teammates get the same stack.
- Restart the conversation (or reload the window) for Claude Code to pick up newly enabled plugins.
- Pipeline Phase 1 stack detection is independent (it reads project files); `stack` only sets which plugin skill set is active.
