All DevOps examples now use Claude AI by default for intelligent analysis. Follow these steps:
- Go to: https://console.anthropic.com/settings/keys
- Create a new API key
- Copy the key (starts with
sk-ant-)
# Option A: Create .env file (recommended)
cp .env.example .env
# Edit .env and add your CLAUDE_API_KEY
# Option B: Export directly
export CLAUDE_API_KEY="sk-ant-your-key-here"
export CLAUDE_DEBUG_LOGGING=true # To see all prompts/responses# Using the run script (recommended - handles everything)
cd cost-optimizer
./run.sh
# Or run directly with environment
source ../setup-env.sh
./cost-optimizer- Intelligent cost analysis based on actual usage patterns
- Risk assessment for each recommendation (low/medium/high)
- Specific optimization actions with expected savings
- Context-aware suggestions based on your infrastructure
- Root cause analysis of configuration drift
- Automated fix recommendations with safety ratings
- Pattern recognition for recurring drift issues
# Disable for one run
ENABLE_CLAUDE=false ./run.sh
# Or export for session
export ENABLE_CLAUDE=false
./cost-optimizer# In .env file, change:
ENABLE_CLAUDE=false// In main.go, comment out Claude initialization:
// app.Claude = sdk.NewClaudeClient(os.Getenv("CLAUDE_API_KEY"))Claude debug logging is enabled by default to show all prompts and responses.
export CLAUDE_DEBUG_LOGGING=true # Already default
./cost-optimizerOutput will show:
[Claude] req-1 ◀ FULL_PROMPT:
Analyze the following Kubernetes resource usage...
[Claude] req-1 ▶ FULL_RESPONSE:
{
"total_monthly_cost": 922.00,
"recommendations": [...]
}
export CLAUDE_DEBUG_LOGGING=falseWhen debug logging is enabled, you'll see:
- Request Counter:
req-1,req-2, etc. - Full Prompts: Complete text sent to Claude
- Full Responses: Complete JSON/text returned
- Timing: Duration of each API call
- Errors: Any API failures with details
Example log output:
[Claude] 🔍 Debug logging enabled - all prompts and responses will be logged
[Claude] req-1 ◀ REQUEST: Analyze the following Kubernetes resource usage data...
[Claude] req-1 ◀ FULL_PROMPT:
Analyze the following Kubernetes resource usage data and provide cost optimization recommendations.
Focus on:
1. Resources with low utilization (<50%)...
[Claude] req-1 → Sending API request
[Claude] req-1 ▶ RESPONSE (1.2s): {"total_monthly_cost": 922.00, "potential_savings": 208.95...
[Claude] req-1 ▶ FULL_RESPONSE:
{
"total_monthly_cost": 922.00,
"potential_savings": 208.95,
"savings_percentage": 22.8,
"recommendations": [
{
"resource": "deployment/frontend-web",
"priority": "high",
"monthly_savings": 73.65,
"risk": "low",
"explanation": "Frontend is over-provisioned..."
}
]
}
ConfigHub is also enabled by default. Authentication happens automatically:
# Token is obtained automatically from cub CLI
# Or set manually:
export CUB_TOKEN=$(cub auth get-token)Every example follows this pattern:
- run.sh script - Handles all setup automatically
- Claude enabled by default - With easy disable option
- Debug logging by default - See all AI interactions
- ConfigHub integration - Automatic authentication
- Fallback to basic - Works without Claude if needed
# Check your key is exported
echo $CLAUDE_API_KEY
# Or add to .env file
echo "CLAUDE_API_KEY=sk-ant-your-key" >> .envYour API key is invalid. Get a new one from https://console.anthropic.com/settings/keys
Check debug logs for details:
export CLAUDE_DEBUG_LOGGING=true
./run.sh- Claude API calls cost ~$0.25 per 1M input tokens
- Each analysis typically uses ~2-5K tokens
- Cost optimizer runs analysis every 30 seconds
- Approximate cost: $0.01-0.02 per hour of operation
To reduce costs:
- Increase analysis interval in code
- Use ENABLE_CLAUDE=false for development
- Enable only for production monitoring