sinapse-ai 7.0.5 → 7.2.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 (93) hide show
  1. package/.sinapse-ai/core-config.yaml +2 -26
  2. package/.sinapse-ai/data/entity-registry.yaml +742 -917
  3. package/.sinapse-ai/data/registry-update-log.jsonl +22 -0
  4. package/.sinapse-ai/infrastructure/scripts/ide-sync/index.js +1 -49
  5. package/.sinapse-ai/infrastructure/scripts/validate-parity.js +0 -7
  6. package/.sinapse-ai/install-manifest.yaml +11 -43
  7. package/README.en.md +6 -11
  8. package/README.md +6 -11
  9. package/bin/cli.js +116 -75
  10. package/bin/modules/env-config.js +1 -2
  11. package/bin/sinapse-init.js +23 -188
  12. package/docs/ide-integration.md +22 -263
  13. package/docs/installation/README.md +4 -6
  14. package/docs/installation/faq.md +10 -33
  15. package/docs/installation/linux.md +0 -23
  16. package/docs/installation/macos.md +0 -10
  17. package/docs/installation/troubleshooting.md +5 -9
  18. package/docs/installation/v4-quick-start.md +1 -1
  19. package/docs/installation/windows.md +0 -18
  20. package/package.json +2 -9
  21. package/packages/installer/src/config/ide-configs.js +3 -49
  22. package/squads/claude-code-mastery/CHANGELOG.md +22 -0
  23. package/squads/claude-code-mastery/README.md +146 -0
  24. package/squads/claude-code-mastery/agents/claude-mastery-chief.md +554 -0
  25. package/squads/claude-code-mastery/agents/config-engineer.md +865 -0
  26. package/squads/claude-code-mastery/agents/hooks-architect.md +1013 -0
  27. package/squads/claude-code-mastery/agents/mcp-integrator.md +791 -0
  28. package/squads/claude-code-mastery/agents/project-integrator.md +1196 -0
  29. package/squads/claude-code-mastery/agents/roadmap-sentinel.md +931 -0
  30. package/squads/claude-code-mastery/agents/skill-craftsman.md +1250 -0
  31. package/squads/claude-code-mastery/agents/swarm-orqx.md +1008 -0
  32. package/squads/claude-code-mastery/checklists/agent-team-readiness-checklist.md +88 -0
  33. package/squads/claude-code-mastery/checklists/brownfield-readiness-checklist.md +91 -0
  34. package/squads/claude-code-mastery/checklists/change-checklist.md +75 -0
  35. package/squads/claude-code-mastery/checklists/context-rot-checklist.md +114 -0
  36. package/squads/claude-code-mastery/checklists/integration-audit-checklist.md +104 -0
  37. package/squads/claude-code-mastery/checklists/multi-agent-review-checklist.md +77 -0
  38. package/squads/claude-code-mastery/checklists/pre-push-checklist.md +79 -0
  39. package/squads/claude-code-mastery/data/ci-cd-patterns.yaml +412 -0
  40. package/squads/claude-code-mastery/data/claude-code-quick-ref.yaml +314 -0
  41. package/squads/claude-code-mastery/data/hook-patterns.yaml +512 -0
  42. package/squads/claude-code-mastery/data/mcp-integration-catalog.yaml +323 -0
  43. package/squads/claude-code-mastery/data/project-type-signatures.yaml +335 -0
  44. package/squads/claude-code-mastery/scripts/validate-setup.js +163 -0
  45. package/squads/claude-code-mastery/squad.yaml +205 -0
  46. package/squads/claude-code-mastery/tasks/audit-integration.md +219 -0
  47. package/squads/claude-code-mastery/tasks/audit-settings.md +206 -0
  48. package/squads/claude-code-mastery/tasks/audit-setup.md +225 -0
  49. package/squads/claude-code-mastery/tasks/brownfield-setup.md +322 -0
  50. package/squads/claude-code-mastery/tasks/ci-cd-setup.md +335 -0
  51. package/squads/claude-code-mastery/tasks/claude-md-engineer.md +334 -0
  52. package/squads/claude-code-mastery/tasks/configure-claude-code.md +215 -0
  53. package/squads/claude-code-mastery/tasks/context-rot-audit.md +329 -0
  54. package/squads/claude-code-mastery/tasks/create-agent-definition.md +278 -0
  55. package/squads/claude-code-mastery/tasks/create-rules.md +206 -0
  56. package/squads/claude-code-mastery/tasks/create-team-topology.md +258 -0
  57. package/squads/claude-code-mastery/tasks/diagnose.md +166 -0
  58. package/squads/claude-code-mastery/tasks/enterprise-config.md +346 -0
  59. package/squads/claude-code-mastery/tasks/hook-designer.md +272 -0
  60. package/squads/claude-code-mastery/tasks/integrate-project.md +304 -0
  61. package/squads/claude-code-mastery/tasks/mcp-integration-plan.md +229 -0
  62. package/squads/claude-code-mastery/tasks/mcp-workflow.md +285 -0
  63. package/squads/claude-code-mastery/tasks/multi-project-setup.md +228 -0
  64. package/squads/claude-code-mastery/tasks/optimize-context.md +217 -0
  65. package/squads/claude-code-mastery/tasks/optimize-workflow.md +226 -0
  66. package/squads/claude-code-mastery/tasks/parallel-decomposition.md +293 -0
  67. package/squads/claude-code-mastery/tasks/permission-strategy.md +266 -0
  68. package/squads/claude-code-mastery/tasks/sandbox-setup.md +279 -0
  69. package/squads/claude-code-mastery/tasks/setup-repository.md +230 -0
  70. package/squads/claude-code-mastery/tasks/setup-wizard.md +236 -0
  71. package/squads/claude-code-mastery/tasks/worktree-strategy.md +320 -0
  72. package/squads/claude-code-mastery/templates/claude-md-fullstack.md +147 -0
  73. package/squads/claude-code-mastery/templates/claude-md-library.md +175 -0
  74. package/squads/claude-code-mastery/templates/claude-md-microservices.md +186 -0
  75. package/squads/claude-code-mastery/templates/claude-md-mobile.md +198 -0
  76. package/squads/claude-code-mastery/templates/claude-md-monorepo.md +139 -0
  77. package/squads/claude-code-mastery/templates/github-actions-claude-ci.yml +348 -0
  78. package/squads/claude-code-mastery/templates/github-actions-claude-review.yml +179 -0
  79. package/squads/claude-code-mastery/workflows/wf-audit-complete.yaml +140 -0
  80. package/squads/claude-code-mastery/workflows/wf-knowledge-update.yaml +165 -0
  81. package/squads/claude-code-mastery/workflows/wf-project-setup.yaml +192 -0
  82. package/.sinapse-ai/infrastructure/scripts/ide-sync/transformers/antigravity.js +0 -105
  83. package/.sinapse-ai/infrastructure/scripts/ide-sync/transformers/cursor.js +0 -94
  84. package/.sinapse-ai/infrastructure/scripts/ide-sync/transformers/github-copilot.js +0 -184
  85. package/.sinapse-ai/infrastructure/scripts/validate-gemini-integration.js +0 -151
  86. package/.sinapse-ai/product/templates/ide-rules/antigravity-rules.md +0 -115
  87. package/.sinapse-ai/product/templates/ide-rules/copilot-rules.md +0 -92
  88. package/.sinapse-ai/product/templates/ide-rules/cursor-rules.md +0 -115
  89. package/.sinapse-ai/product/templates/ide-rules/gemini-rules.md +0 -87
  90. package/docs/pt/platforms/antigravity.md +0 -508
  91. package/docs/pt/platforms/cursor.md +0 -633
  92. package/docs/pt/platforms/gemini-cli.md +0 -481
  93. package/docs/pt/platforms/github-copilot.md +0 -478
@@ -0,0 +1,322 @@
1
+ # Task: Brownfield Project Claude Code Setup
2
+
3
+ **Task ID:** brownfield-setup
4
+ **Version:** 1.0
5
+ **Purpose:** Set up Claude Code in an existing brownfield project, respecting established conventions and protecting critical paths
6
+ **Orchestrator:** @project-integrator (Conduit)
7
+ **Mode:** Interactive (elicit: true)
8
+ **Quality Standard:** No existing workflow disrupted, deny rules protect critical paths, conventions documented
9
+
10
+ ---
11
+
12
+ ## Overview
13
+
14
+ This task differs from integrate-project in that it focuses on **discovering and respecting existing conventions** rather than establishing new ones. The brownfield approach prioritizes safety: protect what exists, teach Claude the project's rules, and integrate without disrupting established workflows.
15
+
16
+ ```
17
+ INPUT (project_root + critical_paths)
18
+ |
19
+ [PHASE 1: CODEBASE SCANNING]
20
+ -> Discover frameworks, patterns, naming conventions
21
+ -> Identify coding style from existing code
22
+ -> Map project structure and architecture
23
+ |
24
+ [PHASE 2: EXISTING TOOLING DETECTION]
25
+ -> Detect CI/CD pipelines
26
+ -> Detect linting, formatting, testing setup
27
+ -> Identify deployment workflows
28
+ |
29
+ [PHASE 3: CONVENTION-RESPECTING CLAUDE.MD]
30
+ -> Generate CLAUDE.md that teaches Claude the project's ways
31
+ -> Document coding patterns found in existing code
32
+ -> Include project-specific terminology
33
+ |
34
+ [PHASE 4: PATTERN RULES]
35
+ -> Create rules that encode project-specific patterns
36
+ -> Teach Claude about architectural decisions
37
+ -> Document anti-patterns to avoid
38
+ |
39
+ [PHASE 5: DENY RULES FOR CRITICAL PATHS]
40
+ -> Identify files/directories that must not be modified
41
+ -> Configure deny rules in settings.json
42
+ -> Set up allow exceptions for specific operations
43
+ |
44
+ [PHASE 6: WORKFLOW INTEGRATION]
45
+ -> Configure hooks for existing CI/CD
46
+ -> Set up pre-commit alignment with existing linters
47
+ -> Ensure Claude follows the team's git workflow
48
+ |
49
+ OUTPUT: Brownfield integration config + protected paths + convention docs
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Inputs
55
+
56
+ | Field | Type | Source | Required | Validation |
57
+ |-------|------|--------|----------|------------|
58
+ | project_root | string | Auto-detect | yes | Existing project with source code |
59
+ | critical_paths | array | User | no | Paths that must never be modified by AI |
60
+ | team_conventions_doc | string | User | no | Path to existing coding standards doc |
61
+ | deployment_branch | string | User | no | Branch used for deployment (default: main) |
62
+ | legacy_areas | array | User | no | Directories with legacy code to be careful with |
63
+
64
+ ---
65
+
66
+ ## Preconditions
67
+
68
+ 1. Project exists with established codebase (not greenfield)
69
+ 2. Project has existing commit history (to analyze conventions)
70
+ 3. User can identify critical paths that need protection
71
+ 4. Git is initialized and functional
72
+
73
+ ---
74
+
75
+ ## Phase 1: Codebase Scanning
76
+
77
+ **Goal:** Understand the project's established patterns without changing anything.
78
+
79
+ ### Steps
80
+
81
+ 1.1. Scan directory structure and build a source tree:
82
+
83
+ ```
84
+ src/
85
+ components/ -> React components (functional, arrow functions)
86
+ services/ -> API service layer (class-based)
87
+ utils/ -> Utility functions (pure functions)
88
+ hooks/ -> Custom React hooks (use* naming)
89
+ types/ -> TypeScript type definitions
90
+ ```
91
+
92
+ 1.2. Analyze coding patterns from existing files:
93
+ - Import style (named vs default, absolute vs relative)
94
+ - Component patterns (functional vs class, hooks usage)
95
+ - Error handling patterns (try/catch vs error boundaries)
96
+ - Naming conventions (camelCase, PascalCase, kebab-case for files)
97
+ - Comment style and density
98
+
99
+ 1.3. Detect architectural patterns:
100
+ - State management approach
101
+ - API integration patterns
102
+ - Routing structure
103
+ - Authentication flow
104
+
105
+ 1.4. Build a pattern inventory:
106
+
107
+ ```yaml
108
+ patterns:
109
+ imports: "absolute with @ alias"
110
+ components: "functional with arrow functions"
111
+ state: "Zustand stores in src/stores/"
112
+ api: "axios instances in src/services/"
113
+ naming:
114
+ files: "kebab-case"
115
+ components: "PascalCase"
116
+ functions: "camelCase"
117
+ constants: "UPPER_SNAKE_CASE"
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Phase 2: Existing Tooling Detection
123
+
124
+ **Goal:** Map all existing development tools and workflows.
125
+
126
+ ### Steps
127
+
128
+ 2.1. Check for CI/CD:
129
+ - `.github/workflows/*.yml` (GitHub Actions)
130
+ - `.gitlab-ci.yml` (GitLab CI)
131
+ - `Jenkinsfile` (Jenkins)
132
+ - `.circleci/` (CircleCI)
133
+ - `vercel.json` (Vercel)
134
+ - `netlify.toml` (Netlify)
135
+
136
+ 2.2. Check for code quality tools:
137
+ - `.eslintrc*` / `eslint.config.*` (ESLint)
138
+ - `.prettierrc*` (Prettier)
139
+ - `.stylelintrc*` (Stylelint)
140
+ - `.editorconfig` (EditorConfig)
141
+ - `commitlint.config.*` (Commit message linting)
142
+
143
+ 2.3. Check for testing:
144
+ - `jest.config.*` (Jest)
145
+ - `vitest.config.*` (Vitest)
146
+ - `cypress.config.*` (Cypress)
147
+ - `playwright.config.*` (Playwright)
148
+
149
+ 2.4. Document existing scripts from package.json:
150
+
151
+ ```yaml
152
+ scripts:
153
+ dev: "next dev"
154
+ build: "next build"
155
+ test: "jest --coverage"
156
+ lint: "eslint src/"
157
+ format: "prettier --write src/"
158
+ ```
159
+
160
+ ---
161
+
162
+ ## Phase 3: Convention-Respecting CLAUDE.md
163
+
164
+ **Goal:** Create CLAUDE.md that teaches Claude to write code that looks like the existing codebase.
165
+
166
+ ### Steps
167
+
168
+ 3.1. Write CLAUDE.md with emphasis on existing patterns:
169
+
170
+ ```markdown
171
+ # {Project Name}
172
+
173
+ ## Code Standards (from existing codebase)
174
+ - Import style: {detected pattern}
175
+ - Component pattern: {detected pattern}
176
+ - File naming: {detected pattern}
177
+ - Error handling: {detected pattern}
178
+
179
+ ## Commands
180
+ - `{npm run dev}` -- Start development server
181
+ - `{npm test}` -- Run tests
182
+ - `{npm run lint}` -- Run linter
183
+
184
+ ## Architecture
185
+ {Brief description of project structure}
186
+
187
+ ## Critical Rules
188
+ - NEVER modify files in {critical_paths}
189
+ - ALWAYS follow existing patterns in neighboring files
190
+ - When in doubt, check how similar code is written in the codebase
191
+ ```
192
+
193
+ 3.2. If a team conventions document exists, incorporate its rules.
194
+ 3.3. Keep under 200 lines. Move details to rules files.
195
+
196
+ ---
197
+
198
+ ## Phase 4: Pattern Rules
199
+
200
+ **Goal:** Create rules that encode project-specific knowledge.
201
+
202
+ ### Steps
203
+
204
+ 4.1. Create `.claude/rules/` with pattern files:
205
+
206
+ | Rule | Content |
207
+ |------|---------|
208
+ | `code-style.md` | Naming conventions, import patterns, file structure |
209
+ | `architecture.md` | Layer boundaries, data flow, dependency rules |
210
+ | `anti-patterns.md` | Things to never do in this codebase |
211
+ | `legacy-areas.md` | Special handling for legacy code sections |
212
+
213
+ 4.2. Use path-based activation for context-specific rules:
214
+
215
+ ```markdown
216
+ ---
217
+ paths:
218
+ - "src/legacy/**"
219
+ ---
220
+ # Legacy Code Rules
221
+ - Do NOT refactor unless explicitly asked
222
+ - Maintain existing patterns even if suboptimal
223
+ - Add tests before making any changes
224
+ ```
225
+
226
+ ---
227
+
228
+ ## Phase 5: Deny Rules for Critical Paths
229
+
230
+ **Goal:** Protect files and directories that AI should not modify.
231
+
232
+ ### Common Critical Paths
233
+
234
+ | Path Pattern | Reason |
235
+ |-------------|--------|
236
+ | `.env*` | Secrets and credentials |
237
+ | `**/migrations/**` | Database migrations (run, don't edit) |
238
+ | `docker-compose.prod.yml` | Production infrastructure |
239
+ | `*.lock` | Lock files (managed by package managers) |
240
+ | `.github/workflows/**` | CI/CD pipelines |
241
+ | `infrastructure/**` | Infrastructure-as-code |
242
+
243
+ ### Steps
244
+
245
+ 5.1. Collect critical paths from user and auto-detection.
246
+ 5.2. Configure deny rules in `.claude/settings.json`:
247
+
248
+ ```json
249
+ {
250
+ "permissions": {
251
+ "deny": [
252
+ "Edit(.env*)",
253
+ "Write(.env*)",
254
+ "Edit(**/migrations/**)",
255
+ "Edit(docker-compose.prod.yml)",
256
+ "Edit(.github/workflows/**)"
257
+ ],
258
+ "allow": [
259
+ "Read(**)"
260
+ ]
261
+ }
262
+ }
263
+ ```
264
+
265
+ 5.3. Verify deny rules do not block legitimate development work.
266
+
267
+ ---
268
+
269
+ ## Phase 6: Workflow Integration
270
+
271
+ **Goal:** Make Claude Code work within the project's existing workflows.
272
+
273
+ ### Steps
274
+
275
+ 6.1. Configure pre-tool-use hooks to align with existing linters:
276
+ - After writing code, suggest running the project's lint command
277
+ - After modifying tests, suggest running the project's test command
278
+
279
+ 6.2. Align git behavior with team conventions:
280
+ - Detect commit message format from history (conventional commits, etc.)
281
+ - Document branch naming conventions
282
+ - Note any PR template or review requirements
283
+
284
+ 6.3. Set up notification hooks for critical operations:
285
+ - Alert when modifying shared configuration files
286
+ - Alert when adding new dependencies
287
+
288
+ ---
289
+
290
+ ## Output Format
291
+
292
+ ```yaml
293
+ brownfield_setup_result:
294
+ project_analysis:
295
+ language: "TypeScript"
296
+ framework: "Next.js 14"
297
+ patterns_detected: 12
298
+ tooling_detected: ["ESLint", "Prettier", "Jest", "GitHub Actions"]
299
+ files_created:
300
+ - "CLAUDE.md"
301
+ - ".claude/settings.json"
302
+ - ".claude/rules/code-style.md"
303
+ - ".claude/rules/architecture.md"
304
+ - ".claude/rules/anti-patterns.md"
305
+ critical_paths_protected: 5
306
+ deny_rules_configured: 5
307
+ existing_workflows_integrated: true
308
+ disruption_risk: "none"
309
+ overall_status: "PASS"
310
+ ```
311
+
312
+ ---
313
+
314
+ ## Veto Conditions
315
+
316
+ | Condition | Action |
317
+ |-----------|--------|
318
+ | Project has no existing source code | HALT -- use integrate-project for greenfield |
319
+ | CLAUDE.md exists and is manually maintained | WARN -- ask before overwriting |
320
+ | Cannot detect any coding patterns (empty repo) | HALT -- nothing to learn from |
321
+ | Critical paths list is empty and project is large | WARN -- strongly recommend identifying critical paths |
322
+ | Existing .claude/settings.json has deny rules | MERGE -- add to existing rules, do not replace |
@@ -0,0 +1,335 @@
1
+ # Task: Claude Code CI/CD Pipeline Setup
2
+
3
+ **Task ID:** ci-cd-setup
4
+ **Version:** 1.0
5
+ **Purpose:** Configure Claude Code for headless execution in CI/CD pipelines (PR review, code generation, testing)
6
+ **Orchestrator:** @project-integrator (Conduit)
7
+ **Mode:** Interactive (elicit: true)
8
+ **Quality Standard:** Pipeline runs successfully in headless mode, safety limits configured, costs controlled
9
+
10
+ ---
11
+
12
+ ## Overview
13
+
14
+ This task sets up Claude Code to run in CI/CD pipelines using headless mode (`claude -p`). It covers GitHub Actions integration, API key management, output format configuration, and safety limits to prevent runaway costs.
15
+
16
+ ```
17
+ INPUT (ci_platform + integration_pattern + budget)
18
+ |
19
+ [PHASE 1: INTEGRATION PATTERN SELECTION]
20
+ -> Choose what Claude does in CI (review, generate, test)
21
+ -> Define trigger events (PR open, push, comment)
22
+ -> Set scope and limitations
23
+ |
24
+ [PHASE 2: HEADLESS MODE CONFIGURATION]
25
+ -> Configure claude -p for non-interactive use
26
+ -> Set --output-format for machine-readable output
27
+ -> Configure --max-turns for cost control
28
+ |
29
+ [PHASE 3: GITHUB ACTIONS WORKFLOW]
30
+ -> Create .github/workflows/claude-*.yml
31
+ -> Configure trigger events
32
+ -> Set up job steps
33
+ |
34
+ [PHASE 4: API KEY AND ENVIRONMENT]
35
+ -> Set up ANTHROPIC_API_KEY as secret
36
+ -> Configure environment variables
37
+ -> Set up caching for Claude Code CLI
38
+ |
39
+ [PHASE 5: OUTPUT FORMAT AND PARSING]
40
+ -> Configure --output-format stream-json
41
+ -> Parse output for PR comments
42
+ -> Handle error output
43
+ |
44
+ [PHASE 6: SAFETY LIMITS]
45
+ -> Set --max-turns to cap execution
46
+ -> Configure cost budget per run
47
+ -> Set up alerting for anomalies
48
+ |
49
+ OUTPUT: CI/CD workflow files + secrets docs + safety config
50
+ ```
51
+
52
+ ---
53
+
54
+ ## Inputs
55
+
56
+ | Field | Type | Source | Required | Validation |
57
+ |-------|------|--------|----------|------------|
58
+ | ci_platform | enum | User | yes | github-actions / gitlab-ci / other |
59
+ | integration_pattern | enum | User | yes | pr-review / code-gen / testing / custom |
60
+ | max_cost_per_run | string | User | no | Budget cap (default: $1.00) |
61
+ | trigger_events | array | User | no | When to run (default: pull_request) |
62
+ | claude_version | string | User | no | Pin to specific version or "latest" |
63
+
64
+ ---
65
+
66
+ ## Preconditions
67
+
68
+ 1. GitHub repository with Actions enabled (or equivalent CI platform)
69
+ 2. Anthropic API key available
70
+ 3. Repository has existing CI/CD (recommended, not required)
71
+ 4. Understanding of which tasks Claude should automate
72
+
73
+ ---
74
+
75
+ ## Phase 1: Integration Pattern Selection
76
+
77
+ **Goal:** Choose the right CI integration pattern.
78
+
79
+ ### Available Patterns
80
+
81
+ | Pattern | Trigger | What Claude Does | Typical Cost |
82
+ |---------|---------|-----------------|--------------|
83
+ | **PR Review** | `pull_request` | Reviews code changes, posts comments | $0.10-0.50/PR |
84
+ | **Code Generation** | `workflow_dispatch` or comment | Generates code from spec/issue | $0.50-2.00/run |
85
+ | **Test Generation** | `pull_request` | Generates tests for new code | $0.20-1.00/PR |
86
+ | **Documentation** | `push` to main | Updates docs for changed code | $0.10-0.30/push |
87
+ | **Issue Triage** | `issues.opened` | Categorizes and labels issues | $0.05-0.10/issue |
88
+
89
+ ### Steps
90
+
91
+ 1.1. Select one or more patterns based on team needs.
92
+ 1.2. Define the specific prompt for each pattern.
93
+ 1.3. Set expected output format (comment, file, label).
94
+
95
+ ---
96
+
97
+ ## Phase 2: Headless Mode Configuration
98
+
99
+ **Goal:** Configure Claude Code for non-interactive execution.
100
+
101
+ ### Headless Mode Basics
102
+
103
+ ```bash
104
+ # Basic headless execution
105
+ claude -p "Review the changes in this PR for bugs and security issues"
106
+
107
+ # With output format
108
+ claude -p "..." --output-format stream-json
109
+
110
+ # With turn limit
111
+ claude -p "..." --max-turns 10
112
+
113
+ # With specific model
114
+ claude -p "..." --model sonnet
115
+
116
+ # With system prompt from file
117
+ claude -p "..." --system-prompt "$(cat .claude/ci-system-prompt.md)"
118
+ ```
119
+
120
+ ### Key Flags
121
+
122
+ | Flag | Purpose | Recommended |
123
+ |------|---------|-------------|
124
+ | `-p` | Non-interactive mode (read from argument) | Always use in CI |
125
+ | `--output-format stream-json` | Machine-parseable JSON output | For automated processing |
126
+ | `--output-format text` | Plain text output | For simple logging |
127
+ | `--max-turns` | Limit tool calls | Always set (default: 10) |
128
+ | `--model` | Select model | sonnet for cost, opus for quality |
129
+ | `--no-telemetry` | Disable telemetry | Recommended for CI |
130
+
131
+ ### Steps
132
+
133
+ 2.1. Compose the headless command for each integration pattern.
134
+ 2.2. Create a system prompt file for CI context (`.claude/ci-system-prompt.md`).
135
+ 2.3. Test the command locally before adding to CI.
136
+
137
+ ---
138
+
139
+ ## Phase 3: GitHub Actions Workflow
140
+
141
+ **Goal:** Create the CI workflow file.
142
+
143
+ ### GitHub Actions Template
144
+
145
+ ```yaml
146
+ name: Claude Code Review
147
+ on:
148
+ pull_request:
149
+ types: [opened, synchronize]
150
+
151
+ permissions:
152
+ contents: read
153
+ pull-requests: write
154
+
155
+ jobs:
156
+ claude-review:
157
+ runs-on: ubuntu-latest
158
+ timeout-minutes: 10
159
+ steps:
160
+ - name: Checkout
161
+ uses: actions/checkout@v4
162
+ with:
163
+ fetch-depth: 0
164
+
165
+ - name: Install Claude Code
166
+ run: npm install -g @anthropic-ai/claude-code@latest
167
+
168
+ - name: Run Claude Review
169
+ env:
170
+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
171
+ run: |
172
+ DIFF=$(git diff origin/main...HEAD)
173
+ claude -p "Review these changes for bugs, security issues, and code quality. Be concise. Changes: $DIFF" \
174
+ --output-format text \
175
+ --max-turns 10 \
176
+ --model sonnet \
177
+ > review-output.txt
178
+
179
+ - name: Post Review Comment
180
+ uses: actions/github-script@v7
181
+ with:
182
+ script: |
183
+ const fs = require('fs');
184
+ const review = fs.readFileSync('review-output.txt', 'utf8');
185
+ await github.rest.issues.createComment({
186
+ owner: context.repo.owner,
187
+ repo: context.repo.repo,
188
+ issue_number: context.issue.number,
189
+ body: `## Claude Code Review\n\n${review}`
190
+ });
191
+ ```
192
+
193
+ ### Steps
194
+
195
+ 3.1. Create `.github/workflows/claude-review.yml` (or equivalent).
196
+ 3.2. Configure trigger events.
197
+ 3.3. Set appropriate `timeout-minutes` (10 for reviews, 30 for generation).
198
+ 3.4. Add `permissions` block for required GitHub token scopes.
199
+
200
+ ---
201
+
202
+ ## Phase 4: API Key and Environment
203
+
204
+ **Goal:** Securely configure API access.
205
+
206
+ ### Steps
207
+
208
+ 4.1. Add `ANTHROPIC_API_KEY` as a repository secret:
209
+ - Go to Settings > Secrets and variables > Actions
210
+ - Add `ANTHROPIC_API_KEY` with the API key value
211
+
212
+ 4.2. Configure additional environment variables if needed:
213
+
214
+ ```yaml
215
+ env:
216
+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
217
+ CLAUDE_MODEL: "sonnet"
218
+ CLAUDE_MAX_TURNS: "10"
219
+ ```
220
+
221
+ 4.3. Security considerations:
222
+ - NEVER log the API key
223
+ - NEVER pass the key as a command argument (use env var)
224
+ - Use repository secrets, not environment variables in workflow files
225
+ - Consider using OIDC for keyless authentication if available
226
+
227
+ ---
228
+
229
+ ## Phase 5: Output Format and Parsing
230
+
231
+ **Goal:** Configure output for machine consumption.
232
+
233
+ ### Stream JSON Format
234
+
235
+ When using `--output-format stream-json`, output is newline-delimited JSON:
236
+
237
+ ```json
238
+ {"type": "assistant", "content": "Here is my analysis..."}
239
+ {"type": "tool_use", "tool": "Read", "input": {"file_path": "..."}}
240
+ {"type": "tool_result", "content": "..."}
241
+ {"type": "assistant", "content": "Based on reading the file..."}
242
+ ```
243
+
244
+ ### Steps
245
+
246
+ 5.1. Choose output format based on integration pattern:
247
+ - PR review -> `text` (for posting as comment)
248
+ - Code generation -> `stream-json` (for parsing file changes)
249
+ - Testing -> `text` (for test result summary)
250
+
251
+ 5.2. Create a parsing script if using `stream-json`:
252
+
253
+ ```bash
254
+ # Extract final assistant message
255
+ claude -p "..." --output-format stream-json | \
256
+ jq -s '[.[] | select(.type == "assistant")] | last | .content'
257
+ ```
258
+
259
+ 5.3. Handle error cases:
260
+ - Empty output -> Claude could not process
261
+ - Timeout -> increase timeout or reduce scope
262
+ - Rate limit -> add retry logic with backoff
263
+
264
+ ---
265
+
266
+ ## Phase 6: Safety Limits
267
+
268
+ **Goal:** Prevent runaway costs and unintended behavior.
269
+
270
+ ### Safety Configuration
271
+
272
+ | Limit | Value | Purpose |
273
+ |-------|-------|---------|
274
+ | `--max-turns` | 10 (review), 25 (generation) | Cap tool call iterations |
275
+ | `timeout-minutes` | 10 (review), 30 (generation) | GitHub Actions job timeout |
276
+ | Max diff size | 5000 lines | Skip very large PRs |
277
+ | Cost per run | $1.00 default | Alert if exceeded |
278
+ | Runs per day | 50 | Prevent abuse on high-activity repos |
279
+
280
+ ### Steps
281
+
282
+ 6.1. Set `--max-turns` for every `claude -p` invocation.
283
+ 6.2. Add a diff size check before running Claude:
284
+
285
+ ```bash
286
+ DIFF_LINES=$(git diff origin/main...HEAD | wc -l)
287
+ if [ "$DIFF_LINES" -gt 5000 ]; then
288
+ echo "PR too large for automated review ($DIFF_LINES lines)"
289
+ exit 0
290
+ fi
291
+ ```
292
+
293
+ 6.3. Configure job concurrency to prevent parallel runs:
294
+
295
+ ```yaml
296
+ concurrency:
297
+ group: claude-review-${{ github.event.pull_request.number }}
298
+ cancel-in-progress: true
299
+ ```
300
+
301
+ 6.4. Set up cost monitoring (check Anthropic usage dashboard).
302
+
303
+ ---
304
+
305
+ ## Output Format
306
+
307
+ ```yaml
308
+ ci_cd_setup_result:
309
+ platform: "github-actions"
310
+ integration_pattern: "pr-review"
311
+ files_created:
312
+ - ".github/workflows/claude-review.yml"
313
+ - ".claude/ci-system-prompt.md"
314
+ secrets_required:
315
+ - "ANTHROPIC_API_KEY"
316
+ safety_limits:
317
+ max_turns: 10
318
+ timeout_minutes: 10
319
+ max_diff_lines: 5000
320
+ estimated_cost_per_run: "$0.10-0.50"
321
+ tested: true
322
+ overall_status: "PASS"
323
+ ```
324
+
325
+ ---
326
+
327
+ ## Veto Conditions
328
+
329
+ | Condition | Action |
330
+ |-----------|--------|
331
+ | No CI platform access (cannot create workflows) | HALT -- need admin access |
332
+ | API key not available | HALT -- cannot configure without key |
333
+ | Repository is public and key would be exposed | HALT -- ensure secrets are properly configured |
334
+ | Cost budget is zero | HALT -- headless mode incurs API costs |
335
+ | CI platform not supported (no GitHub Actions, no GitLab CI) | HALT -- manual setup required |