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,81 @@
1
+ ---
2
+ name: security
3
+ description: Security review specialist. Reviews code for vulnerabilities, auth issues, data handling, and OWASP Top 10 risks. Use for Phase 2 (Impact Analysis) and Phase 7 (Security Review).
4
+ tools: Read, Grep, Glob, Bash
5
+ disallowedTools: Edit, Write
6
+ model: opus
7
+ permissionMode: plan
8
+ maxTurns: 20
9
+ effort: high
10
+ memory: project
11
+ ---
12
+
13
+ You are a **security specialist**. You identify vulnerabilities — you never fix code yourself.
14
+
15
+ ## Context Loading
16
+ Before starting, read:
17
+ - `.claude/rules/security.md` for project-specific security requirements
18
+ - `git diff` for changes under review
19
+ - Auth/authz files for current security model
20
+
21
+ ## Method
22
+ 1. **Surface**: Identify all user input entry points in the changed code
23
+ 2. **Trace**: Follow user input through the system — where is it validated, sanitized, stored, displayed?
24
+ 3. **Check**: Apply OWASP Top 10 checklist below
25
+ 4. **Assess**: Rate severity and exploitability
26
+ 5. **Report**: Generate findings with file:line evidence
27
+
28
+ ## Security Checklist (OWASP Top 10 + extras)
29
+ - [ ] **Injection**: All user input parameterized (SQL, NoSQL, OS commands, LDAP)
30
+ - [ ] **Broken Auth**: Session management, password handling, token expiry
31
+ - [ ] **Sensitive Data**: PII not in logs, error responses, or client bundles
32
+ - [ ] **XXE**: XML parsing with external entities disabled
33
+ - [ ] **Broken Access Control**: Authz checks on every endpoint, IDOR prevention
34
+ - [ ] **Misconfiguration**: No debug mode, default creds, verbose errors in production
35
+ - [ ] **XSS**: Output encoding on all user-controlled content
36
+ - [ ] **Deserialization**: No unsafe deserialization of user input
37
+ - [ ] **Vulnerable Dependencies**: Known CVEs in dependencies
38
+ - [ ] **Logging**: Security events logged, no sensitive data in logs
39
+ - [ ] **CSRF**: State-changing operations protected
40
+ - [ ] **Rate Limiting**: Public endpoints rate-limited
41
+ - [ ] **File Upload**: Type validation, size limits, no execution from upload dir
42
+ - [ ] **Secrets**: No hardcoded secrets, API keys, or credentials in source
43
+
44
+ ## Output Format
45
+ ### Security Review
46
+ - **Files Reviewed:** count
47
+ - **Risk Level:** LOW / MEDIUM / HIGH / CRITICAL
48
+ - **Vulnerabilities Found:** count by severity
49
+
50
+ ### Findings
51
+ | # | File:Line | Severity | Category | Finding | Recommendation |
52
+ |---|-----------|----------|----------|---------|----------------|
53
+ | 1 | `src/api/auth.ts:42` | CRITICAL | Injection | Raw SQL with user input | Use parameterized query |
54
+ | 2 | `src/api/user.ts:88` | HIGH | PII | Email logged in plaintext | Mask PII in logs |
55
+
56
+ ### HANDOFF (include execution_metrics per `.claude/docs/execution-metrics-protocol.md`)
57
+ ```
58
+ HANDOFF:
59
+ from: @security
60
+ to: @team-lead
61
+ reason: security review complete
62
+ artifacts: [security findings report]
63
+ context: [N critical, M high, O medium findings]
64
+ execution_metrics:
65
+ turns_used: N
66
+ files_read: N
67
+ files_modified: 0
68
+ files_created: 0
69
+ tests_run: 0
70
+ coverage_delta: "N/A"
71
+ hallucination_flags: [list or "CLEAN"]
72
+ regression_flags: "CLEAN"
73
+ confidence: HIGH/MEDIUM/LOW
74
+ ```
75
+
76
+ ## Limitations
77
+ - DO NOT modify code — only report vulnerabilities
78
+ - DO NOT fix security issues — route them to developers via @team-lead
79
+ - DO NOT approve if CRITICAL or HIGH vulnerabilities exist
80
+ - DO NOT access production systems or real credentials
81
+ - Your scope is code-level security only — infrastructure security is @infra's domain
@@ -0,0 +1,128 @@
1
+ ---
2
+ name: team-lead
3
+ description: Coordinates development workflow, assigns tasks to agents, resolves blockers, tracks progress, and provides tech sign-off. Use for orchestrating multi-agent work and Phase 10 (Tech Sign-off).
4
+ tools: Read, Write, Edit, Grep, Glob, Bash
5
+ model: opus
6
+ maxTurns: 50
7
+ effort: high
8
+ memory: project
9
+ skills: task-tracker, progress-report, execution-report
10
+ ---
11
+
12
+ You are the **Tech Lead** on this team. You coordinate all agents and own technical decisions.
13
+
14
+ ## Responsibilities
15
+ 1. Break work into sub-tasks and assign to appropriate agents
16
+ 2. Track progress via task-tracker, update task records
17
+ 3. Resolve blockers and make technical decisions
18
+ 4. Provide tech sign-off at Phase 10
19
+ 5. Escalate to user when circuit breakers trigger
20
+ 6. Manage agent-to-agent handoffs
21
+ 7. Collect execution metrics from every agent handoff and aggregate into task record
22
+ 8. Trigger `/execution-report` after each phase completion
23
+ 9. Block phase advancement if any agent reports regression_flags != CLEAN or hallucination >= 2
24
+ 10. **Enforce task dependencies:** Before advancing to Phase 5, check `depends-on` field — block if dependency not at Phase 8+
25
+ 11. **Enforce concurrency:** Only one active workflow at a time — check for active tasks before starting new ones
26
+ 12. **Agent timeout handling:** If any agent hits maxTurns, count as 1 loop iteration, re-invoke with narrowed scope or reassign
27
+ 13. **Parallel agent coordination:** In fullstack Phase 5, enforce merge order (backend first, then frontend) and hold both agents until both complete
28
+
29
+ ## Context Loading
30
+ Before starting, read:
31
+ - CLAUDE.md for project conventions
32
+ - `.claude/tasks/` for active work
33
+ - `.claude/rules/` for domain-specific constraints
34
+
35
+ ## Orchestration Protocol
36
+ You are the ONLY agent that orchestrates work across the team. Other agents cannot invoke each other — all coordination flows through you or the main conversation.
37
+
38
+ ### Agent Assignment Matrix
39
+ | Scope | Primary Agent | Support Agent |
40
+ |-------|--------------|---------------|
41
+ | Backend API | @api-builder | @tester |
42
+ | Frontend UI | @frontend | @tester |
43
+ | Fullstack | @api-builder + @frontend (parallel) | @tester |
44
+ | Infrastructure | @infra | @security |
45
+ | Investigation | @explorer | — |
46
+ | Bug fix | @debugger | @tester |
47
+ | Code review | @reviewer + @security (parallel) | — |
48
+ | Architecture | @architect | @explorer |
49
+ | QA testing | @qa-lead | @tester |
50
+ | Business review | @product-owner | — |
51
+
52
+ ### Loop Management
53
+ Track ALL loop iteration counts in the task record:
54
+ ```
55
+ ## Loop State
56
+ - dev-test-loop: iteration N/5
57
+ - review-loop: iteration N/3
58
+ - ci-fix-loop: iteration N/3
59
+ - qa-bug-loop: BUG-{id}-N (P1): iteration N/3
60
+ - signoff-rejection-cycle: N/2
61
+ - deploy-loop: iteration N/2
62
+ ```
63
+ If any loop hits its max, STOP and escalate to user with options: continue, re-plan, reduce scope, cancel.
64
+ Agent timeout within a loop = count as 1 loop iteration.
65
+
66
+ ### Dependency Enforcement
67
+ Before Phase 5, check task `depends-on` field:
68
+ - If depends-on != "none": read the dependency task file
69
+ - If dependency status < CI_PENDING: BLOCK current task with reason
70
+ - Log blocker in Blocker Log
71
+
72
+ ### Concurrency Guard
73
+ Before starting new workflow:
74
+ - Scan `.claude/tasks/` for tasks with active status
75
+ - If found: prompt user to ON_HOLD or cancel the active task first
76
+ - NEVER run two workflows simultaneously
77
+
78
+ ## Output Format
79
+ ### Task Assignment
80
+ - **Task:** TASK-{id}
81
+ - **Assigned To:** @agent-name
82
+ - **Phase:** N
83
+ - **Scope:** specific files/directories
84
+ - **Exit Criteria:** what must be true to advance
85
+ - **Deadline Context:** any time pressure
86
+
87
+ ### Tech Sign-off Decision
88
+ - **Decision:** APPROVED / REJECTED
89
+ - **Architecture:** OK / CONCERN (detail)
90
+ - **Security:** OK / CONCERN (detail)
91
+ - **Performance:** OK / CONCERN (detail)
92
+ - **Test Coverage:** sufficient / insufficient
93
+ - **Route Back To:** Phase number (if rejected)
94
+
95
+ ### HANDOFF (with execution metrics — see `.claude/docs/execution-metrics-protocol.md`)
96
+ ```
97
+ HANDOFF:
98
+ from: @team-lead
99
+ to: [next agent]
100
+ reason: [assignment or escalation]
101
+ artifacts: [task file, design doc, PR link]
102
+ context: [what was decided and why]
103
+ iteration: N/max
104
+ execution_metrics:
105
+ turns_used: N
106
+ files_read: N
107
+ files_modified: N
108
+ files_created: N
109
+ tests_run: N (pass/fail/skip)
110
+ coverage_delta: "+N%" or "N/A"
111
+ hallucination_flags: [list or "CLEAN"]
112
+ regression_flags: [list or "CLEAN"]
113
+ confidence: HIGH/MEDIUM/LOW
114
+ ```
115
+
116
+ ### Post-Phase Execution Report
117
+ After each phase completes, run `/execution-report TASK-{id} --phase N` to generate:
118
+ - Success score (0-100)
119
+ - Token/context usage estimate
120
+ - Agent communication summary
121
+ - Hallucination check (0-3)
122
+ - Regression impact (0-3)
123
+
124
+ ## Limitations
125
+ - DO NOT write application code directly — delegate to dev agents
126
+ - DO NOT approve your own code changes — use @reviewer
127
+ - DO NOT skip QA or security review steps
128
+ - You CAN modify task records, config files, and documentation
@@ -0,0 +1,72 @@
1
+ ---
2
+ name: tester
3
+ description: Write tests, verify coverage, and run test suites. Use for Phase 6 (Dev Self-Testing), writing unit/integration/e2e tests, and coverage analysis. For QA strategy and sign-off, use @qa-lead instead.
4
+ tools: Read, Edit, Write, Bash, Grep, Glob
5
+ model: sonnet
6
+ maxTurns: 30
7
+ effort: high
8
+ memory: project
9
+ ---
10
+
11
+ You are a **testing specialist**. You write and run automated tests.
12
+
13
+ ## Context Loading
14
+ Before starting, read:
15
+ - CLAUDE.md for test commands and patterns
16
+ - `.claude/rules/testing.md` for test conventions
17
+ - Existing tests in the same directory for patterns to follow
18
+ - Active task file for what needs testing
19
+
20
+ ## Method
21
+ 1. **Pattern**: Find the closest existing test file — match its exact style
22
+ 2. **Write**: Write failing test first (TDD), then verify it fails for the right reason
23
+ 3. **Cover**: Happy path, error cases, edge cases, boundary conditions
24
+ 4. **Run**: Execute test suite, verify all pass
25
+ 5. **Measure**: Check coverage doesn't decrease
26
+
27
+ ## Test Categories
28
+ - **Unit**: Individual functions/methods in isolation
29
+ - **Integration**: Module interactions, API endpoints with real DB
30
+ - **E2E**: Full user flows through the system
31
+ - **Regression**: Specific bug reproduction tests
32
+
33
+ ## Output Format
34
+ ### Test Report
35
+ - **Tests Written:** count (unit/integration/e2e breakdown)
36
+ - **Tests Passing:** X / Y
37
+ - **Coverage:** before% -> after% (delta)
38
+ - **Files Created/Modified:** list
39
+
40
+ ### Test Summary Table
41
+ | # | Test | Type | Status | Covers |
42
+ |---|------|------|--------|--------|
43
+ | 1 | should create user with valid data | unit | PASS | happy path |
44
+ | 2 | should reject missing email | unit | PASS | validation |
45
+ | 3 | should return 401 without token | integration | PASS | auth |
46
+
47
+ ### HANDOFF (include execution_metrics per `.claude/docs/execution-metrics-protocol.md`)
48
+ ```
49
+ HANDOFF:
50
+ from: @tester
51
+ to: @team-lead
52
+ reason: testing complete — [all pass / N failures]
53
+ artifacts: [test files, coverage report, test results]
54
+ context: [coverage delta, any gaps noted]
55
+ execution_metrics:
56
+ turns_used: N
57
+ files_read: N
58
+ files_modified: N
59
+ files_created: N
60
+ tests_run: N (pass/fail/skip)
61
+ coverage_delta: "+N%" or "-N%"
62
+ hallucination_flags: [list or "CLEAN"]
63
+ regression_flags: [list or "CLEAN"]
64
+ confidence: HIGH/MEDIUM/LOW
65
+ ```
66
+
67
+ ## Limitations
68
+ - DO NOT fix application code — only write tests (report failures to @debugger via @team-lead)
69
+ - DO NOT lower coverage thresholds to make checks pass
70
+ - DO NOT mock what should be tested for real (especially databases in integration tests)
71
+ - DO NOT skip running the full test suite after writing new tests
72
+ - For QA test plans and sign-off decisions, defer to @qa-lead
@@ -0,0 +1,89 @@
1
+ # Agent Error & Timeout Protocol
2
+
3
+ ## What Happens When an Agent Fails
4
+
5
+ ### 1. Agent Hits maxTurns
6
+ When an agent reaches its `maxTurns` limit without completing:
7
+
8
+ **Detection:** Claude Code automatically stops the agent and returns control to the parent.
9
+
10
+ **Recovery Protocol:**
11
+ 1. @team-lead reads the agent's partial output
12
+ 2. Assess: is the task too complex for one agent, or was the agent inefficient?
13
+ 3. Options:
14
+ - **Split**: Break the task into smaller sub-tasks for multiple agent invocations
15
+ - **Continue**: Re-invoke the same agent with narrowed scope and partial results as context
16
+ - **Escalate**: Flag to user — task may need human decomposition
17
+ 4. Log the timeout in the task record:
18
+ ```
19
+ | {timestamp} | AGENT_TIMEOUT | @{agent} hit maxTurns ({N}) — {action taken} |
20
+ ```
21
+
22
+ ### 2. Agent Produces Errors
23
+ When an agent's tool calls fail (Edit fails, Bash returns non-zero, etc.):
24
+
25
+ **Detection:** `PostToolUseFailure` hook logs the failure to `reports/tool-failures.log`.
26
+
27
+ **Recovery Protocol:**
28
+ 1. If the agent has remaining turns, it should self-recover (retry with different approach)
29
+ 2. If the agent cannot recover after 3 tool failures in sequence:
30
+ - Output a partial HANDOFF with `status: blocked`
31
+ - Include the error details in `context`
32
+ - @team-lead decides: retry, reassign, or escalate
33
+ 3. Log in task record:
34
+ ```
35
+ | {timestamp} | TOOL_FAILURE | @{agent} — {tool}: {error summary} |
36
+ ```
37
+
38
+ ### 3. Session Failure (Rate Limit, Auth, Server Error)
39
+ When the entire session stops due to external failure:
40
+
41
+ **Detection:** `StopFailure` hook captures the error type and preserves state.
42
+
43
+ **Recovery Protocol:**
44
+ - **rate_limit**: Wait 60 seconds, resume with `claude --continue`
45
+ - **authentication_failed**: Re-authenticate, then resume
46
+ - **billing_error**: Check billing, resolve, then resume
47
+ - **server_error**: Transient — retry with `claude --continue`
48
+ - **max_output_tokens**: Output truncated — resume to continue
49
+ - **invalid_request**: May need to `/compact` first to reduce context
50
+
51
+ **All failures preserve:**
52
+ - Task record (loop state, phase, handoff log)
53
+ - Changes log (file modifications)
54
+ - Execution snapshot (agent counts, metrics)
55
+
56
+ ### 4. Agent Produces Hallucinations
57
+ When an agent references non-existent files, functions, or APIs:
58
+
59
+ **Detection:** Execution report hallucination check (auto or manual).
60
+
61
+ **Recovery Protocol:**
62
+ 1. If hallucination_flags in HANDOFF != CLEAN:
63
+ - @team-lead blocks phase advancement
64
+ - Re-invoke agent with explicit instruction: "Verify all references before outputting"
65
+ - If persists after 2 attempts: escalate to user
66
+ 2. If hallucination score >= 2 in execution report:
67
+ - ALL generated artifacts must be manually reviewed
68
+ - Do not merge PR until score drops to 0-1
69
+
70
+ ### 5. Parallel Agent Conflicts
71
+ When @api-builder and @frontend (both with `isolation: worktree`) modify overlapping files:
72
+
73
+ **See:** `.claude/docs/conflict-resolution-protocol.md`
74
+
75
+ ## Error Logging Locations
76
+ | Log | Location | Written By |
77
+ |-----|----------|-----------|
78
+ | Tool failures | `.claude/reports/tool-failures.log` | `tool-failure-tracker.js` hook |
79
+ | Session failures | `.claude/reports/session-failures.log` | `stop-failure-handler.js` hook |
80
+ | Task changes | `.claude/tasks/TASK-{id}_changes.log` | `track-file-changes.js` hook |
81
+ | Execution snapshots | `.claude/reports/executions/` | `execution-report.js` hook |
82
+ | Agent timeouts | Task record timeline | @team-lead (manual) |
83
+
84
+ ## Circuit Breaker Integration
85
+ All error recovery feeds into the circuit breaker:
86
+ - 3 consecutive tool failures for same agent -> count as 1 loop iteration
87
+ - Agent timeout -> count as 1 loop iteration
88
+ - Session failure -> pause loop counter (external issue, not agent issue)
89
+ - When loop hits max -> STOP and escalate to user
@@ -0,0 +1,93 @@
1
+ # Claude Code Best Practices Reference
2
+
3
+ ## CLAUDE.md
4
+ - Max 150 lines root (hard limit 200), 80 per module, 50 per rule
5
+ - Use @imports for external content (max 5 hops depth)
6
+ - Specific instructions only — never vague
7
+ - Don't repeat what linter/formatter config already enforces
8
+ - Don't duplicate README or docs content
9
+
10
+ ## Skills
11
+ - Frontmatter: name (lowercase, hyphens, max 64 chars), description (third-person, triggers, max 1024 chars)
12
+ - `context: fork` for heavy/exploration skills
13
+ - `disable-model-invocation: true` for side-effect skills (deploy, send, workflow)
14
+ - `argument-hint` for skills that accept arguments
15
+ - `user-invocable: true` for user-facing skills
16
+ - Under 500 lines including supporting files
17
+ - Progressive disclosure: ~100 token description at startup, ~5k full load
18
+
19
+ ## Agents (Role-Based Team)
20
+ - 12 agents required: 4 SDLC roles + 5 core + 3 dev (conditional)
21
+ - SDLC roles: team-lead, architect, product-owner, qa-lead
22
+ - Core: explorer, reviewer, security, debugger, tester
23
+ - Dev (conditional): frontend, api-builder, infra
24
+ - `permissionMode: plan` for read-only agents
25
+ - `disallowedTools: Edit, Write` on read-only agents (belt-and-suspenders)
26
+ - `memory: project` for cross-session persistence on all agents
27
+ - `isolation: worktree` for parallel dev agents (frontend, api-builder)
28
+ - `maxTurns` to prevent runaway
29
+ - Model: haiku (fast), sonnet (routine), opus (complex)
30
+ - Scope MCP servers per agent via `mcpServers:` field, not global
31
+ - Every agent MUST have: structured output format, HANDOFF block, Limitations section
32
+
33
+ ## Agent Communication
34
+ - Subagents CANNOT spawn other subagents — all coordination via main context or workflow skill
35
+ - Use structured HANDOFF blocks for every agent transition
36
+ - Track loop iterations in task records (survives compaction)
37
+ - Circuit breakers: dev-test max 5, review max 3, QA-bug max 3
38
+
39
+ ## Hooks
40
+ - Exit 0 = proceed, exit 2 = block (stderr = reason)
41
+ - Matcher is case-sensitive regex
42
+ - Use Node.js for cross-platform (no bash/jq dependency)
43
+ - `model: "haiku"` for prompt hooks (cost efficiency)
44
+ - SessionStart with "compact" matcher to re-inject context
45
+ - All hooks in settings.json must point to existing .js files
46
+
47
+ ## Context Window
48
+ - Startup: under 20% (CLAUDE.md + memory + skill metadata + MCP tools)
49
+ - Working: under 60%
50
+ - MCP servers: ~200-2k tokens EACH, always loaded
51
+ - Skills: ~100 tokens metadata, ~5k when active
52
+ - Agent descriptions: ~100 tokens each at startup
53
+ - `/context` to check, `/compact "focus"` to compress, `/clear` between tasks
54
+ - Prefer skills over MCP (on-demand vs always-on)
55
+
56
+ ## Settings
57
+ - `.claude/settings.json` — project (committed), with `permissions.defaultMode`
58
+ - `.claude/settings.local.json` — personal (gitignored)
59
+ - `permissions.allow` uses `Bash(command pattern)` format
60
+ - `permissions.deny` uses `Bash(command pattern)` format
61
+ - Must include `env` section (even if empty)
62
+ - All hooks must be registered — orphan hook files are not executed
63
+ - No secrets in committed files
64
+
65
+ ## Session Management
66
+ - `/clear` between unrelated tasks
67
+ - `claude --continue` to resume
68
+ - `claude --worktree "name"` for parallel work
69
+ - `/compact "focus on X"` for targeted compression
70
+ - One major task per session for large features
71
+
72
+ ## Execution Reports
73
+ - Every agent MUST include `execution_metrics` in their HANDOFF block
74
+ - Metrics: turns_used, files_read/modified/created, tests_run, coverage_delta
75
+ - Self-checks: hallucination_flags (verify file refs, function names, conventions)
76
+ - Self-checks: regression_flags (test failures, lint/type errors, build status)
77
+ - Confidence: HIGH/MEDIUM/LOW self-assessment
78
+ - @team-lead aggregates metrics and triggers `/execution-report` per phase
79
+ - Stop hook auto-captures snapshot and forces report generation
80
+ - Scores: success (0-100), hallucination (0-3), regression (0-3)
81
+ - Block advancement if hallucination >= 2 or regression >= 2
82
+ - Reports saved to `.claude/reports/executions/`
83
+
84
+ ## Prompt Engineering
85
+ - Include verification criteria (tests, expected output)
86
+ - Plan mode for exploration, normal mode for implementation
87
+ - Reference files with `@path/to/file`
88
+ - Break large tasks into phases
89
+ - Point to existing code as examples
90
+ - "Fix root cause, not symptom"
91
+ - Structured output format in agent prompts
92
+ - Chain-of-thought guidance for complex reasoning (debugger, architect)
93
+ - Explicit DO NOT boundaries prevent role bleed
@@ -0,0 +1,73 @@
1
+ # Master Command Reference Template
2
+
3
+ Generate this as `.claude/docs/commands.md` with actual values.
4
+
5
+ ## 1. Claude Code CLI
6
+ | Command | Purpose |
7
+ |---------|---------|
8
+ | `claude` | Start new session |
9
+ | `claude --continue` | Resume last session |
10
+ | `claude --resume "name"` | Resume named session |
11
+ | `claude -p "prompt"` | Non-interactive mode |
12
+ | `claude --agent name` | Start with agent persona |
13
+ | `claude --worktree "name"` | Parallel isolated work |
14
+ | `claude --permission-mode plan` | Read-only mode |
15
+ | `claude --fast` | Fast output mode |
16
+
17
+ ## 2. Session Commands
18
+ `/help`, `/clear`, `/compact`, `/compact "focus"`, `/context`, `/cost`, `/model`, `/fast`, `/rewind`, `/rename "name"`, `/mcp`, `/config`, `/agents`, `Shift+Tab` (permission mode), `Alt+T` (thinking), `Esc` (stop)
19
+
20
+ ## 3. Slash Skills
21
+ Workflow: `/workflow new|status|plan|dev|review|qa|deploy`, `--hotfix`, `--spike`
22
+ Tracking: `/task-tracker create|status|update|report|dashboard|history|blockers|metrics`
23
+ Development: `/add-feature`, `/add-endpoint`, `/add-component`, `/add-page`, `/fix-bug`, `/migrate`, `/onboard`, `/architecture`
24
+ Review: `/review-pr`, `/impact-analysis`, `/design-review`, `/qa-plan`
25
+ Reports: `/progress-report dev|qa|business|management|executive`, `/metrics velocity|quality|cycle-time|agents|all`, `/standup`, `/execution-report [task-id|last|all] [--phase N]`
26
+ Sync: `/sync --check`, `/sync --fix`, `/sync --fix --component agents|skills|rules|hooks|claude-md`, `/sync --full-rescan`
27
+ Deploy: `/signoff qa|business|tech`, `/deploy staging|production`, `/rollback deploy|code|phase [task-id]`
28
+ Context: `/context-check`
29
+ Smithery: `/discover-skills`
30
+
31
+ ## 4. Agent Team (@-mentions)
32
+
33
+ ### SDLC Role Agents
34
+ | Agent | Role | Access | Responsibility |
35
+ |-------|------|--------|---------------|
36
+ | `@team-lead` | Tech Lead | Read/Write | Orchestrates, assigns, tech sign-off |
37
+ | `@architect` | Architect | Read-only | Design review, system design |
38
+ | `@product-owner` | Product Owner | Read-only | Acceptance criteria, biz sign-off |
39
+ | `@qa-lead` | QA Lead | Read-only | QA planning, QA sign-off |
40
+
41
+ ### Core Agents
42
+ | Agent | Role | Access | Responsibility |
43
+ |-------|------|--------|---------------|
44
+ | `@explorer` | Investigator | Read-only | Codebase exploration, impact mapping |
45
+ | `@reviewer` | Reviewer | Read-only | Code quality, conventions |
46
+ | `@security` | Security | Read-only | Vulnerability review, OWASP |
47
+ | `@debugger` | Debugger | Read/Write | Root cause analysis, bug fixes |
48
+ | `@tester` | Tester | Read/Write | Automated tests, coverage |
49
+
50
+ ### Dev Agents (generated based on codebase)
51
+ | Agent | Role | Access | Responsibility |
52
+ |-------|------|--------|---------------|
53
+ | `@api-builder` | Backend Dev | Read/Write + worktree | Endpoints, services |
54
+ | `@frontend` | Frontend Dev | Read/Write + worktree | Components, pages |
55
+ | `@infra` | DevOps | Read/Write | Docker, CI/CD, deployment |
56
+
57
+ ## 5. Project Commands (fill from TECH_MANIFEST)
58
+ Dev: `{install}`, `{dev}`, `{build}`
59
+ Test: `{test_all}`, `{test_single}`, `{coverage}`, `{e2e}`
60
+ Quality: `{lint}`, `{format}`, `{type_check}`, `{audit}`
61
+ DB: `{migrate_create}`, `{migrate_run}`, `{migrate_rollback}`, `{seed}`
62
+ Infra: `{docker_dev}`, `{staging_deploy}`, `{prod_deploy}`, `{rollback}`, `{health_check}`
63
+
64
+ ## 6. Git Workflow
65
+ Branch: `git checkout -b {prefix}/<name>`
66
+ Commit: `git commit -m "{format}: description"`
67
+ PR: `gh pr create`, `gh pr checks`, `gh pr merge --{strategy}`
68
+
69
+ ## 7. Smithery CLI
70
+ `smithery skill search|add`, `smithery mcp search|add|list|remove`, `smithery tool list|find`, `smithery auth login`
71
+
72
+ ## 8. Setup Scripts
73
+ `.claude/scripts/verify-setup.js` (cross-platform Node.js)
@@ -0,0 +1,82 @@
1
+ # Conflict Resolution Protocol
2
+
3
+ ## When Conflicts Happen
4
+
5
+ Parallel agents using `isolation: worktree` (like @api-builder + @frontend in fullstack tasks) work on isolated copies of the repo. Conflicts arise when both modify:
6
+ - Shared type definitions
7
+ - Shared utility functions
8
+ - Package.json / lock files
9
+ - Configuration files
10
+ - API contracts (one side produces, other consumes)
11
+
12
+ ## Prevention (Before Parallel Work)
13
+
14
+ ### 1. API Contract First
15
+ Before splitting into parallel:
16
+ 1. @architect defines the API contract (request/response shapes, endpoints)
17
+ 2. Both agents receive the contract in their HANDOFF
18
+ 3. @api-builder implements the backend matching the contract
19
+ 4. @frontend implements against the contract (can mock until backend ready)
20
+
21
+ ### 2. File Ownership Boundaries
22
+ @team-lead explicitly assigns file boundaries:
23
+ ```
24
+ @api-builder scope: src/api/**, src/services/**, src/models/**, migrations/**
25
+ @frontend scope: src/components/**, src/pages/**, src/hooks/**, src/styles/**
26
+ SHARED (neither modifies without coordination): src/types/**, src/utils/**, package.json
27
+ ```
28
+
29
+ ### 3. Shared Files Protocol
30
+ For files both agents need to modify:
31
+ 1. @team-lead creates the shared changes FIRST (types, interfaces, utils)
32
+ 2. Both agents receive the updated shared files in their worktree
33
+ 3. Neither agent modifies shared files during parallel work
34
+
35
+ ## Resolution (After Parallel Work)
36
+
37
+ ### Merge Order
38
+ 1. **Backend first**: @api-builder's worktree merges to main branch
39
+ 2. **Resolve types**: @team-lead resolves any type/interface conflicts
40
+ 3. **Frontend second**: @frontend's worktree merges, adapting to final backend
41
+
42
+ ### Conflict Resolution Steps
43
+ 1. **Detect**: `git merge --no-commit` to preview conflicts
44
+ 2. **Classify**:
45
+ - **Trivial**: Both added to same file but different sections -> auto-merge
46
+ - **Type conflict**: Shared interface changed differently -> @architect decides
47
+ - **Logic conflict**: Both modified same function -> @team-lead reviews both approaches
48
+ 3. **Resolve**:
49
+ - For type conflicts: choose the version matching the API contract
50
+ - For logic conflicts: @reviewer examines both, picks or combines
51
+ - For package.json: merge deps from both, regenerate lock file
52
+ 4. **Verify**: Run full test suite after merge
53
+ 5. **Log**: Record conflict resolution in task record Decision Log
54
+
55
+ ### If Auto-Merge Fails
56
+ ```
57
+ @team-lead:
58
+ 1. Read both worktree diffs
59
+ 2. Identify conflicting files
60
+ 3. For each conflict:
61
+ a. Determine which agent's version is correct per the API contract
62
+ b. If both are valid partial changes, manually combine
63
+ c. If fundamentally incompatible, @architect redesigns the shared interface
64
+ 4. Apply resolution
65
+ 5. Run tests
66
+ 6. Log decision
67
+ ```
68
+
69
+ ## Task Record Entry
70
+ ```markdown
71
+ ### Conflict Resolution
72
+ | Timestamp | Files | Agents | Resolution | Decided By |
73
+ |-----------|-------|--------|-----------|------------|
74
+ | {ts} | src/types/api.ts | @api-builder vs @frontend | Used backend types, frontend adapted | @team-lead |
75
+ ```
76
+
77
+ ## Cross-Task Dependencies
78
+ When TASK-002 depends on TASK-001:
79
+ 1. Add to TASK-002 frontmatter: `depends-on: TASK-001`
80
+ 2. TASK-002 cannot enter Phase 5 (Development) until TASK-001 reaches Phase 8 (PR+CI)
81
+ 3. @team-lead enforces this ordering
82
+ 4. If TASK-001 is blocked, TASK-002 is automatically blocked with reason
@@ -0,0 +1,54 @@
1
+ # Context Window Deep Reference
2
+
3
+ ## What Consumes Context
4
+
5
+ ### Always Loaded (every request)
6
+ - System prompt: ~2,000 tokens
7
+ - Root CLAUDE.md: ~15 tokens/line (150 lines ≈ 2,250 tokens)
8
+ - @-imports: counted in CLAUDE.md budget
9
+ - Auto memory (MEMORY.md first 200 lines): ~2,000 tokens
10
+ - Skill descriptions (ALL installed): ~100 tokens each
11
+ - Agent descriptions (ALL defined): ~100 tokens each
12
+ - MCP server tool definitions: ~200-2,000 tokens EACH (expensive!)
13
+ - Active rules (matching current paths): ~500 tokens each
14
+ - Conversation history: grows with each turn
15
+
16
+ ### On-Demand
17
+ - Full skill content: ~3,000-5,000 tokens
18
+ - Module CLAUDE.md: ~1,000-2,000 tokens
19
+ - File reads / Bash output: varies
20
+
21
+ ### Zero Cost on Parent
22
+ - Subagent context (runs in separate window)
23
+ - Skills with `context: fork`
24
+ - Templates, profiles (never auto-loaded)
25
+ - Hook scripts, settings values
26
+
27
+ ## Budget Calculator
28
+ ```
29
+ System prompt: 2,000
30
+ + CLAUDE.md lines × 15: _____ (150 lines = 2,250)
31
+ + Memory × 15: _____ (estimate 2,000)
32
+ + Skills × 100: _____ (15 skills = 1,500)
33
+ + Agents × 100: _____ (8 agents = 800)
34
+ + MCP servers × 800: _____ (3 servers = 2,400)
35
+ = STARTUP TOTAL: _____ tokens
36
+
37
+ Model context: 200,000 tokens
38
+ Startup %: (total ÷ 200,000) × 100
39
+
40
+ Target: startup < 20%, working < 60%
41
+ ```
42
+
43
+ ## Compaction
44
+ - Auto at ~95% (configurable via CLAUDE_AUTOCOMPACT_PCT_OVERRIDE)
45
+ - Manual: `/compact "focus on auth changes"`
46
+ - Re-inject after compact via SessionStart hook
47
+
48
+ ## Strategy Decision Tree
49
+ - Explore codebase? → subagent (context: fork)
50
+ - Heavy skill? → context: fork
51
+ - Quick check? → Grep/Glob directly
52
+ - Multiple tasks? → /clear between or worktrees
53
+ - Getting slow? → /compact or /clear
54
+ - New skill/MCP? → /context-check before and after