Troubleshooting Guide
April 19, 2026 ยท View on GitHub
This guide helps you diagnose and resolve common issues with ccflare.
Table of Contents
- OAuth Authentication Problems
- Rate Limiting Issues
- Connection Problems
- Performance Issues
- Account Management Issues
- Configuration Problems
- Database Issues
- Streaming and Analytics Issues
- Logging and Debugging
- Common Error Messages
- Environment Variables Reference
- FAQ
- Getting Help
OAuth Authentication Problems
Invalid Tokens
Symptom: Requests fail with 401 Unauthorized errors
Error Message: Failed to refresh access token
Solutions:
-
Check if the access token has expired:
ccflare --listLook for accounts with expired tokens (expires_at in the past)
-
Refresh the token manually:
- Remove and re-add the account:
ccflare --remove <account-name> ccflare --add-account <account-name>
- Remove and re-add the account:
-
Verify the refresh token is still valid in your Anthropic console
Expired Tokens
Symptom: Token refresh attempts fail repeatedly
Error Message: Token expired or missing for account: [name]
Solutions:
- ccflare automatically attempts to refresh expired tokens
- If automatic refresh fails, re-authenticate the account
- Check for refresh token stampede prevention - multiple simultaneous refresh attempts are prevented
PKCE Failures
Symptom: OAuth authorization fails during account setup
Error Messages:
Token exchange failed: [error]Invalid code_verifierRefresh promise not found for account
Solutions:
- Ensure you're using the complete authorization code including the state fragment (format:
code#state) - Don't modify or truncate the authorization code
- Complete the OAuth flow within the time limit (codes expire quickly)
- Try the authorization flow again from the beginning
- Ensure only one refresh attempt happens at a time (refresh stampede prevention is active)
Token Refresh Failures
Symptom: Automatic token refresh fails
Error Messages:
Failed to refresh access tokenToken refresh failed: [error]
Solutions:
- Check if the refresh token was revoked in your Anthropic console
- Verify the CLIENT_ID environment variable matches your OAuth app
- Remove and re-add the account:
ccflare --remove <account-name> ccflare --add-account <account-name> - Check for multiple simultaneous refresh attempts in logs
Rate Limiting Issues
Identifying Rate Limits
ccflare detects rate limits through response headers and HTTP status codes:
- Rate Limited Responses:
- HTTP 429 responses
- Rate limit headers in responses
- Account is marked unavailable for selection
How to Check Rate Limit Status:
# View account status including rate limits
ccflare --list
# Check logs for rate limit messages
cat /tmp/ccflare-logs/app.log | grep "rate limited"
# View rate limit reset times in the dashboard
curl http://localhost:8080/api/accounts | jq '.[] | {name, rate_limit_status, rate_limit_reset}'
Recovery Strategies
When an account is rate-limited:
- ccflare automatically rotates to the next available account
- Rate-limited accounts are marked with a reset timestamp
- Accounts automatically become available again after the reset time
Manual recovery steps:
-
Add more accounts to your pool:
ccflare --add-account account2 -
Check rate limit reset times in the dashboard:
http://localhost:8080 -
Monitor account-specific rate limits:
# View rate limit details for each account ccflare --list # Look for rate_limit_status and rate_limit_reset columns -
Pause/resume accounts as needed:
ccflare --pause <account-name> ccflare --resume <account-name>
Connection Problems
Network Timeouts
Symptom: Requests hang or timeout
Error Messages:
ECONNREFUSEDETIMEDOUTFailed to forward unauthenticated requestAll accounts failed to proxy the request
Solutions:
- Check your internet connection
- Verify the Anthropic API is accessible:
curl -I https://api.anthropic.com/v1/messages - Check proxy settings if behind a corporate firewall
- Increase retry configuration in config file
Proxy Configuration
Configuring HTTP proxy:
# Set proxy environment variables before starting
export HTTP_PROXY=http://proxy.company.com:8080
export HTTPS_PROXY=http://proxy.company.com:8080
bun start
Bypass proxy for local requests:
export NO_PROXY=localhost,127.0.0.1
Performance Issues
Slow Responses
Symptoms:
- High response times in logs
- Dashboard shows increased latency
Solutions:
-
Check account distribution:
- Ensure accounts aren't all rate-limited
- Verify load balancing strategy is appropriate
-
Optimize retry settings:
{ "retry_attempts": 2, "retry_delay_ms": 500, "retry_backoff": 1.5 } -
Use session-based routing for conversational workloads:
# Set strategy to session for better performance with conversations # Session is the default and only supported strategy
High Memory Usage
Symptom: Process consuming excessive memory
Solutions:
-
Check log file size (auto-rotates at 10MB):
ls -lh /tmp/ccflare-logs/app.log -
Clear request history:
ccflare --clear-history -
Restart the server to clear in-memory caches:
# Graceful shutdown with Ctrl+C # Then restart bun start # Or ccflare --serve
Account Management Issues
Account Not Being Used
Symptom: Specific account never receives requests
Check:
-
Account status:
ccflare --list # Look for: paused, rate_limited, or expired -
Session persistence:
- Check if account has an active session
- Verify session hasn't expired
Solutions:
- Resume the account if paused:
ccflare --resume <account-name> - Wait for rate limit to reset
- Re-add the account if expired
Account Selection Problems
Symptom: Uneven distribution of requests
Solutions:
-
Check current strategy:
# Session strategy is the default and only supported strategy -
Session strategy behavior:
session: Maintains 1-hour sessions with individual accounts (default: 3600000ms)- This is the only supported strategy to avoid account bans
- Adjust session_duration_ms if needed
Configuration Problems
Config File Location
Default locations by platform:
- macOS:
~/.config/ccflare/ccflare.json - Linux:
~/.config/ccflare/ccflare.json - Windows:
%LOCALAPPDATA%\ccflare\ccflare.jsonor%APPDATA%\ccflare\ccflare.json
Invalid Configuration
Symptom: Server fails to start or uses default values
Error Messages:
Failed to parse config fileInvalid strategy: [name]
Solutions:
-
Validate JSON syntax:
cat ~/.config/ccflare/ccflare.json | jq . -
Reset to defaults:
# Backup current config cp ~/.config/ccflare/ccflare.json ~/.config/ccflare/config.backup.json # Remove corrupted config rm ~/.config/ccflare/ccflare.json # Restart server to create new config bun start
Environment Variable Override
Environment variables override config file settings:
CLIENT_ID: OAuth client IDPORT: Server port (default: 8080)LB_STRATEGY: Load balancing strategyRETRY_ATTEMPTS: Number of retry attemptsRETRY_DELAY_MS: Initial retry delaySESSION_DURATION_MS: Session duration for session strategy
Database Issues
Database Path Problems
Symptom: Server fails to start with database errors
Error Messages:
Database file not foundPermission deniedCannot create database
Solutions:
-
Check database file permissions:
# macOS/Linux ls -la ~/.config/ccflare/ccflare.db # Windows dir %LOCALAPPDATA%\ccflare\ccflare.db -
Create the directory if it doesn't exist:
# macOS/Linux mkdir -p ~/.config/ccflare # Windows mkdir %LOCALAPPDATA%\ccflare -
Use a custom database path:
export ccflare_DB_PATH=/path/to/custom/ccflare.db bun start
Database Migration Failures
Symptom: Server logs show migration errors
Error Messages:
ALTER TABLE failedColumn already existsMigration failed
Solutions:
-
The migration system is idempotent - errors about existing columns are harmless
-
If migrations fail repeatedly:
# Backup existing database cp ~/.config/ccflare/ccflare.db ~/.config/ccflare/ccflare.db.backup # Remove and let it recreate rm ~/.config/ccflare/ccflare.db bun start -
Check for database corruption:
sqlite3 ~/.config/ccflare/ccflare.db "PRAGMA integrity_check;"
Async Database Writer Issues
Symptom: Database writes appear delayed or missing
Error Messages:
Failed to execute DB jobAsync DB writer queue flushed
Solutions:
- The async writer batches writes every 100ms for performance
- During shutdown, ensure graceful termination (Ctrl+C) to flush pending writes
- Check logs for async writer errors:
grep "async-db-writer" /tmp/ccflare-logs/app.log
Database Lock Errors
Symptom: Multiple processes accessing the database
Error Messages:
database is lockedSQLITE_BUSY
Solutions:
-
Ensure only one instance of ccflare is running:
ps aux | grep "bun start" | grep -v grep ps aux | grep "ccflare --serve" | grep -v grep -
Kill any zombie processes:
pkill -f "bun start" pkill -f "ccflare --serve" -
Check for hanging database connections:
lsof ~/.config/ccflare/ccflare.db
Streaming and Analytics Issues
Streaming Response Capture Problems
Symptom: Analytics data missing for streaming responses
Error Messages:
Stream tee errorFailed to capture streaming responseBuffer truncated at 1MB
Solutions:
- Streaming responses are captured up to 1MB for analytics
- Large responses will be truncated but still forwarded completely to the client
- Check if streaming is working:
# Look for streaming response logs grep "Streaming response" /tmp/ccflare-logs/app.log
Analytics Data Issues
Symptom: Dashboard shows incorrect or missing analytics
Error Messages:
Failed to fetch analytics dataAnalytics error:
Solutions:
-
Check if requests are being recorded:
# Count recent requests in database sqlite3 ~/.config/ccflare/ccflare.db "SELECT COUNT(*) FROM requests WHERE timestamp > strftime('%s', 'now', '-1 hour') * 1000;" -
Verify analytics endpoint:
# Test analytics API curl "http://localhost:8080/api/analytics?range=1h" -
Clear and rebuild analytics data:
ccflare --clear-history -
Reset account statistics without clearing history:
ccflare --reset-stats
Usage Tracking Problems
Symptom: Token usage and costs not updating
Solutions:
-
Usage is extracted from response headers and streaming data
-
Check for usage extraction errors:
grep "extractUsageInfo" /tmp/ccflare-logs/app.log -
Verify model pricing data:
# Pricing updates every 24 hours by default grep "Fetching latest pricing" /tmp/ccflare-logs/app.log
Logging and Debugging
Log File Locations
Logs are stored in the system's temporary directory:
- All platforms:
/tmp/ccflare-logs/app.log - Windows:
%TEMP%\ccflare-logs\app.log
Enabling Debug Mode
Method 1: Environment Variable
export ccflare_DEBUG=1
export LOG_LEVEL=DEBUG
bun start
Method 2: Verbose Logging
# View real-time logs
tail -f /tmp/ccflare-logs/app.log
Log Formats
JSON Format (for parsing):
export LOG_FORMAT=json
bun start
Pretty Format (default):
[2024-01-20T10:30:45.123Z] INFO: [Proxy] Request completed for account1: 200 in 1234ms
Reading Logs
Filter by log level:
# View only errors
grep "ERROR" /tmp/ccflare-logs/app.log
# View warnings and errors
grep -E "WARN|ERROR" /tmp/ccflare-logs/app.log
Filter by component:
# View only proxy logs
grep "\[Proxy\]" /tmp/ccflare-logs/app.log
# View only server logs
grep "\[Server\]" /tmp/ccflare-logs/app.log
Common Error Messages
Authentication and Token Errors
"No active accounts available - forwarding request without authentication"
Meaning: All accounts are either paused, rate-limited, or expired
Solution:
- Add new accounts or wait for rate limits to reset
- Check account status:
ccflare --list - Requests will be forwarded without authentication (may fail)
"Refresh promise not found for account"
Meaning: Internal error during token refresh process
Solution:
- Restart the server to clear refresh state
- Check for concurrent refresh attempts in logs
"Failed to refresh access token"
Meaning: OAuth refresh token is invalid or revoked
Solution:
- Remove and re-add the account
- Check if the OAuth app still has permissions in Anthropic console
Request Processing Errors
"Provider cannot handle path"
Meaning: Request path doesn't match expected Anthropic API patterns
Solution:
- Ensure requests are to
/v1/*endpoints - Check if you're using the correct base URL
- Valid paths:
/v1/messages,/v1/complete, etc.
"All accounts failed to proxy the request"
Meaning: Every account attempted but all failed
Response:
{
"error": "All accounts failed to proxy the request",
"attempts": 3,
"lastError": "Error message here"
}
Solutions:
- Check individual account errors in logs
- Verify network connectivity
- Ensure at least one account has valid credentials
- Check for API outages
"Failed to forward unauthenticated request"
Meaning: Request forwarding without authentication failed
Solutions:
- Check network connectivity
- Verify Anthropic API is accessible
- Check for proxy configuration issues
- Look for timeout errors in logs
"Failed to proxy request with account"
Meaning: Error occurred while proxying with a specific account
Solutions:
- Check the specific account's status
- Look for token expiration or rate limits
- Verify network connectivity
Database Errors
"Failed to execute DB job"
Meaning: Async database write failed
Solutions:
- Check disk space
- Verify database file permissions
- Look for detailed error in logs
"database is locked"
Meaning: Another process is accessing the database
Solutions:
- Ensure only one ccflare instance is running
- Kill any zombie processes
- Wait for current operations to complete
Analytics and Streaming Errors
"Stream tee error"
Meaning: Failed to capture streaming response for analytics
Solutions:
- This doesn't affect the actual response to the client
- Check for memory issues if frequent
- Large responses may exceed 1MB capture limit
"Failed to fetch analytics data"
Meaning: Analytics query failed
Solutions:
- Check if database is accessible
- Verify time range parameters
- Clear history if data is corrupted:
ccflare --clear-history
Configuration Errors
"Failed to parse config file"
Meaning: JSON syntax error in config file
Solutions:
- Validate JSON syntax:
cat ~/.config/ccflare/ccflare.json | jq . - Check for trailing commas or missing quotes
- Reset to defaults by deleting config file
"Invalid strategy: [name]"
Meaning: Unknown load balancing strategy specified
Solutions:
- Only valid strategy:
session - Check spelling in config or environment variable
- The default is already
session
HTTP Status Codes
400 Bad Request
Common Causes:
- Invalid request format
- Missing required parameters
- Invalid account name or ID
401 Unauthorized
Common Causes:
- Expired access token
- Invalid OAuth credentials
- No active accounts available
403 Forbidden
Common Causes:
- Account doesn't have required permissions
- OAuth app restrictions
429 Too Many Requests
Common Causes:
- Account rate limited
- All accounts exhausted
- Check rate limit headers for reset time
500 Internal Server Error
Common Causes:
- Unexpected server error
- Database connection issues
- Check logs for stack trace
Startup Errors
"Address already in use"
Meaning: Port is already occupied
Solutions:
- Check if another instance is running:
lsof -i :8080 - Use a different port:
PORT=3000 bun start - Kill the process using the port
"Cannot create database"
Meaning: Unable to create or access database file
Solutions:
- Check directory permissions
- Ensure parent directory exists
- Use custom path:
export ccflare_DB_PATH=/custom/path/db.db
Environment Variables Reference
Core Configuration
| Variable | Description | Default | Example |
|---|---|---|---|
CLIENT_ID | OAuth client ID for Anthropic | None | my-oauth-client-id |
PORT | Server port | 8080 | 3000 |
LB_STRATEGY | Load balancing strategy | session | Only session is supported |
RETRY_ATTEMPTS | Number of retry attempts | 3 | 5 |
RETRY_DELAY_MS | Initial retry delay in ms | 1000 | 500 |
RETRY_BACKOFF | Retry backoff multiplier | 2 | 1.5 |
SESSION_DURATION_MS | Session duration for session strategy | 3600000 (1 hour) | 1800000 |
Paths and Storage
| Variable | Description | Default | Example |
|---|---|---|---|
ccflare_CONFIG_PATH | Custom config file location | Platform-specific | /opt/ccflare/config.json |
ccflare_DB_PATH | Custom database location | Platform-specific | /opt/ccflare/data.db |
Logging and Debugging
| Variable | Description | Default | Example |
|---|---|---|---|
ccflare_DEBUG | Enable debug mode | 0 | 1 |
LOG_LEVEL | Log level | INFO | DEBUG, WARN, ERROR |
LOG_FORMAT | Log format | pretty | json |
Proxy Settings
| Variable | Description | Default | Example |
|---|---|---|---|
HTTP_PROXY | HTTP proxy URL | None | http://proxy.company.com:8080 |
HTTPS_PROXY | HTTPS proxy URL | None | http://proxy.company.com:8080 |
NO_PROXY | Bypass proxy for hosts | None | localhost,127.0.0.1 |
Advanced Settings
| Variable | Description | Default | Example |
|---|---|---|---|
CF_PRICING_REFRESH_HOURS | Hours between pricing updates | 24 | 12 |
Usage Examples
# Development setup with debug logging
export ccflare_DEBUG=1
export LOG_LEVEL=DEBUG
export LOG_FORMAT=json
bun start
# Production setup with custom paths
export ccflare_CONFIG_PATH=/etc/ccflare/config.json
export ccflare_DB_PATH=/var/lib/ccflare/data.db
export PORT=3000
bun start
# Corporate proxy setup
export HTTP_PROXY=http://proxy.corp.com:8080
export HTTPS_PROXY=http://proxy.corp.com:8080
export NO_PROXY=localhost,127.0.0.1,internal.corp.com
bun start
FAQ
Q: How do I know if ccflare is working?
A: Check the health endpoint:
curl http://localhost:8080/health
Expected response:
{
"status": "ok",
"accounts": {
"total": 3,
"active": 2,
"paused": 1
},
"uptime": 3600000
}
Q: Can I use ccflare with multiple client applications?
A: Yes, ccflare acts as a transparent proxy. Point any Claude API client to http://localhost:8080 instead of https://api.anthropic.com.
Q: How do I backup my accounts?
A: The account data is stored in the SQLite database. Backup locations:
- macOS/Linux:
~/.config/ccflare/ccflare.db - Windows:
%LOCALAPPDATA%\ccflare\ccflare.dbor%APPDATA%\ccflare\ccflare.db
Q: What happens during a graceful shutdown?
A: When receiving SIGINT (Ctrl+C) or SIGTERM:
- Stops accepting new requests
- Waits for in-flight requests to complete (with timeout)
- Flushes async database writer queue
- Closes database connections
- Flushes logs to disk
- Exits cleanly
Q: How do I migrate to a new machine?
A: Copy these files to the new machine:
- Database file (
ccflare.db) - Config file (
ccflare.json) - Set the same CLIENT_ID environment variable
- Ensure Bun is installed on the new machine
Q: Why is my analytics data missing or incorrect?
A: Several reasons can cause analytics issues:
- Streaming responses are only captured up to 1MB
- Database writes are async and may be delayed
- Usage data depends on response headers from Anthropic
- Check if requests are being recorded:
sqlite3 ~/.config/ccflare/ccflare.db "SELECT COUNT(*) FROM requests;"
Q: How do I handle rate limits effectively?
A: Best practices for rate limit handling:
- Add multiple accounts to your pool
- Maintain proper session duration (default 1 hour)
- Monitor rate limit warnings in logs
- Set up alerts for rate-limited accounts
- Consider implementing request queuing in your application
Q: Can I use ccflare in production?
A: Yes, with these considerations:
- Use environment variables for sensitive configuration
- Set up proper logging and monitoring
- Use a persistent database path (not /tmp)
- Configure appropriate retry settings
- Add sufficient accounts for your load
- Use systemd or similar for process management
Q: Why are some accounts not being used?
A: Accounts may be skipped for several reasons:
- Paused: Manually paused via CLI
- Rate Limited: Temporarily unavailable due to rate limits
- Expired Token: Needs re-authentication
- Session: Account may have an active session
- Check status:
ccflare --list
Q: How do I troubleshoot slow responses?
A: Steps to diagnose performance issues:
- Check response times in logs or analytics
- Verify no accounts are rate limited
- Look for retry attempts in logs
- Consider session duration settings
- Check network latency to Anthropic API
- Monitor database performance
Q: What's the difference between running with bun start vs ccflare --serve?
A: Both commands start the server:
bun start: Runs the server using the npm scriptccflare --serve: Runs the server directly via the CLI binary- Both are functionally equivalent
Getting Help
Reporting Bugs
When reporting issues, include:
-
System Information:
bun --version node --version echo $OSTYPE -
Error Logs:
# Last 100 lines of logs tail -n 100 /tmp/ccflare-logs/app.log -
Configuration (sanitized):
# Remove sensitive data before sharing cat ~/.config/ccflare/ccflare.json | jq 'del(.client_id)' -
Steps to Reproduce:
- Exact commands run
- Expected behavior
- Actual behavior
Debug Information Script
Save this as debug-info.sh:
#!/bin/bash
echo "=== ccflare Debug Info ==="
echo "Date: $(date)"
echo "System: $(uname -a)"
echo "Bun Version: $(bun --version)"
echo "Node Version: $(node --version 2>/dev/null || echo 'Node not installed')"
echo ""
echo "=== Environment Variables ==="
env | grep -E "ccflare|CLIENT_ID|PORT|LB_STRATEGY|LOG_|PROXY" | sort
echo ""
echo "=== Process Info ==="
ps aux | grep -E "bun start|ccflare" | grep -v grep
echo ""
echo "=== Port Check ==="
lsof -i :${PORT:-8080} 2>/dev/null || echo "Port ${PORT:-8080} not in use"
echo ""
echo "=== Database Info ==="
if [ -f "$HOME/.config/ccflare/ccflare.db" ]; then
echo "Database size: $(du -h "$HOME/.config/ccflare/ccflare.db" | cut -f1)"
echo "Request count: $(sqlite3 "$HOME/.config/ccflare/ccflare.db" "SELECT COUNT(*) FROM requests;" 2>/dev/null || echo "Could not query")"
echo "Account count: $(sqlite3 "$HOME/.config/ccflare/ccflare.db" "SELECT COUNT(*) FROM accounts;" 2>/dev/null || echo "Could not query")"
else
echo "Database not found at default location"
fi
echo ""
echo "=== Recent Errors (last 24h) ==="
if [ -f "/tmp/ccflare-logs/app.log" ]; then
grep "ERROR" /tmp/ccflare-logs/app.log | tail -20
else
echo "Log file not found"
fi
echo ""
echo "=== Recent Rate Limits ==="
if [ -f "/tmp/ccflare-logs/app.log" ]; then
grep -E "rate.?limit" /tmp/ccflare-logs/app.log | tail -10
else
echo "Log file not found"
fi
echo ""
echo "=== Account Status ==="
ccflare --list 2>/dev/null || echo "Could not get account list"
echo ""
echo "=== API Health Check ==="
curl -s http://localhost:${PORT:-8080}/health | jq . 2>/dev/null || echo "Health check failed"
echo ""
echo "=== Recent Analytics (1h) ==="
curl -s "http://localhost:${PORT:-8080}/api/analytics?range=1h" | jq '.overview' 2>/dev/null || echo "Analytics unavailable"
Make the script executable:
chmod +x debug-info.sh
./debug-info.sh > debug-report.txt
Community Support
- Check existing issues in the repository
- Review this troubleshooting guide
- Search logs for specific error messages
- Try running in debug mode for more details
Performance Monitoring
Monitor key metrics via the dashboard API:
# Get current stats
curl http://localhost:8080/api/stats | jq .
# Get request history with filters
curl "http://localhost:8080/api/requests?limit=10&status=error" | jq .
# Get analytics with time ranges
curl "http://localhost:8080/api/analytics?range=1h" | jq .
curl "http://localhost:8080/api/analytics?range=24h" | jq .
curl "http://localhost:8080/api/analytics?range=7d" | jq .
# Get analytics with filters
curl "http://localhost:8080/api/analytics?range=1h&model=claude-3-opus&status=success" | jq .
# Monitor real-time logs
tail -f /tmp/ccflare-logs/app.log | grep -E "INFO|WARN|ERROR"
Quick Troubleshooting Checklist
When experiencing issues, check these in order:
-
Service Health
curl http://localhost:8080/health -
Account Status
ccflare --list -
Recent Errors
grep ERROR /tmp/ccflare-logs/app.log | tail -20 -
Rate Limits
grep "rate.?limit" /tmp/ccflare-logs/app.log | tail -10 -
Network Connectivity
curl -I https://api.anthropic.com/v1/messages -
Database Health
sqlite3 ~/.config/ccflare/ccflare.db "PRAGMA integrity_check;"
Common Quick Fixes
| Problem | Quick Fix |
|---|---|
| All accounts rate limited | Add more accounts: ccflare --add-account newaccount |
| Token expired | Re-authenticate: ccflare --remove account && ccflare --add-account account |
| Database locked | Kill duplicate processes: pkill -f "bun start" |
| Port in use | Use different port: PORT=3000 bun start |
| Config corrupted | Reset config: rm ~/.config/ccflare/ccflare.json |
| Analytics missing | Clear history: ccflare --clear-history |
| Slow responses | Check session duration settings (default 1 hour) |
Remember: Most issues can be resolved by checking logs, verifying account status, and ensuring proper network connectivity. When in doubt, restart the service with debug logging enabled: ccflare_DEBUG=1 LOG_LEVEL=DEBUG bun start