ginskill-init 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.
- package/README.md +77 -0
- package/agents/developer.md +56 -0
- package/agents/frontend-design.md +69 -0
- package/agents/mobile-reviewer.md +36 -0
- package/agents/review-code.md +49 -0
- package/agents/security-scanner.md +50 -0
- package/agents/tester.md +72 -0
- package/bin/cli.js +226 -0
- package/package.json +20 -0
- package/skills/ai-asset-generator/SKILL.md +255 -0
- package/skills/ai-asset-generator/docs/gen-image.md +274 -0
- package/skills/ai-asset-generator/docs/genvideo.md +341 -0
- package/skills/ai-asset-generator/docs/remove-background.md +19 -0
- package/skills/ai-asset-generator/generate-credit-assets.mjs +180 -0
- package/skills/ai-asset-generator/generate-ginbrowser-assets.mjs +242 -0
- package/skills/ai-asset-generator/generate-sty-icon.mjs +149 -0
- package/skills/ai-asset-generator/lib/bg-remove.mjs +34 -0
- package/skills/ai-asset-generator/lib/env.mjs +38 -0
- package/skills/ai-asset-generator/lib/kie-client.mjs +88 -0
- package/skills/ai-asset-generator/scripts/scaffold-generator.mjs +203 -0
- package/skills/ai-build-ai/SKILL.md +124 -0
- package/skills/ai-build-ai/docs/agent-teams.md +293 -0
- package/skills/ai-build-ai/docs/checkpointing.md +161 -0
- package/skills/ai-build-ai/docs/create-agent.md +399 -0
- package/skills/ai-build-ai/docs/create-mcp.md +395 -0
- package/skills/ai-build-ai/docs/create-skill.md +299 -0
- package/skills/ai-build-ai/docs/headless-mode.md +614 -0
- package/skills/ai-build-ai/docs/hooks.md +578 -0
- package/skills/ai-build-ai/docs/memory-claude-md.md +375 -0
- package/skills/ai-build-ai/docs/output-styles.md +208 -0
- package/skills/ai-build-ai/docs/overview.md +162 -0
- package/skills/ai-build-ai/docs/permissions.md +391 -0
- package/skills/ai-build-ai/docs/plugins.md +396 -0
- package/skills/ai-build-ai/docs/sandbox.md +262 -0
- package/skills/ai-build-ai/scripts/load-tutorial.sh +54 -0
- package/skills/icon-generator/SKILL.md +270 -0
- package/skills/mobile-app-review/SKILL.md +321 -0
- package/skills/mobile-app-review/references/apple-review.md +132 -0
- package/skills/mobile-app-review/references/google-play-review.md +203 -0
- package/skills/mongodb/SKILL.md +667 -0
- package/skills/mongodb/references/mongoose-patterns.md +368 -0
- package/skills/nestjs-architecture/SKILL.md +1086 -0
- package/skills/nestjs-architecture/references/advanced-patterns.md +590 -0
- package/skills/performance/SKILL.md +509 -0
- package/skills/react-fsd-architecture/SKILL.md +693 -0
- package/skills/react-fsd-architecture/references/fsd-patterns.md +747 -0
- package/skills/react-query/SKILL.md +685 -0
- package/skills/react-query/references/query-patterns.md +365 -0
- package/skills/review-code/SKILL.md +321 -0
- package/skills/review-code/references/clean-code-principles.md +395 -0
- package/skills/review-code/references/frontend-patterns.md +136 -0
- package/skills/review-code/references/nestjs-patterns.md +184 -0
- package/skills/review-code/scripts/check-module.sh +201 -0
- package/skills/review-code/scripts/deep-scan.sh +604 -0
- package/skills/review-code/scripts/dep-check.sh +522 -0
- package/skills/review-code/scripts/detect-duplicates.sh +466 -0
- package/skills/review-code/scripts/format-check.sh +577 -0
- package/skills/review-code/scripts/run-review.sh +167 -0
- package/skills/review-code/scripts/scan-codebase.sh +152 -0
- package/skills/security-scanner/SKILL.md +327 -0
- package/skills/security-scanner/references/nestjs-security.md +260 -0
- package/skills/security-scanner/references/nextjs-security.md +201 -0
- package/skills/security-scanner/references/react-native-security.md +199 -0
- package/skills/security-scanner/scripts/security-scan.sh +478 -0
- package/skills/ui-ux-pro-max/SKILL.md +377 -0
- package/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/skills/ui-ux-pro-max/data/stacks/astro.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/skills/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/skills/ui-ux-pro-max/data/styles.csv +68 -0
- package/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/skills/ui-ux-pro-max/scripts/core.py +253 -0
- package/skills/ui-ux-pro-max/scripts/design_system.py +1067 -0
- package/skills/ui-ux-pro-max/scripts/search.py +114 -0
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
# Tutorial: Headless Mode & Agent SDK
|
|
2
|
+
|
|
3
|
+
Run Claude Code programmatically — from scripts, CI/CD pipelines, automation workflows, or the Python/TypeScript Agent SDK.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Step 1: The Basics — `-p` Flag
|
|
8
|
+
|
|
9
|
+
The `-p` (or `--print`) flag runs Claude non-interactively:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Ask a question
|
|
13
|
+
claude -p "What does the auth module do?"
|
|
14
|
+
|
|
15
|
+
# Run a task
|
|
16
|
+
claude -p "Find and fix the bug in src/auth/login.ts"
|
|
17
|
+
|
|
18
|
+
# With specific tools
|
|
19
|
+
claude -p "Run tests and report failures" \
|
|
20
|
+
--allowedTools "Bash,Read,Edit"
|
|
21
|
+
|
|
22
|
+
# From a file or pipe
|
|
23
|
+
echo "Summarize this project" | claude -p -
|
|
24
|
+
cat PROMPT.md | claude -p -
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Step 2: Output Formats
|
|
30
|
+
|
|
31
|
+
### Text (default)
|
|
32
|
+
```bash
|
|
33
|
+
claude -p "Explain what useAuth.ts does"
|
|
34
|
+
# → plain text response
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### JSON (with metadata)
|
|
38
|
+
```bash
|
|
39
|
+
claude -p "Summarize this project" --output-format json
|
|
40
|
+
# → { "result": "...", "session_id": "abc123", "usage": {...}, "cost_usd": 0.012 }
|
|
41
|
+
|
|
42
|
+
# Extract just the text
|
|
43
|
+
claude -p "Summarize this project" --output-format json | jq -r '.result'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Structured JSON (with schema)
|
|
47
|
+
```bash
|
|
48
|
+
# Extract data conforming to a schema
|
|
49
|
+
claude -p "Extract function names from auth.ts" \
|
|
50
|
+
--output-format json \
|
|
51
|
+
--json-schema '{"type":"object","properties":{"functions":{"type":"array","items":{"type":"string"}}},"required":["functions"]}'
|
|
52
|
+
|
|
53
|
+
# → { "result": "...", "structured_output": { "functions": ["login", "logout", "refresh"] }, ... }
|
|
54
|
+
|
|
55
|
+
# Extract structured output
|
|
56
|
+
... | jq '.structured_output'
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Streaming JSON (real-time)
|
|
60
|
+
```bash
|
|
61
|
+
# Stream tokens as they generate
|
|
62
|
+
claude -p "Write a detailed analysis" \
|
|
63
|
+
--output-format stream-json \
|
|
64
|
+
--verbose \
|
|
65
|
+
--include-partial-messages
|
|
66
|
+
|
|
67
|
+
# Filter for just the text tokens
|
|
68
|
+
claude -p "Write a poem" \
|
|
69
|
+
--output-format stream-json --verbose --include-partial-messages | \
|
|
70
|
+
jq -rj 'select(.type == "stream_event" and .event.delta.type? == "text_delta") | .event.delta.text'
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Step 3: Auto-Approve Tools
|
|
76
|
+
|
|
77
|
+
Use `--allowedTools` to let Claude use tools without prompting:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Allow basic file operations
|
|
81
|
+
claude -p "Refactor the auth module" \
|
|
82
|
+
--allowedTools "Read,Edit,Grep,Glob"
|
|
83
|
+
|
|
84
|
+
# Allow bash with specific command prefixes
|
|
85
|
+
claude -p "Run tests and fix failures" \
|
|
86
|
+
--allowedTools "Bash,Read,Edit"
|
|
87
|
+
|
|
88
|
+
# Restrict bash to specific commands (prefix matching with space+*)
|
|
89
|
+
claude -p "Create a commit for staged changes" \
|
|
90
|
+
--allowedTools "Bash(git diff *),Bash(git log *),Bash(git status *),Bash(git commit *)"
|
|
91
|
+
|
|
92
|
+
# Allow all tools (bypass all permission prompts — use carefully)
|
|
93
|
+
claude -p "..." --dangerously-skip-permissions
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Permission rule syntax:**
|
|
97
|
+
- `Bash` — any bash command
|
|
98
|
+
- `Bash(git *)` — any command starting with `git` (space + `*` = prefix match)
|
|
99
|
+
- `Bash(git diff)` — exact match only
|
|
100
|
+
- `Read,Edit,Grep` — comma-separated list
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Step 4: Customize the System Prompt
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Append to Claude Code's default system prompt
|
|
108
|
+
claude -p "Review this PR for security vulnerabilities" \
|
|
109
|
+
--append-system-prompt "You are a security engineer. Focus on OWASP Top 10."
|
|
110
|
+
|
|
111
|
+
# Fully replace the system prompt (loses Claude Code's default behavior)
|
|
112
|
+
claude -p "Analyze this data" \
|
|
113
|
+
--system-prompt "You are a data scientist. Respond only with JSON."
|
|
114
|
+
|
|
115
|
+
# Pipe a PR diff and review it
|
|
116
|
+
gh pr diff 123 | claude -p \
|
|
117
|
+
--append-system-prompt "You are a senior TypeScript engineer reviewing a NestJS PR." \
|
|
118
|
+
--output-format json
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Step 5: Multi-Turn Conversations
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Continue the most recent conversation
|
|
127
|
+
claude -p "Review this codebase for performance issues"
|
|
128
|
+
claude -p "Now focus specifically on the database layer" --continue
|
|
129
|
+
claude -p "Generate a fix plan for the top 3 issues" --continue
|
|
130
|
+
|
|
131
|
+
# Continue a specific session
|
|
132
|
+
session=$(claude -p "Start a deep review" --output-format json | jq -r '.session_id')
|
|
133
|
+
claude -p "Continue that review focusing on security" --resume "$session"
|
|
134
|
+
claude -p "Generate a full report" --resume "$session"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## Step 6: Common CI/CD Patterns
|
|
140
|
+
|
|
141
|
+
### Auto-review on PR
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
#!/bin/bash
|
|
145
|
+
# .github/scripts/review-pr.sh
|
|
146
|
+
|
|
147
|
+
PR_NUMBER="$1"
|
|
148
|
+
|
|
149
|
+
# Fetch PR context
|
|
150
|
+
DIFF=$(gh pr diff "$PR_NUMBER")
|
|
151
|
+
DESCRIPTION=$(gh pr view "$PR_NUMBER" --json title,body -q '.title + "\n\n" + .body')
|
|
152
|
+
|
|
153
|
+
# Run Claude review
|
|
154
|
+
REVIEW=$(echo "$DIFF" | claude -p \
|
|
155
|
+
--append-system-prompt "You are a TypeScript/NestJS expert reviewing a PR. Be concise and specific." \
|
|
156
|
+
--output-format json | jq -r '.result')
|
|
157
|
+
|
|
158
|
+
# Post review as GitHub comment
|
|
159
|
+
gh pr comment "$PR_NUMBER" --body "$REVIEW"
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Auto-fix lint errors in CI
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
#!/bin/bash
|
|
166
|
+
# Run lint, capture failures, fix with Claude
|
|
167
|
+
|
|
168
|
+
LINT_OUTPUT=$(npm run lint 2>&1 || true)
|
|
169
|
+
|
|
170
|
+
if echo "$LINT_OUTPUT" | grep -q "error"; then
|
|
171
|
+
echo "Lint errors found. Asking Claude to fix..."
|
|
172
|
+
|
|
173
|
+
echo "$LINT_OUTPUT" | claude -p \
|
|
174
|
+
"These are lint errors from our codebase. Fix all of them:" \
|
|
175
|
+
--allowedTools "Read,Edit,Bash(npm run lint *)" \
|
|
176
|
+
--append-system-prompt "Fix lint errors minimally. Do not refactor unrelated code."
|
|
177
|
+
fi
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Batch file processing
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
#!/bin/bash
|
|
184
|
+
# Process all TypeScript files missing JSDoc comments
|
|
185
|
+
|
|
186
|
+
find src -name "*.ts" | while read -r file; do
|
|
187
|
+
HAS_JSDOC=$(grep -c "@param\|@returns\|@description" "$file" || echo "0")
|
|
188
|
+
|
|
189
|
+
if [ "$HAS_JSDOC" -eq 0 ]; then
|
|
190
|
+
claude -p "Add JSDoc comments to all exported functions in $file" \
|
|
191
|
+
--allowedTools "Read,Edit"
|
|
192
|
+
fi
|
|
193
|
+
done
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Generate reports from codebase analysis
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
#!/bin/bash
|
|
200
|
+
# Generate weekly codebase health report
|
|
201
|
+
|
|
202
|
+
REPORT=$(claude -p \
|
|
203
|
+
"Analyze this codebase and produce a JSON health report with: complexity_score (1-10), test_coverage_estimate, biggest_risks (array), recommended_actions (array)" \
|
|
204
|
+
--allowedTools "Read,Grep,Glob,Bash" \
|
|
205
|
+
--output-format json \
|
|
206
|
+
--json-schema '{
|
|
207
|
+
"type": "object",
|
|
208
|
+
"properties": {
|
|
209
|
+
"complexity_score": {"type": "number"},
|
|
210
|
+
"test_coverage_estimate": {"type": "string"},
|
|
211
|
+
"biggest_risks": {"type": "array", "items": {"type": "string"}},
|
|
212
|
+
"recommended_actions": {"type": "array", "items": {"type": "string"}}
|
|
213
|
+
}
|
|
214
|
+
}' | jq '.structured_output')
|
|
215
|
+
|
|
216
|
+
echo "$REPORT" | jq '.'
|
|
217
|
+
# Save to file or send to Slack
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Step 7: GitHub Actions Integration
|
|
223
|
+
|
|
224
|
+
Use the official Claude Code GitHub Action to run Claude in CI/CD pipelines with full GitHub context (PR diffs, issue bodies, comment threads).
|
|
225
|
+
|
|
226
|
+
### Basic Setup
|
|
227
|
+
|
|
228
|
+
```yaml
|
|
229
|
+
# .github/workflows/claude.yml
|
|
230
|
+
name: Claude Code
|
|
231
|
+
|
|
232
|
+
on:
|
|
233
|
+
pull_request:
|
|
234
|
+
types: [opened, synchronize]
|
|
235
|
+
issue_comment:
|
|
236
|
+
types: [created] # For @claude comment triggers
|
|
237
|
+
|
|
238
|
+
jobs:
|
|
239
|
+
claude:
|
|
240
|
+
runs-on: ubuntu-latest
|
|
241
|
+
permissions:
|
|
242
|
+
contents: read
|
|
243
|
+
pull-requests: write
|
|
244
|
+
issues: write
|
|
245
|
+
steps:
|
|
246
|
+
- uses: anthropics/claude-code-action@v1
|
|
247
|
+
with:
|
|
248
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
249
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Action Parameters
|
|
253
|
+
|
|
254
|
+
| Parameter | Required | Description |
|
|
255
|
+
|-----------|----------|-------------|
|
|
256
|
+
| `anthropic_api_key` | Yes (direct API) | From `${{ secrets.ANTHROPIC_API_KEY }}` |
|
|
257
|
+
| `github_token` | No | For GitHub API access (comments, PR info) |
|
|
258
|
+
| `prompt` | No | Instructions or skill (e.g., `/review`) |
|
|
259
|
+
| `claude_args` | No | Any CLI flags passed through |
|
|
260
|
+
| `trigger_phrase` | No | Default: `@claude` (for comment triggers) |
|
|
261
|
+
| `use_bedrock` | No | `"true"` for AWS Bedrock |
|
|
262
|
+
| `use_vertex` | No | `"true"` for Google Vertex AI |
|
|
263
|
+
|
|
264
|
+
### Passing CLI Arguments via `claude_args`
|
|
265
|
+
|
|
266
|
+
```yaml
|
|
267
|
+
- uses: anthropics/claude-code-action@v1
|
|
268
|
+
with:
|
|
269
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
270
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
271
|
+
claude_args: "--max-turns 5 --model claude-opus-4-6 --allowedTools Read,Grep,Glob"
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
| Flag | Purpose |
|
|
275
|
+
|------|---------|
|
|
276
|
+
| `--max-turns N` | Limit iterations (default: 10) — key for cost control |
|
|
277
|
+
| `--model <model>` | Override model (default: Sonnet) |
|
|
278
|
+
| `--allowedTools <list>` | Restrict which tools Claude can use |
|
|
279
|
+
| `--disallowedTools <list>` | Block specific tools |
|
|
280
|
+
| `--append-system-prompt <text>` | Add instructions to system prompt |
|
|
281
|
+
| `--mcp-config <path>` | Use an MCP config file |
|
|
282
|
+
|
|
283
|
+
**Auto-detection:** If `prompt` is omitted and the trigger is a comment event, the action runs in interactive mode (responds to `@claude` comments). If `prompt` is set, it runs in automation mode.
|
|
284
|
+
|
|
285
|
+
### Common Patterns
|
|
286
|
+
|
|
287
|
+
#### Auto-review PRs
|
|
288
|
+
|
|
289
|
+
```yaml
|
|
290
|
+
name: PR Review
|
|
291
|
+
on:
|
|
292
|
+
pull_request:
|
|
293
|
+
types: [opened, synchronize]
|
|
294
|
+
jobs:
|
|
295
|
+
review:
|
|
296
|
+
runs-on: ubuntu-latest
|
|
297
|
+
permissions:
|
|
298
|
+
pull-requests: write
|
|
299
|
+
steps:
|
|
300
|
+
- uses: anthropics/claude-code-action@v1
|
|
301
|
+
with:
|
|
302
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
303
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
304
|
+
prompt: "/review"
|
|
305
|
+
claude_args: "--max-turns 5"
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
#### Respond to @claude comments on PRs/Issues
|
|
309
|
+
|
|
310
|
+
```yaml
|
|
311
|
+
name: Claude Interactive
|
|
312
|
+
on:
|
|
313
|
+
issue_comment:
|
|
314
|
+
types: [created]
|
|
315
|
+
pull_request_review_comment:
|
|
316
|
+
types: [created]
|
|
317
|
+
jobs:
|
|
318
|
+
respond:
|
|
319
|
+
runs-on: ubuntu-latest
|
|
320
|
+
if: contains(github.event.comment.body, '@claude')
|
|
321
|
+
permissions:
|
|
322
|
+
contents: write
|
|
323
|
+
pull-requests: write
|
|
324
|
+
steps:
|
|
325
|
+
- uses: anthropics/claude-code-action@v1
|
|
326
|
+
with:
|
|
327
|
+
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
|
|
328
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
329
|
+
# No prompt = interactive mode; responds to the @claude comment
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### AWS Bedrock Setup
|
|
333
|
+
|
|
334
|
+
```yaml
|
|
335
|
+
jobs:
|
|
336
|
+
review:
|
|
337
|
+
runs-on: ubuntu-latest
|
|
338
|
+
permissions:
|
|
339
|
+
id-token: write # REQUIRED for OIDC
|
|
340
|
+
pull-requests: write
|
|
341
|
+
steps:
|
|
342
|
+
- name: Configure AWS Credentials
|
|
343
|
+
uses: aws-actions/configure-aws-credentials@v4
|
|
344
|
+
with:
|
|
345
|
+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
|
|
346
|
+
aws-region: us-west-2
|
|
347
|
+
|
|
348
|
+
- uses: anthropics/claude-code-action@v1
|
|
349
|
+
with:
|
|
350
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
351
|
+
use_bedrock: "true"
|
|
352
|
+
claude_args: "--model us.anthropic.claude-sonnet-4-6 --max-turns 10"
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
**AWS requirements:** GitHub OIDC provider in AWS, IAM role with `AmazonBedrockFullAccess`, model ID format: `us.anthropic.claude-sonnet-4-6` (region-prefixed).
|
|
356
|
+
|
|
357
|
+
### Google Vertex AI Setup
|
|
358
|
+
|
|
359
|
+
```yaml
|
|
360
|
+
steps:
|
|
361
|
+
- name: Auth with Google Cloud
|
|
362
|
+
uses: google-github-actions/auth@v2
|
|
363
|
+
id: auth
|
|
364
|
+
with:
|
|
365
|
+
workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
|
|
366
|
+
service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
|
|
367
|
+
|
|
368
|
+
- uses: anthropics/claude-code-action@v1
|
|
369
|
+
with:
|
|
370
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
371
|
+
use_vertex: "true"
|
|
372
|
+
claude_args: "--model claude-sonnet-4@20250514"
|
|
373
|
+
env:
|
|
374
|
+
ANTHROPIC_VERTEX_PROJECT_ID: ${{ steps.auth.outputs.project_id }}
|
|
375
|
+
CLOUD_ML_REGION: us-east5
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
**Vertex AI requirements:** Workload Identity Federation (not service account keys), Vertex AI API enabled. Model ID format: `claude-sonnet-4@20250514`.
|
|
379
|
+
|
|
380
|
+
### Cost Control
|
|
381
|
+
|
|
382
|
+
```yaml
|
|
383
|
+
# Limit turns to control cost
|
|
384
|
+
claude_args: "--max-turns 5"
|
|
385
|
+
|
|
386
|
+
# Set a workflow-level timeout
|
|
387
|
+
jobs:
|
|
388
|
+
claude:
|
|
389
|
+
timeout-minutes: 10
|
|
390
|
+
|
|
391
|
+
# Prevent parallel runs (cancel in-progress if new commit pushed)
|
|
392
|
+
concurrency:
|
|
393
|
+
group: claude-${{ github.ref }}
|
|
394
|
+
cancel-in-progress: true
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## Step 8: Agent SDK (Python)
|
|
400
|
+
|
|
401
|
+
For full programmatic control with callbacks, streaming, and native objects:
|
|
402
|
+
|
|
403
|
+
```bash
|
|
404
|
+
pip install claude-agent-sdk
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
```python
|
|
408
|
+
import asyncio
|
|
409
|
+
import claude_agent_sdk as agent
|
|
410
|
+
|
|
411
|
+
async def main():
|
|
412
|
+
# Simple one-shot
|
|
413
|
+
result = await agent.run(
|
|
414
|
+
prompt="Analyze the auth module and list all security concerns",
|
|
415
|
+
options=agent.ClaudeCodeOptions(
|
|
416
|
+
allowed_tools=["Read", "Grep", "Glob"],
|
|
417
|
+
cwd="/path/to/project",
|
|
418
|
+
)
|
|
419
|
+
)
|
|
420
|
+
print(result)
|
|
421
|
+
|
|
422
|
+
asyncio.run(main())
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
### With streaming and callbacks
|
|
426
|
+
|
|
427
|
+
```python
|
|
428
|
+
import asyncio
|
|
429
|
+
import claude_agent_sdk as agent
|
|
430
|
+
from claude_agent_sdk import MessageParam, AssistantMessageParam
|
|
431
|
+
|
|
432
|
+
async def process_stream():
|
|
433
|
+
async with agent.run_stream(
|
|
434
|
+
prompt="Run the test suite and fix all failures",
|
|
435
|
+
options=agent.ClaudeCodeOptions(
|
|
436
|
+
allowed_tools=["Bash", "Read", "Edit"],
|
|
437
|
+
max_turns=20,
|
|
438
|
+
),
|
|
439
|
+
) as stream:
|
|
440
|
+
async for event in stream:
|
|
441
|
+
if event.type == "assistant":
|
|
442
|
+
for block in event.message.content:
|
|
443
|
+
if hasattr(block, "text"):
|
|
444
|
+
print(block.text, end="", flush=True)
|
|
445
|
+
elif event.type == "result":
|
|
446
|
+
print(f"\n\nFinal result: {event.result}")
|
|
447
|
+
print(f"Session: {event.session_id}")
|
|
448
|
+
print(f"Cost: ${event.cost_usd:.4f}")
|
|
449
|
+
|
|
450
|
+
asyncio.run(process_stream())
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### Multi-turn conversation
|
|
454
|
+
|
|
455
|
+
```python
|
|
456
|
+
import asyncio
|
|
457
|
+
import claude_agent_sdk as agent
|
|
458
|
+
|
|
459
|
+
async def multi_turn():
|
|
460
|
+
messages = []
|
|
461
|
+
|
|
462
|
+
# First turn
|
|
463
|
+
async with agent.run_stream(
|
|
464
|
+
prompt="Review the codebase for performance issues",
|
|
465
|
+
messages=messages,
|
|
466
|
+
options=agent.ClaudeCodeOptions(allowed_tools=["Read", "Grep", "Glob"]),
|
|
467
|
+
) as stream:
|
|
468
|
+
async for event in stream:
|
|
469
|
+
if hasattr(event, 'messages'):
|
|
470
|
+
messages.extend(event.messages)
|
|
471
|
+
|
|
472
|
+
# Continue the conversation
|
|
473
|
+
async with agent.run_stream(
|
|
474
|
+
prompt="Now suggest concrete fixes for the top 3 issues",
|
|
475
|
+
messages=messages, # Pass previous messages for context
|
|
476
|
+
options=agent.ClaudeCodeOptions(allowed_tools=["Read", "Edit"]),
|
|
477
|
+
) as stream:
|
|
478
|
+
async for event in stream:
|
|
479
|
+
if event.type == "assistant":
|
|
480
|
+
for block in event.message.content:
|
|
481
|
+
if hasattr(block, "text"):
|
|
482
|
+
print(block.text, end="", flush=True)
|
|
483
|
+
|
|
484
|
+
asyncio.run(multi_turn())
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
---
|
|
488
|
+
|
|
489
|
+
## Step 9: Agent SDK (TypeScript)
|
|
490
|
+
|
|
491
|
+
```bash
|
|
492
|
+
npm install @anthropic-ai/claude-code
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
```typescript
|
|
496
|
+
import { query, type Options } from "@anthropic-ai/claude-code";
|
|
497
|
+
|
|
498
|
+
async function reviewCode(projectPath: string) {
|
|
499
|
+
const options: Options = {
|
|
500
|
+
allowedTools: ["Read", "Grep", "Glob", "Bash"],
|
|
501
|
+
cwd: projectPath,
|
|
502
|
+
maxTurns: 15,
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
// One-shot
|
|
506
|
+
const result = await query({
|
|
507
|
+
prompt: "Review the authentication module for security issues",
|
|
508
|
+
options,
|
|
509
|
+
});
|
|
510
|
+
console.log(result);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// With streaming
|
|
514
|
+
async function streamReview(projectPath: string) {
|
|
515
|
+
const stream = query({
|
|
516
|
+
prompt: "Analyze and fix all TypeScript type errors",
|
|
517
|
+
options: {
|
|
518
|
+
allowedTools: ["Read", "Edit", "Bash(tsc *)"],
|
|
519
|
+
cwd: projectPath,
|
|
520
|
+
},
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
for await (const event of stream) {
|
|
524
|
+
if (event.type === "assistant") {
|
|
525
|
+
for (const block of event.message.content) {
|
|
526
|
+
if (block.type === "text") process.stdout.write(block.text);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (event.type === "result") {
|
|
530
|
+
console.log(`\nCost: $${event.cost_usd.toFixed(4)}`);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
---
|
|
537
|
+
|
|
538
|
+
## Step 10: Run Claude as an MCP Server
|
|
539
|
+
|
|
540
|
+
Expose Claude Code's tools to other applications:
|
|
541
|
+
|
|
542
|
+
```bash
|
|
543
|
+
# Start Claude Code as an MCP server
|
|
544
|
+
claude mcp serve
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
Add to Claude Desktop's `claude_desktop_config.json`:
|
|
548
|
+
```json
|
|
549
|
+
{
|
|
550
|
+
"mcpServers": {
|
|
551
|
+
"claude-code": {
|
|
552
|
+
"type": "stdio",
|
|
553
|
+
"command": "/usr/local/bin/claude",
|
|
554
|
+
"args": ["mcp", "serve"],
|
|
555
|
+
"env": {}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
This exposes Read, Edit, Bash, and other tools to any MCP client. The client is responsible for user confirmation.
|
|
562
|
+
|
|
563
|
+
---
|
|
564
|
+
|
|
565
|
+
## Step 11: Environment Variables
|
|
566
|
+
|
|
567
|
+
```bash
|
|
568
|
+
# Model selection
|
|
569
|
+
ANTHROPIC_MODEL=claude-opus-4-6 claude -p "..."
|
|
570
|
+
|
|
571
|
+
# Skip permission prompts (scripts/CI only — dangerous in interactive use)
|
|
572
|
+
CLAUDE_DANGEROUSLY_SKIP_PERMISSIONS=1 claude -p "..."
|
|
573
|
+
|
|
574
|
+
# Auto-compaction threshold (default: 95%)
|
|
575
|
+
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=70 claude -p "..."
|
|
576
|
+
|
|
577
|
+
# MCP timeout in milliseconds
|
|
578
|
+
MCP_TIMEOUT=30000 claude -p "..."
|
|
579
|
+
|
|
580
|
+
# Disable background tasks
|
|
581
|
+
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 claude -p "..."
|
|
582
|
+
|
|
583
|
+
# Disable claude.ai MCP servers
|
|
584
|
+
ENABLE_CLAUDEAI_MCP_SERVERS=false claude -p "..."
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
---
|
|
588
|
+
|
|
589
|
+
## Quick Reference
|
|
590
|
+
|
|
591
|
+
```bash
|
|
592
|
+
# Basic
|
|
593
|
+
claude -p "prompt"
|
|
594
|
+
|
|
595
|
+
# With tools
|
|
596
|
+
claude -p "prompt" --allowedTools "Read,Edit,Bash"
|
|
597
|
+
|
|
598
|
+
# JSON output
|
|
599
|
+
claude -p "prompt" --output-format json | jq -r '.result'
|
|
600
|
+
|
|
601
|
+
# Streaming
|
|
602
|
+
claude -p "prompt" --output-format stream-json --verbose --include-partial-messages
|
|
603
|
+
|
|
604
|
+
# Continue conversation
|
|
605
|
+
claude -p "prompt" --continue
|
|
606
|
+
claude -p "prompt" --resume "session-id"
|
|
607
|
+
|
|
608
|
+
# Custom system prompt
|
|
609
|
+
claude -p "prompt" --append-system-prompt "You are a..."
|
|
610
|
+
|
|
611
|
+
# Structured output
|
|
612
|
+
claude -p "extract data" --output-format json \
|
|
613
|
+
--json-schema '{"type":"object","properties":{"items":{"type":"array"}}}'
|
|
614
|
+
```
|