AI-powered code analysis and automated bug fixing using Claude Sonnet 4.5.
DevOps Agent combines static pattern analysis with AI-powered deep code review to identify security vulnerabilities, performance issues, code quality problems, and architectural concerns. It can automatically fix critical issues with high confidence.
Dual Analysis Modes
- Static analysis: Fast pattern-based detection (8 rules)
- AI analysis: Deep semantic understanding via Claude Sonnet 4.5
- Hybrid mode: Combines both for comprehensive coverage
Intelligent Chunking
- Automatically splits large responses into manageable chunks
- Handles files with 100+ issues without token limit errors
- Sequential processing maintains context across chunks
Auto-Fix Capability
- AI generates complete fixed code with explanations
- Confidence scoring (0-100%) for each fix
- Applies fixes sequentially to maintain file consistency
- Dry-run mode for preview before applying changes
Multiple Output Formats
- Console (default): Formatted with severity indicators
- JSON: Structured data for CI/CD integration
- Markdown: Detailed reports for documentation
npm install
npm run buildFor global access:
npm linkSet your Anthropic API key:
export ANTHROPIC_API_KEY=sk-ant-api03-...Or create .env file:
ANTHROPIC_API_KEY=sk-ant-api03-...
ANTHROPIC_MODEL=claude-sonnet-4-5-20250929
# Fast mode (static analysis only, free)
node dist/cli-ai.js ai-review ./src --mode fast
# Thorough mode (AI only, ~$1-2 per run)
node dist/cli-ai.js ai-review ./src --mode thorough
# Hybrid mode (both static + AI, ~$0.50-1)
node dist/cli-ai.js ai-review ./src --mode hybrid
# Save report to file
node dist/cli-ai.js ai-review ./src --mode thorough --output json --file report.json# Preview fixes without applying (dry-run)
node dist/cli-ai.js ai-fix ./src --dry-run
# Apply AI-generated fixes (only high/critical issues)
node dist/cli-ai.js ai-fix ./src
# Fix specific file
node dist/cli-ai.js ai-fix ./src/auth.js# Get AI explanation of code functionality
node dist/cli-ai.js explain ./src/complex-module.js# Fast pattern-based review (no API key needed)
node dist/cli.js review ./src
# Auto-fix static issues
node dist/cli.js fix ./src --dry-run- eval() usage
- Hardcoded credentials (API keys, passwords, tokens)
- var instead of let/const
- console.log and debugger statements
- Empty catch blocks
- TypeScript any types
- TODO comments
- SQL injection vulnerabilities
- XSS (Cross-Site Scripting) attacks
- CSRF vulnerabilities
- Race conditions in async code
- Memory leaks (event listeners, closures)
- N+1 query problems
- Uncontrolled resource consumption
- Missing input validation
- Information disclosure
- Missing rate limiting
- Authentication/authorization issues
- Business logic flaws
- Performance bottlenecks
- Architectural problems
AI-POWERED CODE REVIEW REPORT
Summary:
Total Issues: 148
Critical: 22
High: 45
Medium: 49
Low: 32
Auto-fixable: 32
Files Analyzed: 2
Issues by File:
sample-code.js
Line 5: [Security] Use of eval() with user input creates arbitrary code execution vulnerability
Fix: Remove eval() entirely. Use JSON.parse() for JSON data or redesign to avoid dynamic code execution.
Line 9: [Security] Hardcoded API key detected in source code
Fix: Move to environment variables: const apiKey = process.env.API_KEY;
advanced-test.js
Line 7: [Security] SQL Injection vulnerability - user input directly interpolated into query
Fix: Use parameterized queries: const query = 'SELECT * FROM users WHERE id = ?';
Line 12: [Concurrency] Race condition in withdraw() function - multiple calls can corrupt balance
Fix: Implement mutex locking or database transactions to ensure atomic operations.
Line 22: [Performance] Memory leak - event listeners never removed
Fix: Store bound references and call removeEventListener in cleanup method.
Line 37: [Performance] N+1 query problem - fetches posts individually for each user
Fix: Use eager loading or single query with JOIN to fetch all data at once.
When analyzing complex files, Claude may find 50+ issues. The system automatically:
- Instructs Claude to return max 10 issues per response with
hasMore: trueflag - Makes follow-up requests: "Continue from issue #11"
- Repeats until
hasMore: false - Combines all chunks into single comprehensive report
This prevents token limit errors and ensures complete analysis.
AI fixes are applied sequentially to maintain consistency:
- Analyze code and identify high/critical issues
- For each issue:
- Generate complete fixed code (not just diff)
- Calculate confidence score (0-100%)
- Apply if confidence > 70%
- Update working content for next fix
- Write final result to file
Each fix builds on previous fixes, preventing conflicts.
src/
├── ai-analyzer.ts # Claude API integration, chunking logic
├── ai-agent.ts # Orchestrates static + AI analysis
├── cli-ai.ts # AI-powered CLI commands
├── analyzer.ts # Static pattern rules
├── agent.ts # Basic agent (legacy)
├── cli.ts # Static CLI (legacy)
└── types.ts # TypeScript definitions
Key Components:
AIAnalyzer: Handles Claude API calls, response parsing, chunkingAIDevOpsAgent: Combines static and AI analysis, manages fix applicationCodeAnalyzer: Pattern-based static analysis (regex rules)
name: AI Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install
- run: npm run build
- name: AI Review
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
node dist/cli-ai.js ai-review ./src --mode thorough --output json --file review.json
- uses: actions/upload-artifact@v3
with:
name: code-review
path: review.json#!/bin/sh
# .git/hooks/pre-commit
export ANTHROPIC_API_KEY="your-key"
node dist/cli-ai.js ai-review ./src --mode fast
if [ $? -ne 0 ]; then
echo "Critical issues found. Fix before committing."
exit 1
fi| Mode | Speed | Cost | Use Case |
|---|---|---|---|
| Fast | < 1s | Free | Quick checks, CI/CD, pre-commit |
| Thorough | 1-3 min | $1-2 | Deep review, security audit |
| Hybrid | 1-2 min | $0.50-1 | Balanced coverage |
- Small file (~200 lines): ~2,000 tokens
- Medium file (~500 lines): ~5,000 tokens
- Large file (~1000 lines): ~10,000 tokens (chunked)
- Chunking prevents timeout errors on complex files
- Use
fastmode for frequent checks (CI/CD, git hooks) - Use
thoroughmode for weekly audits or major changes - Use
hybridmode for pull request reviews - Run AI analysis on changed files only to reduce costs
- AI analysis requires valid Anthropic API key
- Fixes require manual review before production deployment
- Pattern-based analysis may produce false positives
- AI may miss context-specific business logic issues
- Large files (>2000 lines) may need multiple chunks
- Confidence scores are estimates, not guarantees
- Fix generation takes 5-10 seconds per issue
# Build
npm run build
# Watch mode
npm run dev
# Run tests
npm testIf you like this project, please give it a star ⭐
For questions, feedback, or support, reach out to: