System prompt for Claude Code. Do not remove or override. ASK (Agentic SDLC Kit) — the perfect fusion of SDD (spec-driven discipline) and TDD (test-driven discipline) for teams building software with AI agents.
Self-contained at the workflow layer. No plugin marketplace to install from, no remote skill source to sync — every legion agent, skill, hook, and script ships in this repo (
.claude/,scripts/,hooks/). Updates are git pulls, not network calls. Host prerequisites (must already be on the developer machine beforebash scripts/setup.sh):bash,git,node ≥ 18,npm,jq. The only runtime dependency the workflow itself adds is GitNexus (code-graph MCP), installed vianpm install -g gitnexusduring setup. "Self-contained" therefore means "no plugin marketplace, no skill sync, no SaaS issue tracker", not "zero external binaries on the host".
Brand: ask-legion
Roles: 3 legion agents (legion-spec-owner, legion-principal, legion-engineer)
Skills: 10 legion discipline skills (legion:brainstorming … legion:verification-before-completion)
Safety: legion-scan hooks (secrets-scan, protected-files, legion-guard) + GitNexus impact gates
Slash commands: /legion:spec, /legion:design, /legion:implement, /legion:ship, /legion:status, /legion:roles
┌────────────────── ask-legion ────────────────────┐
│ │
│ SDD (legion agents) TDD (legion │
│ 3 roles, file-based skills + commit │
│ state machine, phase ordering, machine- │
│ gates enforced) │
│ │
│ ──────────── one product ──────────── │
│ │
├──── safety net (always-on, hook-level) ──────────┤
│ legion-scan + legion-guard + GitNexus │
└──────────────────────────────────────────────────┘
- SDD layer (legion agents) decides WHAT to build and WHO owns each step. The 3 agents —
legion-spec-owner,legion-principal,legion-engineer— are self-contained personas in.claude/agents/legion-*.md. The story state machine (scripts/story.sh) is the connective tissue. - TDD layer (legion skills) decides HOW work is done. Each agent invokes specific skills from
.claude/skills/legion/. Discipline is enforced by code: TDD task ordering at story promotion, TDD commit ordering at pre-merge, verification-before-completion at the gate. - Safety net runs at the hook level and cannot be skipped.
secrets-scanblocks hardcoded tokens;protected-filesblocks edits to.env/.pem/credentials.json;legion-guardblocks Agent dispatch to a missing role file; GitNexus enforces impact-aware editing.
The pipeline collapses into 5 logical steps, owned by 3 roles:
Phases internal to SO: brief → PRD → UX (if UI). Single role drives the entire WHAT/WHY chain.
docs/brief.md(skill: legion:brainstorming)docs/prd.md(skill: legion:brainstorming)docs/front-end-spec.md(if UI — skill: legion:brainstorming)
Principal owns architecture decisions and the binding tech stack.
docs/architecture.md(skills: legion:brainstorming, legion:writing-plans; GitNexus: query, context)
After architecture lands, SO runs validation (8 checks), shards oversized docs, produces epics, and authors stories with embedded GitNexus context.
docs/epics/{epic}.mddocs/stories/{epic}.{story}.md(skills: legion:using-git-worktrees, legion:dispatching-parallel-agents)- GitNexus: context (embedded into story body)
- TDD ordering layer 1: every task tagged
[T]/[I]/[V]; every[I]preceded by a[T](gated byscripts/check-tdd-ordering.shonReady)
Engineer picks up status: Ready stories.
- Skills: legion:test-driven-development, legion:systematic-debugging, legion:verification-before-completion, legion:executing-plans (if complex)
- GitNexus: impact (mandatory pre-edit), rename (for refactors), detect_changes (self-check)
- legion-scan hooks: always on
- TDD ordering layer 2: first
feat:/fix:commit must follow at least onetest:commit on the branch (gated byscripts/check-commit-tdd.shinmake pre-merge-check)
Principal runs Gates 0–4 on stories in Review.
- Skills: legion:verification-before-completion
- GitNexus: detect_changes (mandatory pre-ship)
- Gate 0:
make tdd-check(re-runs both TDD ordering layers) - legion-scan:
make scan
Engineer uses legion:receiving-code-review when Principal returns the story with findings.
| Role | Agent file | Required Legion skills | GitNexus tools |
|---|---|---|---|
| Spec Owner | legion-spec-owner.md |
brainstorming, using-git-worktrees, dispatching-parallel-agents | context (embedded into stories) |
| Principal IE | legion-principal.md |
brainstorming, writing-plans, verification-before-completion | query, context, detect_changes |
| Engineer | legion-engineer.md |
test-driven-development, systematic-debugging, verification-before-completion (+ executing-plans, receiving-code-review when applicable) | impact, rename, detect_changes |
Enforced by scripts/lint-agents.sh — every required skill MUST appear literally in the agent file.
- Every code change goes through a Story. Hotfix = micro-story. No direct edits.
- Engineer MUST run
gitnexus_impactbefore editing any symbol. HIGH/CRITICAL → escalate to legion-principal. - TDD ordering is enforced at two layers (machine-checked, no honor system):
- Layer 1 — Story spec: every task in
## Taskscarries a marker[T](test) /[I](impl) /[V](verify-only). Every[I]MUST have at least one[T]earlier in the list.scripts/check-tdd-ordering.shruns inscripts/story.shonReadyandReviewtransitions — violations block the transition. - Layer 2 — Branch commits: the first
feat:orfix:commit on a branch MUST be preceded by at least onetest:commit. Pure-refactor branches (onlyrefactor:) are intentionally exempt — refactors must not change observable behavior, so the existing test suite is what proves the refactor is safe. Forcing a brand-newtest:per refactor would either produce duplicate-of-existing tests (noise) or invite gaming the gate. The implicit safeguard: pre-existing tests must still pass after the refactor (make pre-merge-checkruns them at Gate 0). If a refactor changes a contract or adds a code path, it is misclassified — relabel asfeat:/fix:and add the missingtest:commit.scripts/check-commit-tdd.shruns inmake pre-merge-check— violations block the gate. - Engineer MUST also confirm each test fails for the right reason BEFORE writing the code that makes it pass.
- Layer 1 — Story spec: every task in
- Engineer MUST paste actual command output when claiming a task done. No "should work" claims.
- Principal MUST run
gitnexus_detect_changesbefore marking Done. Scope creep → return story to Engineer. - 1 Story = 1 branch = 1 worktree = 1 PR. Never bundle stories.
- legion-scan hook blocks cannot be bypassed with
--no-verify. Fix the root cause. - Engineer NEVER marks a story Done. Only Principal can. The split between Engineer (does work + self-verifies) and Principal (gates work) is what preserves the "second pair of eyes" guarantee — every story crosses an agent boundary before merge.
Fast-path skips Steps 1+2+3-validate. Spec Owner story authoring + Engineer + Principal gating are NEVER skipped. Use only if ALL of these are true:
- ≤ 2 files changed (check with
git diff --statagainst main on a dry branch) - No schema change (no
CREATE TABLE,ALTER TABLE, migration files) - No new user-visible behavior (no UX decisions, no new endpoints, no new permissions)
- No dependency added (no new entries in
package.json/go.mod/pyproject.toml/Cargo.toml)
If any is false → run the full 5 steps.
| Scenario | Roles to run |
|---|---|
| Hotfix / typo / doc fix | SO micro-story → Engineer → Principal |
| Bug fix (test added) | SO story → Engineer (TDD) → Principal |
| Feature ≤ 1 day AND all fast-path criteria pass | SO mini-PRD + story + Engineer + Principal |
| Feature > 1 day, or fast-path criterion fails | Full 5 steps |
| Greenfield / new module / new service | Full 5 steps |
When in doubt: run the full flow. Skipping is the expensive mistake.
| Do Not | Instead |
|---|---|
| Write code before a Story exists | Spec Owner creates Story first |
| Skip Principal for brownfield | Principal surveys with GitNexus before design |
| Trust Engineer's "should work" | Principal demands pasted evidence |
| Find-and-replace a rename | gitnexus_rename with dry_run=true |
| Merge with scope creep | Principal returns story; Engineer fixes |
| Bundle multiple stories in one PR | One story per PR, always |
Author story tasks without [T]/[I]/[V] markers |
SO writes markers; check-tdd-ordering.sh blocks Ready if missing |
feat: commit before any test: on the branch |
Stage TDD: test: commit first, then feat:; check-commit-tdd.sh blocks merge |
| Bug fix without a reproducing failing-test commit | Add a test: commit that reproduces the bug, then fix: — every fix: requires a test: predecessor |
| Engineer self-promoting story to Done | Only Principal can mark Done — scripts/story.sh done is a Principal-only command in practice |
- 1 commit per task in the story (one
[T]task → onetest:commit; one[I]task → onefeat:/fix:/refactor:commit). - Message format:
<type>: <description>(feat, fix, refactor, test, docs, chore). Conventional-commits scope(scope)and breaking-change!are allowed. - TDD ordering (see Hard Rule #3): on a story branch, the first
feat:/fix:MUST be preceded by at least onetest:commit. - Tests must pass after every commit. Failing 3× on one task → stop, re-check story, escalate to legion-spec-owner.
- legion-scan PreToolUse hooks (
secrets-scan.sh,protected-files.sh) block secrets and protected files automatically — vendored, no external runtime dependency. - Run
make scanfor whole-repo audit (vendored — nonpxcall). - session-end hook scans staged files for secrets + debug artifacts on Stop.
- Never hardcode credentials. If a hook blocks unexpectedly, fix the underlying issue rather than bypassing.
git init # if not already a repo
bash scripts/setup.shInstalls:
- legion agents →
.claude/agents/legion-*.md(vendored — 3 files) - legion skills →
.claude/skills/legion/*/SKILL.md(vendored — 10 files) - legion-scan hooks → merged into
~/.claude/settings.json(vendored) - GitNexus →
npm install -g gitnexus(only external dependency)
After setup, restart Claude Code. No plugins to install. No marketplace dependencies.
The block below is auto-managed by
npx gitnexus analyzebetween thegitnexus:start/gitnexus:endmarkers. Do not edit by hand — your changes will be overwritten on the next index. To customize the legion-specific short-form rules, edit.claude/skills/legion-core/gitnexus-reference.mdinstead (loaded on demand by agents).
This project is indexed by GitNexus as ask-legion (45 symbols, 34 relationships, 0 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.
If any GitNexus tool warns the index is stale, run
npx gitnexus analyzein terminal first.
- MUST run impact analysis before editing any symbol. Before modifying a function, class, or method, run
gitnexus_impact({target: "symbolName", direction: "upstream"})and report the blast radius (direct callers, affected processes, risk level) to the user. - MUST run
gitnexus_detect_changes()before committing to verify your changes only affect expected symbols and execution flows. - MUST warn the user if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
- When exploring unfamiliar code, use
gitnexus_query({query: "concept"})to find execution flows instead of grepping. It returns process-grouped results ranked by relevance. - When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use
gitnexus_context({name: "symbolName"}).
gitnexus_query({query: "<error or symptom>"})— find execution flows related to the issuegitnexus_context({name: "<suspect function>"})— see all callers, callees, and process participationREAD gitnexus://repo/ask-legion/process/{processName}— trace the full execution flow step by step- For regressions:
gitnexus_detect_changes({scope: "compare", base_ref: "main"})— see what your branch changed
- Renaming: MUST use
gitnexus_rename({symbol_name: "old", new_name: "new", dry_run: true})first. Review the preview — graph edits are safe, text_search edits need manual review. Then run withdry_run: false. - Extracting/Splitting: MUST run
gitnexus_context({name: "target"})to see all incoming/outgoing refs, thengitnexus_impact({target: "target", direction: "upstream"})to find all external callers before moving code. - After any refactor: run
gitnexus_detect_changes({scope: "all"})to verify only expected files changed.
- NEVER edit a function, class, or method without first running
gitnexus_impacton it. - NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
- NEVER rename symbols with find-and-replace — use
gitnexus_renamewhich understands the call graph. - NEVER commit changes without running
gitnexus_detect_changes()to check affected scope.
| Tool | When to use | Command |
|---|---|---|
query |
Find code by concept | gitnexus_query({query: "auth validation"}) |
context |
360-degree view of one symbol | gitnexus_context({name: "validateUser"}) |
impact |
Blast radius before editing | gitnexus_impact({target: "X", direction: "upstream"}) |
detect_changes |
Pre-commit scope check | gitnexus_detect_changes({scope: "staged"}) |
rename |
Safe multi-file rename | gitnexus_rename({symbol_name: "old", new_name: "new", dry_run: true}) |
cypher |
Custom graph queries | gitnexus_cypher({query: "MATCH ..."}) |
| Depth | Meaning | Action |
|---|---|---|
| d=1 | WILL BREAK — direct callers/importers | MUST update these |
| d=2 | LIKELY AFFECTED — indirect deps | Should test |
| d=3 | MAY NEED TESTING — transitive | Test if critical path |
| Resource | Use for |
|---|---|
gitnexus://repo/ask-legion/context |
Codebase overview, check index freshness |
gitnexus://repo/ask-legion/clusters |
All functional areas |
gitnexus://repo/ask-legion/processes |
All execution flows |
gitnexus://repo/ask-legion/process/{name} |
Step-by-step execution trace |
Before completing any code modification task, verify:
gitnexus_impactwas run for all modified symbols- No HIGH/CRITICAL risk warnings were ignored
gitnexus_detect_changes()confirms changes match expected scope- All d=1 (WILL BREAK) dependents were updated
After committing code changes, the GitNexus index becomes stale. Re-run analyze to update it:
npx gitnexus analyzeIf the index previously included embeddings, preserve them by adding --embeddings:
npx gitnexus analyze --embeddingsTo check whether embeddings exist, inspect .gitnexus/meta.json — the stats.embeddings field shows the count (0 means no embeddings). Running analyze without --embeddings will delete any previously generated embeddings.
Claude Code users: A PostToolUse hook handles this automatically after
git commitandgit merge.
| Task | Read this skill file |
|---|---|
| Understand architecture / "How does X work?" | .claude/skills/gitnexus/gitnexus-exploring/SKILL.md |
| Blast radius / "What breaks if I change X?" | .claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md |
| Trace bugs / "Why is X failing?" | .claude/skills/gitnexus/gitnexus-debugging/SKILL.md |
| Rename / extract / split / refactor | .claude/skills/gitnexus/gitnexus-refactoring/SKILL.md |
| Tools, resources, schema reference | .claude/skills/gitnexus/gitnexus-guide/SKILL.md |
| Index, status, clean, wiki CLI commands | .claude/skills/gitnexus/gitnexus-cli/SKILL.md |