Skip to content

Commit b1b92fa

Browse files
authored
Merge pull request #10 from ohsono/feature/claude-code-integration
Add Claude Code GitHub Actions Integration
2 parents a0f46b0 + 9235177 commit b1b92fa

File tree

2 files changed

+738
-0
lines changed

2 files changed

+738
-0
lines changed
Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
# Claude Code Integration Setup Guide
2+
3+
This guide helps you set up the Claude Code GitHub Actions workflow with model restrictions to ensure cost-effective usage.
4+
5+
## 🎯 Key Features
6+
7+
- **Model Restriction**: Forces `claude-sonnet-4-20250514` (excludes premium Claude Opus 4)
8+
- **Usage Safeguards**: Token limits and file count restrictions
9+
- **Multiple Triggers**: PRs, pushes, and manual dispatch
10+
- **Comprehensive Analysis**: Code review, security, optimization, testing, documentation
11+
- **Automatic PR Comments**: Results posted directly to pull requests
12+
13+
## 📋 Setup Requirements
14+
15+
### 1. Add GitHub Secrets
16+
17+
Add authentication secrets to GitHub repository (Settings → Secrets and variables → Actions):
18+
19+
**Option 1: Claude Code OAuth Token (Recommended)**
20+
1. Click **New repository secret**
21+
2. Name: `CLAUDE_CODE_OAUTH_TOKEN`
22+
3. Value: Your Claude Code OAuth token
23+
24+
**Option 2: Anthropic API Key (Fallback)**
25+
1. Click **New repository secret**
26+
2. Name: `ANTHROPIC_API_KEY`
27+
3. Value: Your subscription-based Anthropic API key
28+
29+
**Note**: The workflow will use `CLAUDE_CODE_OAUTH_TOKEN` if available, otherwise fall back to `ANTHROPIC_API_KEY`.
30+
31+
### 2. Verify Workflow File
32+
33+
Ensure `.github/workflows/claude-code-integration.yml` exists in your repository.
34+
35+
## 🚀 Usage
36+
37+
### Automatic Triggers
38+
39+
#### Pull Request Analysis
40+
- **Trigger**: Opening/updating PRs to `main`, `staging`, or `dev`
41+
- **Action**: Analyzes only changed files
42+
- **Output**: PR comment with analysis results
43+
44+
#### Push Analysis
45+
- **Trigger**: Pushing to `main`, `staging`, `dev`, or `test-*` branches
46+
- **Action**: Analyzes entire codebase (limited to 50 files)
47+
- **Output**: Workflow artifacts
48+
49+
### Manual Triggers
50+
51+
#### Code Review
52+
```bash
53+
# Via GitHub UI: Actions → Claude Code Integration → Run workflow
54+
# Select: task_type = "code-review"
55+
```
56+
57+
#### Security Analysis
58+
```bash
59+
# Via GitHub UI: Actions → Claude Code Integration → Run workflow
60+
# Select: task_type = "security-analysis"
61+
```
62+
63+
#### Performance Optimization
64+
```bash
65+
# Via GitHub UI: Actions → Claude Code Integration → Run workflow
66+
# Select: task_type = "code-optimization"
67+
```
68+
69+
#### Testing Suggestions
70+
```bash
71+
# Via GitHub UI: Actions → Claude Code Integration → Run workflow
72+
# Select: task_type = "testing-suggestions"
73+
```
74+
75+
#### Documentation Review
76+
```bash
77+
# Via GitHub UI: Actions → Claude Code Integration → Run workflow
78+
# Select: task_type = "documentation-review"
79+
```
80+
81+
#### Custom Analysis
82+
```bash
83+
# Via GitHub UI: Actions → Claude Code Integration → Run workflow
84+
# Select: task_type = "custom-prompt"
85+
# Enter your custom prompt in the custom_prompt field
86+
```
87+
88+
## ⚡ Configuration Options
89+
90+
### Manual Dispatch Parameters
91+
92+
| Parameter | Description | Default | Options |
93+
|-----------|-------------|---------|---------|
94+
| `task_type` | Type of analysis | `code-review` | `code-review`, `security-analysis`, `code-optimization`, `testing-suggestions`, `documentation-review`, `custom-prompt` |
95+
| `custom_prompt` | Custom analysis prompt | `` | Any text |
96+
| `target_files` | Specific files to analyze | `` | Comma-separated file paths |
97+
| `max_tokens` | Token usage limit | `10000` | Number (1-50000) |
98+
99+
### Safety Limits
100+
101+
| Limit | Value | Purpose |
102+
|-------|-------|---------|
103+
| Max tokens per run | 10,000 | Cost control |
104+
| Max files per run | 50 | Performance |
105+
| Model restriction | `claude-sonnet-4-20250514` | Exclude premium models |
106+
107+
## 📊 Analysis Types
108+
109+
### 1. Code Review (Default)
110+
- Security vulnerabilities
111+
- Code quality issues
112+
- Performance bottlenecks
113+
- Bug detection
114+
- Architecture feedback
115+
116+
### 2. Security Analysis
117+
- OWASP vulnerability categories
118+
- Data protection issues
119+
- Access control problems
120+
- Input validation gaps
121+
- Dependency vulnerabilities
122+
123+
### 3. Code Optimization
124+
- Performance improvements
125+
- Memory optimization
126+
- Database query optimization
127+
- Network efficiency
128+
- Refactoring opportunities
129+
130+
### 4. Testing Suggestions
131+
- Test coverage analysis
132+
- Unit test recommendations
133+
- Integration test scenarios
134+
- Edge case identification
135+
- Mock strategy suggestions
136+
137+
### 5. Documentation Review
138+
- Code comment quality
139+
- API documentation
140+
- README improvements
141+
- Architecture documentation
142+
- Missing documentation
143+
144+
## 🔒 Security Best Practices
145+
146+
1. **API Key Management**
147+
- Use GitHub secrets (never commit keys)
148+
- Use subscription-based keys only
149+
- Rotate keys regularly
150+
151+
2. **Model Restrictions**
152+
- Workflow enforces `claude-sonnet-4-20250514`
153+
- Premium models (Opus 4) are excluded
154+
- Usage monitoring tracks model usage
155+
156+
3. **Access Control**
157+
- Workflow requires `contents: read` permission
158+
- PR comments require `pull-requests: write`
159+
- No write access to repository code
160+
161+
## 📈 Usage Monitoring
162+
163+
The workflow automatically logs:
164+
- Model used (`claude-sonnet-4-20250514`)
165+
- Token consumption
166+
- Files analyzed
167+
- Trigger type
168+
- Repository and branch info
169+
170+
## 🛠️ Troubleshooting
171+
172+
### Common Issues
173+
174+
#### "Neither CLAUDE_CODE_OAUTH_TOKEN nor ANTHROPIC_API_KEY secrets are configured"
175+
**Solution**: Add either `CLAUDE_CODE_OAUTH_TOKEN` (preferred) or `ANTHROPIC_API_KEY` to GitHub repository secrets
176+
177+
#### "Too many files changed"
178+
**Solution**: Workflow automatically limits to 50 files for safety
179+
180+
#### "Claude CLI installation failed"
181+
**Solution**: Check GitHub Actions logs for detailed error messages
182+
183+
#### "Model not supported"
184+
**Solution**: Workflow forces `claude-sonnet-4-20250514` - ensure your API key supports this model
185+
186+
### Debug Steps
187+
188+
1. **Check workflow logs** in GitHub Actions tab
189+
2. **Verify authentication** - ensure either `CLAUDE_CODE_OAUTH_TOKEN` or `ANTHROPIC_API_KEY` is set in repository secrets
190+
3. **Test locally** with Claude CLI if needed
191+
4. **Check file permissions** for target files
192+
193+
## 💰 Cost Management
194+
195+
### Cost-Saving Features
196+
- **Model restriction** prevents expensive Opus 4 usage
197+
- **Token limits** cap maximum usage per run
198+
- **File limits** prevent analyzing too many files
199+
- **Smart triggering** only analyzes changed files in PRs
200+
201+
### Usage Optimization
202+
- Use **PR analysis** for incremental review
203+
- Use **manual dispatch** for specific analysis needs
204+
- Set **lower token limits** for quick reviews
205+
- Target **specific files** when possible
206+
207+
## 🔄 Workflow Outputs
208+
209+
### PR Comments
210+
- Analysis results posted automatically
211+
- Truncated if too long (full results in artifacts)
212+
- Includes metadata (model used, file count, etc.)
213+
214+
### Artifacts
215+
- **Full analysis results** (`analysis_result.md`)
216+
- **File list** (`code_files.txt`)
217+
- **30-day retention** period
218+
219+
## 📚 Examples
220+
221+
### Example PR Comment
222+
```markdown
223+
## 🤖 Claude Code Analysis Results
224+
225+
> **Model Used**: `claude-sonnet-4-20250514` (Premium models excluded)
226+
> **Analysis Type**: `code-review`
227+
228+
### Security Issues Found
229+
- **HIGH**: SQL injection vulnerability in user_service.py:45
230+
- **MEDIUM**: Unvalidated input in auth.py:123
231+
232+
### Performance Improvements
233+
- **Optimize database queries** in dashboard.py:67
234+
- **Add caching** for frequently accessed data
235+
236+
### Code Quality
237+
- **Improve error handling** in api_client.py:34
238+
- **Add type hints** to utility functions
239+
```
240+
241+
### Example Custom Prompt
242+
```
243+
Analyze the code for accessibility issues and provide suggestions for improving web accessibility compliance with WCAG 2.1 guidelines.
244+
```
245+
246+
## 🎯 Next Steps
247+
248+
1. **Add authentication** to GitHub secrets (either `CLAUDE_CODE_OAUTH_TOKEN` or `ANTHROPIC_API_KEY`)
249+
2. **Test with a PR** to verify setup
250+
3. **Customize analysis types** based on your needs
251+
4. **Set up regular security scans** using scheduled workflows
252+
5. **Monitor usage** through workflow logs
253+
254+
## 📞 Support
255+
256+
- **GitHub Issues**: Report problems in the repository
257+
- **Workflow Logs**: Check GitHub Actions for detailed error messages
258+
- **Claude Code Docs**: https://docs.anthropic.com/claude-code
259+
- **API Documentation**: https://docs.anthropic.com/api

0 commit comments

Comments
 (0)