claude-code-scanner 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/DOCUMENTATION.md +1210 -0
  2. package/LICENSE +21 -0
  3. package/README.md +306 -0
  4. package/bin/cli.js +305 -0
  5. package/package.json +43 -0
  6. package/template/.claude/agents/api-builder.md +64 -0
  7. package/template/.claude/agents/architect.md +92 -0
  8. package/template/.claude/agents/debugger.md +69 -0
  9. package/template/.claude/agents/explorer.md +71 -0
  10. package/template/.claude/agents/frontend.md +61 -0
  11. package/template/.claude/agents/infra.md +66 -0
  12. package/template/.claude/agents/product-owner.md +73 -0
  13. package/template/.claude/agents/qa-lead.md +102 -0
  14. package/template/.claude/agents/reviewer.md +77 -0
  15. package/template/.claude/agents/security.md +81 -0
  16. package/template/.claude/agents/team-lead.md +128 -0
  17. package/template/.claude/agents/tester.md +72 -0
  18. package/template/.claude/docs/agent-error-protocol.md +89 -0
  19. package/template/.claude/docs/best-practices.md +93 -0
  20. package/template/.claude/docs/commands-template.md +73 -0
  21. package/template/.claude/docs/conflict-resolution-protocol.md +82 -0
  22. package/template/.claude/docs/context-budget.md +54 -0
  23. package/template/.claude/docs/execution-metrics-protocol.md +105 -0
  24. package/template/.claude/docs/flow-engine.md +475 -0
  25. package/template/.claude/docs/smithery-setup.md +51 -0
  26. package/template/.claude/docs/task-record-schema.md +196 -0
  27. package/template/.claude/hooks/drift-detector.js +143 -0
  28. package/template/.claude/hooks/execution-report.js +114 -0
  29. package/template/.claude/hooks/notify-approval.js +30 -0
  30. package/template/.claude/hooks/post-compact-recovery.js +68 -0
  31. package/template/.claude/hooks/post-edit-format.js +43 -0
  32. package/template/.claude/hooks/pre-compact-save.js +94 -0
  33. package/template/.claude/hooks/protect-files.js +39 -0
  34. package/template/.claude/hooks/session-start.js +76 -0
  35. package/template/.claude/hooks/stop-failure-handler.js +77 -0
  36. package/template/.claude/hooks/tool-failure-tracker.js +54 -0
  37. package/template/.claude/hooks/track-file-changes.js +34 -0
  38. package/template/.claude/hooks/validate-bash.js +34 -0
  39. package/template/.claude/manifest.json +22 -0
  40. package/template/.claude/profiles/backend.md +34 -0
  41. package/template/.claude/profiles/devops.md +36 -0
  42. package/template/.claude/profiles/frontend.md +34 -0
  43. package/template/.claude/rules/context-budget.md +34 -0
  44. package/template/.claude/scripts/verify-setup.js +210 -0
  45. package/template/.claude/settings.json +154 -0
  46. package/template/.claude/skills/context-check/SKILL.md +112 -0
  47. package/template/.claude/skills/execution-report/SKILL.md +229 -0
  48. package/template/.claude/skills/generate-environment/SKILL.md +128 -0
  49. package/template/.claude/skills/generate-environment/additional-skills.md +276 -0
  50. package/template/.claude/skills/generate-environment/artifact-templates.md +386 -0
  51. package/template/.claude/skills/generate-environment/domain-agents.md +202 -0
  52. package/template/.claude/skills/impact-analysis/SKILL.md +17 -0
  53. package/template/.claude/skills/metrics/SKILL.md +19 -0
  54. package/template/.claude/skills/progress-report/SKILL.md +27 -0
  55. package/template/.claude/skills/rollback/SKILL.md +75 -0
  56. package/template/.claude/skills/scan-codebase/SKILL.md +59 -0
  57. package/template/.claude/skills/scan-codebase/deep-scan-instructions.md +101 -0
  58. package/template/.claude/skills/scan-codebase/tech-markers.md +87 -0
  59. package/template/.claude/skills/setup-smithery/SKILL.md +38 -0
  60. package/template/.claude/skills/sync/SKILL.md +239 -0
  61. package/template/.claude/skills/task-tracker/SKILL.md +40 -0
  62. package/template/.claude/skills/validate-setup/SKILL.md +30 -0
  63. package/template/.claude/skills/workflow/SKILL.md +333 -0
  64. package/template/.claude/templates/README.md +42 -0
  65. package/template/CLAUDE.md +67 -0
@@ -0,0 +1,1210 @@
1
+ # Claude Code Scanner — Complete Documentation
2
+
3
+ > Scan any codebase and generate a production-ready AI-powered development environment with 12 role-based agents, 13 workflow skills, 12 automation hooks, and a full 13-phase SDLC pipeline.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [What Is This?](#1-what-is-this)
10
+ 2. [Quick Start (5 Minutes)](#2-quick-start)
11
+ 3. [Installation Methods](#3-installation-methods)
12
+ 4. [How It Works (4-Phase Setup)](#4-how-it-works)
13
+ 5. [The Agent Team (12 Roles)](#5-the-agent-team)
14
+ 6. [Skills Reference (13 Commands)](#6-skills-reference)
15
+ 7. [The Workflow Engine (13 Phases)](#7-the-workflow-engine)
16
+ 8. [Loop Flows & Circuit Breakers](#8-loop-flows--circuit-breakers)
17
+ 9. [Hooks & Automation (12 Hooks)](#9-hooks--automation)
18
+ 10. [Task Tracking System](#10-task-tracking-system)
19
+ 11. [Execution Reports & Scoring](#11-execution-reports--scoring)
20
+ 12. [Context Budget Management](#12-context-budget-management)
21
+ 13. [Drift Detection & Sync](#13-drift-detection--sync)
22
+ 14. [Error Recovery](#14-error-recovery)
23
+ 15. [Configuration Reference](#15-configuration-reference)
24
+ 16. [File Structure](#16-file-structure)
25
+ 17. [Customization Guide](#17-customization-guide)
26
+ 18. [Troubleshooting](#18-troubleshooting)
27
+
28
+ ---
29
+
30
+ ## 1. What Is This?
31
+
32
+ Claude Code Scanner is a tool that scans your existing codebase and generates a complete Claude Code development environment tailored to your project. Instead of manually configuring agents, skills, and rules, the scanner reads your actual code and creates everything automatically.
33
+
34
+ **What you get:**
35
+ - 12 AI agents organized as a development team (tech lead, architect, QA lead, developers, etc.)
36
+ - 13 slash commands for common workflows
37
+ - 12 automation hooks that run behind the scenes
38
+ - A 13-phase SDLC workflow from task intake to production deployment
39
+ - Execution analytics with success scoring and hallucination detection
40
+ - Automatic drift detection that keeps your environment in sync with your codebase
41
+
42
+ **Who it's for:**
43
+ - Development teams using Claude Code who want structured AI-assisted workflows
44
+ - Projects that need role-based agent access control (read-only reviewers, write-capable developers)
45
+ - Teams that want full SDLC automation (not just code generation)
46
+
47
+ ---
48
+
49
+ ## 2. Quick Start
50
+
51
+ ```bash
52
+ # Step 1: Go to your project
53
+ cd /path/to/your-project
54
+
55
+ # Step 2: Install the scanner
56
+ npx claude-code-scanner init
57
+
58
+ # Step 3: Start Claude Code
59
+ claude
60
+
61
+ # Step 4: Scan your codebase (2-5 minutes)
62
+ /scan-codebase
63
+
64
+ # Step 5: Generate your environment
65
+ /generate-environment
66
+
67
+ # Step 6: Start working
68
+ /workflow new "add user notifications feature"
69
+ ```
70
+
71
+ That's it. Your project now has a complete AI development team.
72
+
73
+ ---
74
+
75
+ ## 3. Installation Methods
76
+
77
+ ### npx (Recommended — No Install)
78
+ ```bash
79
+ npx claude-code-scanner init
80
+ ```
81
+
82
+ ### One-Line Install (macOS/Linux)
83
+ ```bash
84
+ curl -fsSL https://raw.githubusercontent.com/adnan-prompts/claude-code-scanner/main/install.sh | bash
85
+ ```
86
+
87
+ ### One-Line Install (Windows PowerShell)
88
+ ```powershell
89
+ irm https://raw.githubusercontent.com/adnan-prompts/claude-code-scanner/main/install.ps1 | iex
90
+ ```
91
+
92
+ ### Git Clone
93
+ ```bash
94
+ git clone https://github.com/adnan-prompts/claude-code-scanner.git /tmp/scanner
95
+ cp /tmp/scanner/template/CLAUDE.md ./CLAUDE.md
96
+ cp -r /tmp/scanner/template/.claude ./.claude
97
+ rm -rf /tmp/scanner
98
+ ```
99
+
100
+ ### Global Install
101
+ ```bash
102
+ npm install -g claude-code-scanner
103
+ claude-code-scanner init
104
+ ```
105
+
106
+ ### CLI Commands After Install
107
+ ```bash
108
+ claude-code-scanner init # Set up environment
109
+ claude-code-scanner init --force # Overwrite existing files
110
+ claude-code-scanner status # Check setup status
111
+ claude-code-scanner verify # Run 170+ validation checks
112
+ claude-code-scanner update # Update to latest version
113
+ ```
114
+
115
+ ### Requirements
116
+ - Node.js >= 18
117
+ - Claude Code CLI installed
118
+ - Works on Windows, macOS, and Linux
119
+
120
+ ---
121
+
122
+ ## 4. How It Works
123
+
124
+ The setup runs in 4 phases:
125
+
126
+ ### Phase 1: Scan (`/scan-codebase`)
127
+
128
+ Spawns 6 parallel agents that read your actual code:
129
+
130
+ | Agent | What It Does |
131
+ |-------|-------------|
132
+ | Technology Fingerprinter | Reads 100+ marker files (package.json, go.mod, Cargo.toml, etc.) to identify languages, frameworks, databases, APIs, testing tools, and infrastructure |
133
+ | Directory Scanner | Maps your project tree up to 4 levels, classifying each directory (source, tests, config, generated, vendor) |
134
+ | Backend Scanner | Reads source files to identify API routes, middleware, validation, auth, database layer, background jobs, error handling |
135
+ | Frontend Scanner | Reads 3-5 components to identify framework, rendering mode, routing, state management, styling, TypeScript config |
136
+ | Architecture Mapper | Traces a request end-to-end through your system, maps module boundaries, dependency graph, deployment topology |
137
+ | Convention Extractor | Reads 20+ files to extract naming conventions, code style, error patterns, git conventions, TODOs, existing AI config |
138
+
139
+ **Output:** `.claude/scan-results.md` — a structured manifest of everything found.
140
+
141
+ ### Phase 2: Generate (`/generate-environment`)
142
+
143
+ Takes the scan results and generates project-specific files:
144
+ - CLAUDE.md with your exact commands, paths, and conventions
145
+ - Rules that enforce your codebase patterns
146
+ - Agents configured for your tech stack
147
+ - Skills with your project's commands and file paths
148
+ - Templates extracted from your real code (not generic boilerplate)
149
+ - Hooks customized for your formatter, linter, and test runner
150
+
151
+ ### Phase 3: Validate (`/validate-setup`)
152
+
153
+ Runs 170+ automated checks:
154
+ - CLAUDE.md under 200 lines, no placeholders
155
+ - All 12 agents compliant (frontmatter, HANDOFF, limitations)
156
+ - All skills have proper frontmatter (context:fork, argument-hint)
157
+ - Settings.json valid, all hooks registered
158
+ - Context budget under limits
159
+ - Flow engine documentation complete
160
+
161
+ ### Phase 4: Extend (`/setup-smithery`)
162
+
163
+ Optionally installs community skills and MCP servers matching your tech stack (React tools, database connections, CI/CD integrations).
164
+
165
+ ---
166
+
167
+ ## 5. The Agent Team
168
+
169
+ ### Understanding Agent Roles
170
+
171
+ The scanner creates a 12-agent team organized like a real development organization. Each agent has:
172
+
173
+ - **Specific tools** — what it can read/write/execute
174
+ - **Permission mode** — read-only agents can't modify code
175
+ - **Model assignment** — opus for complex reasoning, sonnet for routine work
176
+ - **Memory** — persists context across sessions
177
+ - **Structured output** — standardized HANDOFF blocks for agent-to-agent communication
178
+ - **Explicit limitations** — what the agent must NOT do
179
+
180
+ ### SDLC Role Agents (Leadership)
181
+
182
+ These 4 agents manage the development process. Three are **read-only** — they review, plan, and decide, but never write code. The @team-lead has Read/Write access to orchestrate work.
183
+
184
+ #### @team-lead (Tech Lead)
185
+ ```
186
+ Model: opus | Access: Read/Write | MaxTurns: 50
187
+ ```
188
+ The orchestrator. Assigns tasks to agents, tracks progress, resolves blockers, provides tech sign-off. The only agent that coordinates work across the entire team.
189
+
190
+ **When to use:** You don't call @team-lead directly — the `/workflow` skill invokes it automatically. But you can ask it to check task status or resolve a blocker.
191
+
192
+ **Example:**
193
+ ```
194
+ @team-lead what's the status of TASK-001?
195
+ @team-lead assign the auth refactor to @api-builder
196
+ ```
197
+
198
+ #### @architect (Software Architect)
199
+ ```
200
+ Model: opus | Access: Read-only | MaxTurns: 25
201
+ ```
202
+ Designs solutions with alternatives and trade-offs. Reviews architecture impact of changes. Creates Mermaid diagrams.
203
+
204
+ **When to use:** Before making structural changes, when evaluating multiple approaches, or when you need a design document.
205
+
206
+ **Example:**
207
+ ```
208
+ @architect design the migration from REST to GraphQL
209
+ @architect review the impact of splitting the user service
210
+ ```
211
+
212
+ **Output includes:** Design options table, recommendation with rationale, Mermaid diagram, decision record.
213
+
214
+ #### @product-owner (Product Owner)
215
+ ```
216
+ Model: opus | Access: Read-only | MaxTurns: 20
217
+ ```
218
+ Writes acceptance criteria in GIVEN/WHEN/THEN format. Validates business requirements against implementation. Provides business sign-off.
219
+
220
+ **When to use:** When defining what a feature should do, when verifying requirements are met, or during business sign-off.
221
+
222
+ **Example:**
223
+ ```
224
+ @product-owner write acceptance criteria for the password reset feature
225
+ @product-owner verify TASK-001 meets the business requirements
226
+ ```
227
+
228
+ **Output includes:** Acceptance criteria table (GIVEN/WHEN/THEN with PENDING/VERIFIED/FAILED status), sign-off decision.
229
+
230
+ #### @qa-lead (QA Lead)
231
+ ```
232
+ Model: sonnet | Access: Read-only | MaxTurns: 25
233
+ ```
234
+ Creates QA test plans, triages bugs by severity (P0-P4), provides QA sign-off. Distinct from @tester — @qa-lead plans strategy, @tester writes and runs tests.
235
+
236
+ **When to use:** When you need a test plan, when triaging bugs, or during QA sign-off.
237
+
238
+ **Example:**
239
+ ```
240
+ @qa-lead create a QA plan for the checkout flow changes
241
+ @qa-lead triage these 5 bugs and recommend which block release
242
+ ```
243
+
244
+ **Output includes:** Scenario table (happy path, edge cases, regression, security, accessibility), bug severity classification, sign-off decision.
245
+
246
+ ### Core Agents (Specialists)
247
+
248
+ #### @explorer (Codebase Navigator)
249
+ ```
250
+ Model: sonnet | Access: Read-only | MaxTurns: 30
251
+ ```
252
+ Investigates how code works. Traces data flow, maps dependencies, assesses change impact.
253
+
254
+ **When to use:** When you need to understand unfamiliar code, trace a bug's path, or assess what a change will affect.
255
+
256
+ **Example:**
257
+ ```
258
+ @explorer how does the auth middleware work?
259
+ @explorer what would be affected if I change the User model?
260
+ @explorer trace the order creation flow from API to database
261
+ ```
262
+
263
+ **Output includes:** File:line references, dependency graph, impact assessment with risk level.
264
+
265
+ #### @reviewer (Code Reviewer)
266
+ ```
267
+ Model: sonnet | Access: Read-only | MaxTurns: 20
268
+ ```
269
+ Reviews code changes for quality, conventions, and correctness. Generates comments with file:line references.
270
+
271
+ **When to use:** After writing code, before creating a PR, or when reviewing someone else's changes.
272
+
273
+ **Example:**
274
+ ```
275
+ @reviewer review my changes in the last 3 commits
276
+ @reviewer check the auth module for best practices
277
+ ```
278
+
279
+ **Output includes:** Review summary (APPROVE/REQUEST_CHANGES), comments table with file:line and severity.
280
+
281
+ #### @security (Security Reviewer)
282
+ ```
283
+ Model: opus | Access: Read-only | MaxTurns: 20
284
+ ```
285
+ Reviews code for vulnerabilities, auth issues, and OWASP Top 10 risks. Checks for injection, XSS, broken auth, PII exposure, hardcoded secrets.
286
+
287
+ **When to use:** Before any code touches auth, user input, database queries, or handles sensitive data.
288
+
289
+ **Example:**
290
+ ```
291
+ @security audit the new payment endpoint
292
+ @security check for PII exposure in the logging module
293
+ ```
294
+
295
+ **Output includes:** Findings table with severity/category/recommendation, risk level (LOW/MEDIUM/HIGH/CRITICAL).
296
+
297
+ #### @debugger (Bug Fixer)
298
+ ```
299
+ Model: opus | Access: Read/Write | MaxTurns: 40
300
+ ```
301
+ Finds root causes and applies minimal fixes. Uses structured reasoning: reproduce, hypothesize, narrow, verify, fix, regress.
302
+
303
+ **When to use:** When tests fail, CI breaks, or there's a bug in production.
304
+
305
+ **Example:**
306
+ ```
307
+ @debugger the user creation test is failing with "null reference"
308
+ @debugger fix the CI failure in the auth pipeline
309
+ ```
310
+
311
+ **Output includes:** Debug report (error, root cause, evidence, fix), regression test, files modified.
312
+
313
+ #### @tester (Test Writer)
314
+ ```
315
+ Model: sonnet | Access: Read/Write | MaxTurns: 30
316
+ ```
317
+ Writes automated tests (unit, integration, e2e) following your project's existing patterns. Runs test suites and measures coverage.
318
+
319
+ **When to use:** After implementing a feature, when coverage is low, or when you need regression tests.
320
+
321
+ **Example:**
322
+ ```
323
+ @tester write tests for the new order service
324
+ @tester check coverage for the auth module
325
+ ```
326
+
327
+ **Output includes:** Test report (tests written, passing/failing, coverage before/after).
328
+
329
+ ### Dev Agents (Builders)
330
+
331
+ #### @api-builder (Backend Developer)
332
+ ```
333
+ Model: sonnet | Access: Read/Write + Worktree | MaxTurns: 30
334
+ ```
335
+ Builds API endpoints, services, middleware, validation. Follows your project's existing patterns exactly.
336
+
337
+ **When to use:** When building backend features — routes, handlers, services, database operations.
338
+
339
+ **Example:**
340
+ ```
341
+ @api-builder create POST /api/orders endpoint with validation
342
+ @api-builder add pagination to the users list endpoint
343
+ ```
344
+
345
+ **Output includes:** Implementation summary (endpoint, files, auth, validation, response format).
346
+
347
+ #### @frontend (Frontend Developer)
348
+ ```
349
+ Model: sonnet | Access: Read/Write + Worktree | MaxTurns: 30
350
+ ```
351
+ Builds UI components, pages, styling. Ensures accessibility (ARIA, keyboard, screen reader support).
352
+
353
+ **When to use:** When building UI — components, pages, forms, styling.
354
+
355
+ **Example:**
356
+ ```
357
+ @frontend create a UserProfile component with edit mode
358
+ @frontend add a dashboard page with charts
359
+ ```
360
+
361
+ **Output includes:** Implementation summary (files, component API, accessibility notes).
362
+
363
+ #### @infra (DevOps Engineer)
364
+ ```
365
+ Model: sonnet | Access: Read/Write | MaxTurns: 30
366
+ ```
367
+ Manages Docker, CI/CD, deployment, cloud resources. Never hardcodes secrets.
368
+
369
+ **When to use:** For infrastructure changes — Dockerfiles, CI pipelines, deployment scripts, environment configuration.
370
+
371
+ **Example:**
372
+ ```
373
+ @infra add a staging deployment to the GitHub Actions workflow
374
+ @infra optimize the Docker build for faster CI
375
+ ```
376
+
377
+ **Output includes:** Infrastructure changes, new env vars, rollback plan.
378
+
379
+ ### Agent Communication
380
+
381
+ Agents communicate through structured **HANDOFF** blocks:
382
+
383
+ ```
384
+ HANDOFF:
385
+ from: @tester
386
+ to: @team-lead
387
+ reason: testing complete — 3 failures found
388
+ artifacts:
389
+ - test-results.json
390
+ - coverage-report.html
391
+ context: |
392
+ 3 tests fail in auth module. Root cause appears to be
393
+ missing null check in token validation.
394
+ iteration: 2/5
395
+ execution_metrics:
396
+ turns_used: 12
397
+ files_read: 8
398
+ files_modified: 3
399
+ tests_run: 47 (44 pass / 3 fail / 0 skip)
400
+ coverage_delta: "+2%"
401
+ hallucination_flags: CLEAN
402
+ regression_flags: CLEAN
403
+ confidence: HIGH
404
+ ```
405
+
406
+ **All routing goes through the orchestrator.** Agents never call each other directly — subagents can't spawn subagents in Claude Code.
407
+
408
+ ---
409
+
410
+ ## 6. Skills Reference
411
+
412
+ Skills are slash commands you type in Claude Code. Here's every skill and how to use it.
413
+
414
+ ### Setup Skills
415
+
416
+ #### /scan-codebase
417
+ ```
418
+ /scan-codebase
419
+ /scan-codebase /path/to/project
420
+ ```
421
+ Scans your codebase with 6 parallel agents. Takes 2-5 minutes. Outputs scan results to `.claude/scan-results.md`. Run this first before generating the environment.
422
+
423
+ #### /generate-environment
424
+ ```
425
+ /generate-environment
426
+ ```
427
+ Takes scan results and generates all Claude Code files (CLAUDE.md, agents, skills, hooks, rules, templates, profiles). Must run `/scan-codebase` first — will error if scan results are missing.
428
+
429
+ #### /validate-setup
430
+ ```
431
+ /validate-setup
432
+ ```
433
+ Runs 170+ automated checks on your environment. Reports PASS/FAIL/WARN with specific fix instructions. Run after `/generate-environment` to verify everything is correct.
434
+
435
+ #### /setup-smithery
436
+ ```
437
+ /setup-smithery
438
+ ```
439
+ Installs community Smithery skills and MCP servers matching your tech stack. Optional — enhances the environment with third-party tools.
440
+
441
+ ### Workflow Skills
442
+
443
+ #### /workflow
444
+ ```
445
+ /workflow new "add user notifications" # Start full 13-phase SDLC
446
+ /workflow new --hotfix "fix login crash" # Fast-track hotfix (tighter limits)
447
+ /workflow new --spike "evaluate Redis" # Research only (no code)
448
+ /workflow status # Show all active tasks
449
+ /workflow resume TASK-001 # Resume ON_HOLD task
450
+ /workflow cancel TASK-001 # Cancel with cleanup
451
+ /workflow dev TASK-001 # Jump to development phase
452
+ /workflow review TASK-001 # Jump to review phase
453
+ /workflow deploy TASK-001 # Jump to deployment phase
454
+ ```
455
+ The main orchestrator. Coordinates all 12 agents through 13 phases. Includes automatic drift detection at Phase 1, context budget checks between phases, and execution reports after each phase.
456
+
457
+ #### /task-tracker
458
+ ```
459
+ /task-tracker create "implement search" # Create new task
460
+ /task-tracker status # Dashboard of all tasks
461
+ /task-tracker status TASK-001 # Single task detail
462
+ /task-tracker update TASK-001 phase=6 status=DEV_TESTING
463
+ /task-tracker update TASK-001 blocked="waiting on API team"
464
+ /task-tracker update TASK-001 unblocked
465
+ /task-tracker report TASK-001 # Full detail report
466
+ /task-tracker dashboard # Visual dashboard
467
+ /task-tracker history TASK-001 # Timeline of events
468
+ /task-tracker blockers # All open blockers
469
+ /task-tracker metrics # Aggregate performance
470
+ ```
471
+ Manages task lifecycle from BACKLOG to CLOSED. Tracks every phase, loop iteration, handoff, blocker, and decision.
472
+
473
+ ### Analysis Skills
474
+
475
+ #### /impact-analysis
476
+ ```
477
+ /impact-analysis "replace the auth middleware"
478
+ /impact-analysis "upgrade React from 18 to 19"
479
+ ```
480
+ Runs @explorer + @security in parallel to assess blast radius. Outputs: files affected, transitive dependencies, test coverage %, security flags, risk level, Mermaid dependency diagram.
481
+
482
+ #### /context-check
483
+ ```
484
+ /context-check # Check current context usage
485
+ /context-check --compact # Check and auto-compact if over budget
486
+ ```
487
+ Measures context window usage against the 60% working budget. Reports GREEN/YELLOW/ORANGE/RED status. Recommends compaction when needed. Runs automatically between workflow phases.
488
+
489
+ ### Reporting Skills
490
+
491
+ #### /execution-report
492
+ ```
493
+ /execution-report TASK-001 # Full task report
494
+ /execution-report TASK-001 --phase 6 # Single phase report
495
+ /execution-report last # Most recent task
496
+ /execution-report all --verbose # All tasks with detail
497
+ ```
498
+ Post-execution analytics. Generates:
499
+ - **Success Score (0-100):** completeness + quality + efficiency
500
+ - **Hallucination Check (0-3):** verifies file references, function names, conventions
501
+ - **Regression Impact (0-3):** test results, coverage delta, lint/type/build status
502
+ - **Agent Communication:** handoff count, loop iterations, parallel executions
503
+ - **Token/Context Usage:** estimated consumption, peak context %
504
+
505
+ #### /progress-report
506
+ ```
507
+ /progress-report dev TASK-001 # Developer: files, tests, coverage
508
+ /progress-report qa TASK-001 # QA: changes, test scenarios, risks
509
+ /progress-report business # Business: acceptance criteria, ETA
510
+ /progress-report management # Management: portfolio table, health
511
+ /progress-report executive # Executive: status light, key metrics
512
+ ```
513
+ Generates audience-specific reports. Each audience gets different information at different detail levels.
514
+
515
+ #### /metrics
516
+ ```
517
+ /metrics velocity # Tasks/week, throughput, WIP
518
+ /metrics quality # Test pass rate, coverage, bug escape rate
519
+ /metrics cycle-time # Per-phase average, bottlenecks
520
+ /metrics agents # Per-agent performance, rework rate
521
+ /metrics blockers # Resolution time, categories
522
+ /metrics all --period 30d # Everything, last 30 days
523
+ ```
524
+ Calculates aggregate performance metrics from task records.
525
+
526
+ ### Maintenance Skills
527
+
528
+ #### /sync
529
+ ```
530
+ /sync --check # Detect drift (report only)
531
+ /sync --fix # Detect and auto-repair
532
+ /sync --fix --component agents # Fix only agent files
533
+ /sync --fix --component claude-md # Fix only CLAUDE.md
534
+ /sync --full-rescan # Complete re-scan + regenerate
535
+ ```
536
+ Detects drift between your Claude Code environment and the actual codebase across 8 categories: agents, skills, hooks, rules, CLAUDE.md, settings, tech stack, project structure. See [Section 13](#13-drift-detection--sync) for details.
537
+
538
+ #### /rollback
539
+ ```
540
+ /rollback deploy TASK-001 # Rollback failed deployment
541
+ /rollback code TASK-001 # Revert all code changes
542
+ /rollback phase TASK-001 --to-phase 5 # Undo back to Phase 5
543
+ /rollback code --to-commit abc123 # Revert to specific commit
544
+ ```
545
+ Safely undoes deployments, code changes, or workflow phases. Always creates revert commits (never rewrites history). Always runs tests after rollback.
546
+
547
+ ---
548
+
549
+ ## 7. The Workflow Engine
550
+
551
+ The `/workflow` skill orchestrates a 13-phase software development lifecycle. Each phase has specific entry/exit criteria, assigned agents, and quality gates.
552
+
553
+ ### Phase Overview
554
+
555
+ ```
556
+ Phase 1: Task Intake — classify, create branch, drift check
557
+ Phase 2: Impact Analysis — @explorer + @security blast radius scan
558
+ Phase 3: Architecture — @architect designs solution (skip if small+LOW)
559
+ Phase 4: Business Analysis — @product-owner writes acceptance criteria
560
+ Phase 5: Development — @api-builder / @frontend / @infra build code
561
+ Phase 6: Dev Self-Testing — @tester runs tests, @debugger fixes failures
562
+ Phase 7: Code Review — @reviewer + @security review in parallel
563
+ Phase 8: PR + CI — Create PR, fix CI failures
564
+ Phase 9: QA Testing — @qa-lead plans, @tester executes, bug loop
565
+ Phase 10: Sign-offs — QA -> Business -> Tech sequential gates
566
+ Phase 11: Deployment — @infra deploys with health checks
567
+ Phase 12: Post-Deploy — Monitor, close issues, notify
568
+ Phase 13: Execution Report — Scored analytics for the entire workflow
569
+ ```
570
+
571
+ ### Workflow Variants
572
+
573
+ **Normal Feature:**
574
+ All 13 phases in order.
575
+
576
+ **Hotfix (`--hotfix`):**
577
+ Skips Phase 3 (Architecture) and Phase 4 (Business). Uses tighter circuit breakers (max 3 dev-test iterations instead of 5, max 1 deploy attempt). @debugger is the primary dev agent instead of @api-builder.
578
+
579
+ **Spike (`--spike`):**
580
+ Research only. Runs Phase 1-3 (Intake, Impact, Architecture investigation). Produces a research report with findings and recommendation. No code, no tests, no deployment.
581
+
582
+ ### Phase Details
583
+
584
+ #### Phase 1: Task Intake
585
+ - Automatic drift check via `/sync --check`
586
+ - Classifies: type (feature/bugfix/refactor/hotfix/spike)
587
+ - Classifies: scope (frontend/backend/fullstack/infra)
588
+ - Classifies: complexity (small/medium/large)
589
+ - Creates branch and task record in `.claude/tasks/TASK-{id}.md`
590
+ - Checks `depends-on` — blocks if dependency task not ready
591
+
592
+ #### Phase 3: Architecture Review — Skip Condition
593
+ Automatically skipped when ALL of:
594
+ - complexity == small
595
+ - risk == LOW (from Phase 2)
596
+ - type != refactor
597
+
598
+ When skipped, logged in task record. When NOT skipped, @architect produces design with alternatives, Mermaid diagrams, and decision record. User must approve before continuing.
599
+
600
+ #### Phase 5: Development — Sub-Steps
601
+
602
+ | Sub-step | Condition | Agent |
603
+ |----------|-----------|-------|
604
+ | 5a: DB migrations | Backend scope + database changes | @api-builder |
605
+ | 5b: Backend code | Backend scope | @api-builder |
606
+ | 5c: Frontend code | Frontend scope | @frontend |
607
+ | 5d: Tests | Always | @tester |
608
+
609
+ **Fullstack execution:** 5a runs first (DB must be ready). Then 5b + 5c run in parallel using `isolation: worktree` (separate git copies). Backend merges first, frontend adapts. Both must complete before Phase 6.
610
+
611
+ #### Phase 10: Sign-offs — Preservation Rules
612
+
613
+ When a sign-off gate rejects, some earlier approvals are preserved:
614
+
615
+ | Rejection | QA Approval | Biz Approval |
616
+ |-----------|-------------|-------------|
617
+ | QA rejects (bugs) | INVALIDATED | INVALIDATED |
618
+ | Business rejects (reqs) | PRESERVED | INVALIDATED |
619
+ | Business rejects (UI) | PRESERVED | INVALIDATED |
620
+ | Tech rejects (architecture) | INVALIDATED | INVALIDATED |
621
+ | Tech rejects (perf/tests) | PRESERVED | PRESERVED |
622
+
623
+ ---
624
+
625
+ ## 8. Loop Flows & Circuit Breakers
626
+
627
+ Every loop in the workflow has a maximum iteration count. When hit, execution STOPS and escalates to the user.
628
+
629
+ ### Loop Summary
630
+
631
+ | Loop | Phase | Normal Max | Hotfix Max | Scope |
632
+ |------|-------|-----------|------------|-------|
633
+ | Dev-Test | 6 | 5 iterations | 3 | Global |
634
+ | Review-Rework | 7 | 3 iterations | 2 | Global |
635
+ | CI Fix | 8 | 3 iterations | 2 | Global |
636
+ | QA Bug | 9 | 3 per bug, 15 total | 2/bug, 6 total | Per-bug |
637
+ | Sign-off Rejection | 10 | 2 full cycles | 1 cycle | Global |
638
+ | Deploy | 11 | 2 attempts | 1 attempt | Global |
639
+
640
+ ### How Loops Work
641
+
642
+ **Dev-Test Loop (Phase 6):**
643
+ ```
644
+ @tester runs full test suite
645
+ -> ALL PASS -> advance to Phase 7
646
+ -> FAILURES -> route to fix agent by issue type:
647
+ test logic -> @debugger
648
+ backend code -> @api-builder
649
+ frontend code -> @frontend
650
+ config issue -> @infra
651
+ -> fix agent applies fix
652
+ -> @tester re-runs (iteration +1)
653
+ -> iteration 5 -> STOP, escalate to user
654
+ ```
655
+
656
+ **Review-Rework Loop (Phase 7):**
657
+ ```
658
+ @reviewer + @security review in parallel
659
+ -> BOTH APPROVE -> advance to Phase 8
660
+ -> SPLIT DECISION -> stricter verdict wins
661
+ -> REQUEST_CHANGES -> route to dev agent by comment type
662
+ -> fix agent addresses comments
663
+ -> ONLY rejecting reviewer(s) re-review
664
+ -> iteration 3 -> STOP, escalate to user
665
+ ```
666
+
667
+ **QA Bug Loop (Phase 9):**
668
+ ```
669
+ For each bug (P0 first, then P1, then P2):
670
+ @debugger fixes -> @tester runs regression -> @qa-lead re-verifies
671
+ -> VERIFIED -> close bug
672
+ -> REOPENED -> back to @debugger (iteration +1)
673
+ -> per-bug iteration 3 -> escalate that bug
674
+ -> total attempts > 15 -> escalate entire Phase 9
675
+ ```
676
+
677
+ ### Circuit Breaker Options
678
+
679
+ When any loop hits its max, the user is presented with:
680
+ 1. **Continue** — increase max by N iterations
681
+ 2. **Re-plan** — go back to Phase 3 (Architecture Review)
682
+ 3. **Reduce scope** — remove the problematic feature
683
+ 4. **Cancel** — abandon the task
684
+ 5. **Assign to human** — flag for manual intervention
685
+
686
+ ### Loop Counter Resets
687
+
688
+ | Event | What Resets |
689
+ |-------|------------|
690
+ | Phase 10 rejection -> Phase 5 | dev-test, review, ci-fix reset to 0 |
691
+ | Phase 10 rejection -> Phase 3 or 4 | ALL counters reset to 0 |
692
+ | Deploy failure -> Phase 5 | dev-test, review, ci-fix reset to 0 |
693
+ | ON_HOLD -> resume | NO reset (all preserved) |
694
+ | Agent timeout in loop | Counts as +1 iteration |
695
+
696
+ ---
697
+
698
+ ## 9. Hooks & Automation
699
+
700
+ Hooks are scripts that run automatically in response to events. All hooks are cross-platform Node.js (no bash/jq dependency).
701
+
702
+ ### Hook Reference
703
+
704
+ | Event | Hook | What It Does |
705
+ |-------|------|-------------|
706
+ | **SessionStart** (startup/resume/compact) | `session-start.js` | Re-injects active task context. Shows active, ON_HOLD, and BLOCKED tasks |
707
+ | **SessionStart** (startup only) | `drift-detector.js` | Checks for environment drift: stale manifest, agent count mismatch, changed dependencies, orphan hooks |
708
+ | **PreToolUse** (Edit/Write) | `protect-files.js` | Blocks edits to `.env`, `.env.local`, lock files, CI configs |
709
+ | **PreToolUse** (Bash) | `validate-bash.js` | Blocks dangerous commands: `rm -rf /`, fork bombs, `dd if=`, `curl \| bash` |
710
+ | **PostToolUse** (Edit/Write) | `post-edit-format.js` | Auto-formats edited files (Prettier, Black, gofmt, rustfmt) |
711
+ | **PostToolUse** (Edit/Write) | `track-file-changes.js` | Logs file modifications to active task's changes log |
712
+ | **PostToolUseFailure** | `tool-failure-tracker.js` | Logs tool failures for debugging and execution reports |
713
+ | **PreCompact** | `pre-compact-save.js` | Saves loop state, handoffs, blockers to disk before compaction destroys them |
714
+ | **PostCompact** | `post-compact-recovery.js` | Re-injects loop state, last handoff, open bugs, blockers after compaction |
715
+ | **Notification** (permission_prompt) | `notify-approval.js` | OS notification when Claude needs your approval (macOS/Windows/Linux) |
716
+ | **SubagentStop** | `track-file-changes.js` | Records file changes from subagent executions |
717
+ | **Stop** | `execution-report.js` + prompt | Captures execution snapshot and forces mandatory completion report |
718
+ | **StopFailure** | `stop-failure-handler.js` | Preserves task state on rate limits, auth failures, server errors. Provides recovery instructions |
719
+
720
+ ### How Hooks Interact with Workflow
721
+
722
+ ```
723
+ Session starts
724
+ -> session-start.js: "ACTIVE TASK: TASK-001 | STATUS: DEV_TESTING"
725
+ -> drift-detector.js: "DRIFT: package.json changed since last sync"
726
+
727
+ You edit a file
728
+ -> protect-files.js: blocks if .env or lock file
729
+ -> (edit happens)
730
+ -> post-edit-format.js: auto-formats
731
+ -> track-file-changes.js: logs to TASK-001_changes.log
732
+
733
+ Context hits 95%
734
+ -> pre-compact-save.js: saves loop state to disk
735
+ -> (compaction runs)
736
+ -> post-compact-recovery.js: "LOOP STATE: dev-test-loop: 3/5"
737
+
738
+ Session ends
739
+ -> execution-report.js: captures metrics snapshot
740
+ -> Stop prompt: forces success score calculation
741
+
742
+ Session crashes
743
+ -> stop-failure-handler.js: preserves state, logs error
744
+ -> "Recovery: Wait 60 seconds, then resume: claude --continue"
745
+ ```
746
+
747
+ ---
748
+
749
+ ## 10. Task Tracking System
750
+
751
+ Every task is tracked as a markdown file in `.claude/tasks/TASK-{id}.md`.
752
+
753
+ ### Task Record Structure
754
+
755
+ ```yaml
756
+ ---
757
+ id: TASK-001
758
+ title: Add user notification system
759
+ type: feature
760
+ scope: fullstack
761
+ complexity: medium
762
+ priority: P2-medium
763
+ status: DEV_TESTING
764
+ branch: feat/TASK-001-notifications
765
+ pr: 42
766
+ assigned-to: @api-builder
767
+ depends-on: none
768
+ created: 2026-03-26T10:00:00Z
769
+ updated: 2026-03-26T14:30:00Z
770
+ ---
771
+ ```
772
+
773
+ ### Task States
774
+
775
+ ```
776
+ BACKLOG -> INTAKE -> ANALYZING -> DESIGNING -> APPROVED
777
+ -> DEVELOPING -> DEV_TESTING -> REVIEWING -> CI_PENDING
778
+ -> QA_TESTING -> QA_SIGNOFF -> BIZ_SIGNOFF -> TECH_SIGNOFF
779
+ -> DEPLOYING -> MONITORING -> CLOSED
780
+
781
+ Special states (from any active state):
782
+ BLOCKED — waiting on dependency or manual resolution
783
+ ON_HOLD — deferred by user or product owner
784
+ CANCELLED — terminated with cleanup
785
+ ```
786
+
787
+ ### What Gets Tracked
788
+
789
+ - **Loop State:** every iteration counter, baseline values, fix agents, last failures
790
+ - **Handoff Log:** every agent-to-agent transition with timestamps
791
+ - **Timeline:** every event with phase, description, actor, duration
792
+ - **Phase Details:** specific outputs for each of 13 phases
793
+ - **Blocker Log:** timestamp, severity, owner, resolution
794
+ - **Decision Log:** what was decided, rationale, who decided, reversibility
795
+ - **Risk Register:** risks, likelihood, impact, mitigation status
796
+ - **Execution Reports:** per-phase scores, token usage, agent stats
797
+ - **Bug Records:** per-bug severity, status, fix iterations
798
+
799
+ ---
800
+
801
+ ## 11. Execution Reports & Scoring
802
+
803
+ After every phase and at workflow completion, an execution report is generated.
804
+
805
+ ### Success Score (0-100)
806
+
807
+ | Category | Points | What It Measures |
808
+ |----------|--------|-----------------|
809
+ | Completeness | 40 | Phase exit criteria met, acceptance criteria verified, no skipped phases, task advanced |
810
+ | Quality | 30 | Tests pass, coverage maintained, no lint/type errors, review approved, security clean |
811
+ | Efficiency | 30 | Completed within expected turns, no circuit breakers, context under 60%, loops resolved quickly |
812
+
813
+ **Interpretation:**
814
+ - 90-100: EXCELLENT
815
+ - 70-89: GOOD
816
+ - 50-69: FAIR (rework detected)
817
+ - 30-49: POOR
818
+ - 0-29: FAILED
819
+
820
+ ### Hallucination Check (0-3)
821
+
822
+ | Score | Level | Meaning |
823
+ |-------|-------|---------|
824
+ | 0 | CLEAN | All file:line references verified, all function names real, patterns match project |
825
+ | 1 | MINOR | Cosmetic mismatches (wrong line numbers, outdated paths) |
826
+ | 2 | MODERATE | Referenced non-existent functions or wrong imports. **Blocks advancement** |
827
+ | 3 | SEVERE | Generated code based on invented APIs. **Blocks advancement** |
828
+
829
+ ### Regression Impact (0-3)
830
+
831
+ | Score | Level | Meaning |
832
+ |-------|-------|---------|
833
+ | 0 | CLEAN | No new test failures, coverage maintained |
834
+ | 1 | LOW | Coverage decreased slightly, no new failures |
835
+ | 2 | MEDIUM | New test failures introduced. **Blocks advancement** |
836
+ | 3 | HIGH | Build broken or critical regressions. **Blocks advancement** |
837
+
838
+ ### Where Reports Are Saved
839
+
840
+ ```
841
+ .claude/reports/executions/TASK-001_phase-6_2026-03-26T100000Z.md # Per-phase
842
+ .claude/reports/executions/TASK-001_final.md # Cumulative
843
+ .claude/reports/executions/TASK-001_snapshot_1711443600000.json # Auto-snapshot
844
+ ```
845
+
846
+ ---
847
+
848
+ ## 12. Context Budget Management
849
+
850
+ Claude Code has a limited context window. This framework keeps usage under 60% during active work.
851
+
852
+ ### What Loads at Startup (~1.2% of 128K)
853
+
854
+ | Component | Tokens | Loading |
855
+ |-----------|--------|---------|
856
+ | CLAUDE.md + rules | ~332 | Always |
857
+ | Agent descriptions (12) | ~371 | Always (metadata only) |
858
+ | Skill descriptions (13) | ~250 | Always (metadata only) |
859
+ | Settings.json | ~572 | Always |
860
+ | **Total** | **~1,500** | **1.2%** |
861
+
862
+ ### What Costs Zero
863
+
864
+ | Component | Why Zero Cost |
865
+ |-----------|--------------|
866
+ | Agent full bodies | Load in subagent context (separate window) |
867
+ | Forked skills (11/13) | Run in fork context (isolated) |
868
+ | Templates, profiles, docs | Never auto-loaded |
869
+ | File reads by agents | Done in subagent context |
870
+
871
+ ### What Accumulates (Danger)
872
+
873
+ | Component | Risk |
874
+ |-----------|------|
875
+ | File reads in main context | Stay in conversation history |
876
+ | Agent results returned to main | Each handoff adds content |
877
+ | Bash outputs | Especially long ones |
878
+ | Non-forked skill invocations | 2 skills: rollback, setup-smithery |
879
+
880
+ ### Enforcement
881
+
882
+ 1. **Between phases:** `/context-check` runs automatically
883
+ 2. **At 60%:** STOP and compact before continuing
884
+ 3. **At 75%:** Aggressive compact or session split
885
+ 4. **At 95%:** PreCompact hook saves state, auto-compaction fires, PostCompact restores state
886
+ 5. **Compact command:** `/compact "focus on TASK-001 Phase 6"`
887
+
888
+ ---
889
+
890
+ ## 13. Drift Detection & Sync
891
+
892
+ Over time, your codebase changes — new dependencies, new directories, team role changes. The sync system detects when the Claude Code environment goes stale.
893
+
894
+ ### Automatic Detection (Every Session)
895
+
896
+ On every session start, `drift-detector.js` checks:
897
+ - Manifest age (warns if >14 days since last sync)
898
+ - Agent count matches CLAUDE.md
899
+ - Dependency file hashes changed since last scan
900
+ - Orphan or missing hooks
901
+
902
+ ### Manual Sync
903
+
904
+ ```bash
905
+ /sync --check # Report only
906
+ /sync --fix # Auto-repair everything
907
+ /sync --fix --component agents # Fix only agents
908
+ /sync --full-rescan # Re-scan + regenerate from scratch
909
+ ```
910
+
911
+ ### 8 Drift Categories
912
+
913
+ | Category | What's Checked |
914
+ |----------|---------------|
915
+ | Agents | Files vs CLAUDE.md vs workflow vs manifest |
916
+ | Skills | Files vs manifest vs frontmatter compliance |
917
+ | Hooks | Files vs settings.json registration |
918
+ | Rules | Path globs vs actual directories |
919
+ | CLAUDE.md | Tech versions, commands, agent table, key paths |
920
+ | Settings | Hook refs, permission patterns |
921
+ | Tech Stack | Dependency files vs last scan hashes |
922
+ | Structure | Directories vs last scan |
923
+
924
+ ### Manifest
925
+
926
+ `.claude/manifest.json` tracks the state of every generated file. Updated after every `/sync --fix` or `/generate-environment`. Contains SHA-256 hashes of every agent, skill, hook, rule, and dependency file.
927
+
928
+ ---
929
+
930
+ ## 14. Error Recovery
931
+
932
+ ### Agent Hits maxTurns
933
+ - Counts as +1 loop iteration
934
+ - @team-lead re-invokes with narrowed scope or reassigns to different agent
935
+ - If repeatedly hitting limit: escalate to user
936
+
937
+ ### Tool Failure
938
+ - Logged by `tool-failure-tracker.js` to `.claude/reports/tool-failures.log`
939
+ - Agent should self-recover (retry with different approach)
940
+ - 3 consecutive failures: partial HANDOFF with `status: blocked`
941
+
942
+ ### Session Crash (Rate Limit, Auth, Server Error)
943
+ - `stop-failure-handler.js` preserves task state
944
+ - Recovery depends on error type:
945
+ - Rate limit: wait 60s, `claude --continue`
946
+ - Auth failure: re-authenticate
947
+ - Server error: retry with `claude --continue`
948
+ - Max tokens: resume to continue generation
949
+ - Loop state survives (persisted in task file on disk)
950
+
951
+ ### Deploy Failure
952
+ - Triaged before routing (not blind re-route to Phase 5):
953
+ - Config issue: @infra fixes, retry directly
954
+ - Code bug: hotfix fast-track
955
+ - Infra issue: @infra resolves, retry
956
+ - Unknown: `/rollback`, escalate to user
957
+
958
+ ### ON_HOLD Tasks
959
+ - Resume: `/workflow resume TASK-id`
960
+ - 7+ days: session-start warns
961
+ - 30+ days: session-start suggests cancel
962
+ - All loop counters preserved on resume
963
+
964
+ ### Cancelled Tasks
965
+ - Cleanup: close PR, delete branch, remove worktrees
966
+ - Task record preserved for history
967
+
968
+ ---
969
+
970
+ ## 15. Configuration Reference
971
+
972
+ ### settings.json
973
+
974
+ ```json
975
+ {
976
+ "permissions": {
977
+ "defaultMode": "default",
978
+ "allow": ["Bash(git status)", "Bash(git diff *)"],
979
+ "deny": ["Bash(rm -rf /)", "Bash(sudo *)"]
980
+ },
981
+ "env": {},
982
+ "hooks": { ... }
983
+ }
984
+ ```
985
+
986
+ - **permissions.defaultMode:** `default`, `acceptEdits`, `plan`, `auto`, `dontAsk`, `bypassPermissions`
987
+ - **permissions.allow:** Bash command patterns to auto-approve
988
+ - **permissions.deny:** Bash command patterns to always block
989
+ - **env:** Environment variables
990
+ - **hooks:** Event-to-script mappings (see [Section 9](#9-hooks--automation))
991
+
992
+ ### settings.local.json (gitignored)
993
+
994
+ ```json
995
+ {
996
+ "env": {
997
+ "DATABASE_URL": "postgres://localhost:5432/myapp",
998
+ "API_KEY": "sk-..."
999
+ }
1000
+ }
1001
+ ```
1002
+
1003
+ Machine-specific settings. Never committed to git.
1004
+
1005
+ ### CLAUDE.md
1006
+
1007
+ Project-level instructions that Claude reads on every session. Max 200 lines (150 recommended). Contains tech stack, commands, architecture, code style, git conventions, key paths.
1008
+
1009
+ ### Rules (.claude/rules/*.md)
1010
+
1011
+ Path-scoped instructions. Each rule has a `paths:` frontmatter that controls when it loads:
1012
+
1013
+ ```yaml
1014
+ ---
1015
+ paths:
1016
+ - "src/api/**/*.ts"
1017
+ ---
1018
+ # API rules load only when working in src/api/
1019
+ ```
1020
+
1021
+ ---
1022
+
1023
+ ## 16. File Structure
1024
+
1025
+ ```
1026
+ your-project/
1027
+ ├── CLAUDE.md # Project instructions
1028
+ ├── .claude/
1029
+ │ ├── manifest.json # Drift tracking state
1030
+ │ ├── settings.json # Permissions + hooks
1031
+ │ ├── settings.local.json # Personal env vars (gitignored)
1032
+ │ ├── agents/ # 12 agent definitions
1033
+ │ │ ├── team-lead.md # SDLC: orchestrator
1034
+ │ │ ├── architect.md # SDLC: design
1035
+ │ │ ├── product-owner.md # SDLC: business
1036
+ │ │ ├── qa-lead.md # SDLC: quality
1037
+ │ │ ├── explorer.md # Core: investigation
1038
+ │ │ ├── reviewer.md # Core: code review
1039
+ │ │ ├── security.md # Core: security
1040
+ │ │ ├── debugger.md # Core: bug fixing
1041
+ │ │ ├── tester.md # Core: test writing
1042
+ │ │ ├── api-builder.md # Dev: backend
1043
+ │ │ ├── frontend.md # Dev: UI
1044
+ │ │ └── infra.md # Dev: DevOps
1045
+ │ ├── skills/ # 13 slash commands
1046
+ │ │ ├── workflow/SKILL.md
1047
+ │ │ ├── scan-codebase/SKILL.md
1048
+ │ │ ├── generate-environment/SKILL.md
1049
+ │ │ ├── validate-setup/SKILL.md
1050
+ │ │ ├── setup-smithery/SKILL.md
1051
+ │ │ ├── task-tracker/SKILL.md
1052
+ │ │ ├── execution-report/SKILL.md
1053
+ │ │ ├── progress-report/SKILL.md
1054
+ │ │ ├── metrics/SKILL.md
1055
+ │ │ ├── impact-analysis/SKILL.md
1056
+ │ │ ├── context-check/SKILL.md
1057
+ │ │ ├── rollback/SKILL.md
1058
+ │ │ └── sync/SKILL.md
1059
+ │ ├── hooks/ # 12 automation scripts
1060
+ │ ├── rules/ # Path-scoped coding rules
1061
+ │ ├── docs/ # 9 reference documents
1062
+ │ ├── profiles/ # Role-based developer guides
1063
+ │ ├── templates/ # Code scaffolding templates
1064
+ │ ├── scripts/ # Verification scripts
1065
+ │ ├── tasks/ # Task records (gitignored)
1066
+ │ └── reports/ # Reports (gitignored)
1067
+ │ ├── daily/
1068
+ │ ├── weekly/
1069
+ │ └── executions/
1070
+ ```
1071
+
1072
+ ---
1073
+
1074
+ ## 17. Customization Guide
1075
+
1076
+ ### Adding a New Agent
1077
+
1078
+ 1. Create `.claude/agents/my-agent.md` with YAML frontmatter:
1079
+ ```yaml
1080
+ ---
1081
+ name: my-agent
1082
+ description: What this agent does. Use when [trigger condition].
1083
+ tools: Read, Edit, Write, Bash, Grep, Glob
1084
+ model: sonnet
1085
+ maxTurns: 30
1086
+ effort: high
1087
+ memory: project
1088
+ ---
1089
+ ```
1090
+
1091
+ 2. Add structured output format, HANDOFF block with execution_metrics, and Limitations section
1092
+ 3. Run `/sync --fix` to update CLAUDE.md agent table and workflow references
1093
+
1094
+ ### Adding a New Skill
1095
+
1096
+ 1. Create directory `.claude/skills/my-skill/`
1097
+ 2. Create `.claude/skills/my-skill/SKILL.md`:
1098
+ ```yaml
1099
+ ---
1100
+ name: my-skill
1101
+ description: What this skill does.
1102
+ user-invocable: true
1103
+ context: fork
1104
+ allowed-tools: Read, Grep, Glob, Bash
1105
+ argument-hint: "[argument description]"
1106
+ ---
1107
+ # My Skill: $ARGUMENTS
1108
+ Instructions here...
1109
+ ```
1110
+
1111
+ 3. Run `/sync --fix` to register in commands reference
1112
+
1113
+ ### Modifying the Workflow
1114
+
1115
+ Edit `.claude/skills/workflow/SKILL.md`. If you add a new phase:
1116
+ 1. Add the phase definition with entry/exit criteria
1117
+ 2. Map it to a task state in the Task State Machine section
1118
+ 3. Update the circuit breaker table if the phase has loops
1119
+ 4. Update `.claude/docs/flow-engine.md` with the detailed flow
1120
+
1121
+ ### Adding a New Hook
1122
+
1123
+ 1. Create `.claude/hooks/my-hook.js` (Node.js, use `process.stdin` for input, `process.exit(0)` to allow, `process.exit(2)` to block)
1124
+ 2. Register in `.claude/settings.json` under the appropriate event
1125
+ 3. Run `/sync --fix` to verify registration
1126
+
1127
+ ### Modifying Rules
1128
+
1129
+ Edit or create `.claude/rules/my-rule.md`. Use `paths:` frontmatter to scope when the rule loads:
1130
+ ```yaml
1131
+ ---
1132
+ paths:
1133
+ - "src/payments/**"
1134
+ - "src/billing/**"
1135
+ ---
1136
+ # Payment Rules
1137
+ - All amounts in cents (integer), never floating point
1138
+ - ...
1139
+ ```
1140
+
1141
+ ---
1142
+
1143
+ ## 18. Troubleshooting
1144
+
1145
+ ### "CLAUDE.md already exists"
1146
+ ```bash
1147
+ npx claude-code-scanner init --force
1148
+ ```
1149
+
1150
+ ### Verification fails
1151
+ ```bash
1152
+ npx claude-code-scanner verify
1153
+ # Read the FAIL messages and fix each one
1154
+ ```
1155
+
1156
+ ### "scan-results.md not found"
1157
+ Run `/scan-codebase` before `/generate-environment`.
1158
+
1159
+ ### Context keeps hitting 95%
1160
+ - Run `/context-check` to see what's consuming space
1161
+ - Use `/compact "focus on current task"` between phases
1162
+ - Avoid reading large files in main context — let agents read them
1163
+ - Consider starting a new session for remaining phases
1164
+
1165
+ ### Agent hits maxTurns repeatedly
1166
+ - The task may be too complex for one agent invocation
1167
+ - Break into smaller sub-tasks via @team-lead
1168
+ - Or increase maxTurns in the agent's .md file
1169
+
1170
+ ### Drift warnings on every session
1171
+ ```bash
1172
+ /sync --fix # Auto-repair stale files
1173
+ ```
1174
+ Or if too many warnings:
1175
+ ```bash
1176
+ /sync --full-rescan # Complete re-scan + regenerate
1177
+ ```
1178
+
1179
+ ### ON_HOLD task won't resume
1180
+ ```bash
1181
+ /workflow resume TASK-001
1182
+ ```
1183
+ If task state is corrupted, read the task file in `.claude/tasks/TASK-001.md` and manually set the status.
1184
+
1185
+ ### Tests fail after sync
1186
+ `/sync --fix` updated environment files but didn't change application code. If tests fail, the issue is likely in the code itself, not the environment. Run `@debugger` to investigate.
1187
+
1188
+ ### Hook blocks a legitimate operation
1189
+ Check the hook's logic:
1190
+ - `protect-files.js` blocks .env and lock files
1191
+ - `validate-bash.js` blocks dangerous commands
1192
+ If the operation is legitimate, temporarily remove the hook from `settings.json` or modify the hook's filter list.
1193
+
1194
+ ---
1195
+
1196
+ ## Summary
1197
+
1198
+ | Component | Count |
1199
+ |-----------|-------|
1200
+ | Agents | 12 (4 SDLC + 5 core + 3 dev) |
1201
+ | Skills | 13 (all with proper frontmatter) |
1202
+ | Hooks | 12 (covering 10 events) |
1203
+ | Docs | 9 (full protocol coverage) |
1204
+ | Profiles | 3 (backend, frontend, devops) |
1205
+ | Workflow Phases | 13 |
1206
+ | Loop Flows | 6 (all with circuit breakers) |
1207
+ | Task States | 16 (forward) + 3 (special) |
1208
+ | Validation Checks | 170+ |
1209
+
1210
+ Built for Claude Code. Cross-platform. Zero configuration after scan.