Skip to content

SOP-004: Environment Configuration

Document Control

FieldValue
Document IDSOP-004
Version1.0
StatusActive
OwnerClaude AI Operations
Last Updated2024-12-01
Review Date2025-03-01

Overview

This SOP defines the procedures for configuring Claude AI environments, including development, staging, and production environments. Proper environment configuration ensures consistent behavior, security, and maintainability across deployments.

Environment Architecture

┌─────────────────────────────────────────────────────────────┐
│                    Environment Layers                       │
├─────────────────────────────────────────────────────────────┤
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐        │
│  │ Development │  │   Staging   │  │ Production  │        │
│  │             │  │             │  │             │        │
│  │ • Local     │  │ • Pre-prod  │  │ • Live      │        │
│  │ • Testing   │  │ • Validation│  │ • Scaled    │        │
│  │ • Debug     │  │ • QA        │  │ • Monitored │        │
│  └─────────────┘  └─────────────┘  └─────────────┘        │
├─────────────────────────────────────────────────────────────┤
│                 Configuration Management                     │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────┐        │
│  │ Environment │  │ Application │  │  Security   │        │
│  │ Variables   │  │ Settings    │  │ Policies    │        │
│  └─────────────┘  └─────────────┘  └─────────────┘        │
└─────────────────────────────────────────────────────────────┘

Prerequisites

  • Administrative access to target environment
  • Claude API credentials
  • Version control system access
  • Environment-specific configuration templates

Procedure

Step 1: Environment Setup

1.1 Create Environment Configuration Directory

bash
# Create environment configuration structure
mkdir -p ~/.config/claude/{dev,staging,prod}
mkdir -p ~/.config/claude/templates
mkdir -p ~/.config/claude/secrets

1.2 Set Base Environment Variables

bash
# Create base environment configuration
cat > ~/.config/claude/base.env << 'EOF'
# Base Claude Configuration
CLAUDE_LOG_LEVEL=INFO
CLAUDE_TIMEOUT=30000
CLAUDE_RETRY_ATTEMPTS=3
CLAUDE_RETRY_DELAY=1000
CLAUDE_MAX_TOKENS=4096
CLAUDE_TEMPERATURE=0.7
EOF

Step 2: Development Environment

2.1 Development Configuration

bash
# Development environment settings
cat > ~/.config/claude/dev/config.env << 'EOF'
# Development Environment
NODE_ENV=development
CLAUDE_ENV=development
CLAUDE_API_URL=https://api.anthropic.com
CLAUDE_MODEL=claude-3-sonnet-20240229
CLAUDE_DEBUG=true
CLAUDE_VERBOSE=true
CLAUDE_RATE_LIMIT_ENABLED=false
CLAUDE_CACHE_ENABLED=false
CLAUDE_LOG_FILE=~/.logs/claude-dev.log
EOF

2.2 Development CLAUDE.md Template

bash
cat > ~/.config/claude/templates/dev-claude.md << 'EOF'
# Claude Development Configuration

## Environment
- **Type**: Development
- **Debug Mode**: Enabled
- **Logging**: Verbose

## API Configuration
- **Model**: claude-3-sonnet-20240229
- **Temperature**: 0.7
- **Max Tokens**: 4096

## Development Features
- Enhanced error messages
- Debug logging
- Rate limiting disabled
- Cache disabled for fresh responses

## Local Tools
- File system access: Enabled
- Code execution: Sandboxed
- Network access: Limited to APIs
EOF

Step 3: Staging Environment

3.1 Staging Configuration

bash
# Staging environment settings
cat > ~/.config/claude/staging/config.env << 'EOF'
# Staging Environment
NODE_ENV=staging
CLAUDE_ENV=staging
CLAUDE_API_URL=https://api.anthropic.com
CLAUDE_MODEL=claude-3-sonnet-20240229
CLAUDE_DEBUG=false
CLAUDE_VERBOSE=false
CLAUDE_RATE_LIMIT_ENABLED=true
CLAUDE_CACHE_ENABLED=true
CLAUDE_LOG_FILE=~/.logs/claude-staging.log
CLAUDE_METRICS_ENABLED=true
EOF

3.2 Staging Validation Script

bash
cat > ~/.config/claude/staging/validate.sh << 'EOF'
#!/bin/bash
# Staging Environment Validation

echo "🔍 Validating Staging Environment..."

# Check environment variables
if [ -z "$CLAUDE_API_KEY" ]; then
    echo "❌ CLAUDE_API_KEY not set"
    exit 1
fi

# Test API connectivity
if ! curl -s https://api.anthropic.com > /dev/null; then
    echo "❌ Cannot reach Anthropic API"
    exit 1
fi

# Verify model availability
claude --model claude-3-sonnet-20240229 --test-connection

echo "✅ Staging environment validated"
EOF

chmod +x ~/.config/claude/staging/validate.sh

Step 4: Production Environment

4.1 Production Configuration

bash
# Production environment settings
cat > ~/.config/claude/prod/config.env << 'EOF'
# Production Environment
NODE_ENV=production
CLAUDE_ENV=production
CLAUDE_API_URL=https://api.anthropic.com
CLAUDE_MODEL=claude-3-sonnet-20240229
CLAUDE_DEBUG=false
CLAUDE_VERBOSE=false
CLAUDE_RATE_LIMIT_ENABLED=true
CLAUDE_CACHE_ENABLED=true
CLAUDE_LOG_FILE=/var/log/claude/claude-prod.log
CLAUDE_METRICS_ENABLED=true
CLAUDE_MONITORING_ENABLED=true
CLAUDE_SECURITY_ENHANCED=true
EOF

4.2 Production Security Settings

bash
cat > ~/.config/claude/prod/security.env << 'EOF'
# Production Security Configuration
CLAUDE_TLS_VERIFY=true
CLAUDE_CERT_CHECK=strict
CLAUDE_SESSION_TIMEOUT=1800
CLAUDE_MAX_CONCURRENT_REQUESTS=10
CLAUDE_IP_WHITELIST_ENABLED=true
CLAUDE_AUDIT_LOGGING=true
CLAUDE_ENCRYPTION_AT_REST=true
EOF

Step 5: Environment Loading Script

bash
cat > ~/.config/claude/load-env.sh << 'EOF'
#!/bin/bash
# Environment Configuration Loader

CLAUDE_ENV=${1:-development}

case $CLAUDE_ENV in
    "development"|"dev")
        source ~/.config/claude/base.env
        source ~/.config/claude/dev/config.env
        echo "🔧 Development environment loaded"
        ;;
    "staging")
        source ~/.config/claude/base.env
        source ~/.config/claude/staging/config.env
        echo "🔍 Staging environment loaded"
        ;;
    "production"|"prod")
        source ~/.config/claude/base.env
        source ~/.config/claude/prod/config.env
        source ~/.config/claude/prod/security.env
        echo "🚀 Production environment loaded"
        ;;
    *)
        echo "❌ Unknown environment: $CLAUDE_ENV"
        echo "Valid environments: development, staging, production"
        exit 1
        ;;
esac

export CLAUDE_ENV
EOF

chmod +x ~/.config/claude/load-env.sh

Step 6: Environment Switching

6.1 Create Environment Switcher

bash
cat > ~/.local/bin/claude-env << 'EOF'
#!/bin/bash
# Claude Environment Switcher

show_help() {
    cat << EOF
Usage: claude-env [COMMAND] [ENVIRONMENT]

Commands:
    switch <env>    Switch to environment (dev/staging/prod)
    current         Show current environment
    list            List available environments
    validate        Validate current environment
    help            Show this help

Environments:
    dev             Development environment
    staging         Staging environment  
    prod            Production environment

Examples:
    claude-env switch dev
    claude-env current
    claude-env validate
EOF
}

switch_env() {
    local env=$1
    source ~/.config/claude/load-env.sh "$env"
    echo "CLAUDE_ENV=$env" > ~/.config/claude/current-env
}

current_env() {
    if [ -f ~/.config/claude/current-env ]; then
        cat ~/.config/claude/current-env
    else
        echo "No environment set"
    fi
}

case "${1:-help}" in
    "switch")
        if [ -z "$2" ]; then
            echo "❌ Environment required"
            echo "Usage: claude-env switch <dev|staging|prod>"
            exit 1
        fi
        switch_env "$2"
        ;;
    "current")
        current_env
        ;;
    "list")
        echo "Available environments:"
        echo "  - dev (development)"
        echo "  - staging"
        echo "  - prod (production)"
        ;;
    "validate")
        env=$(current_env | cut -d'=' -f2)
        if [ "$env" = "staging" ]; then
            ~/.config/claude/staging/validate.sh
        else
            echo "Environment validation available for staging only"
        fi
        ;;
    "help"|*)
        show_help
        ;;
esac
EOF

chmod +x ~/.local/bin/claude-env

Verification

Environment Configuration Check

bash
# Verify environment setup
claude-env list
claude-env switch dev
claude-env current

# Test configuration loading
source ~/.config/claude/load-env.sh development
echo "Model: $CLAUDE_MODEL"
echo "Debug: $CLAUDE_DEBUG"
echo "Environment: $CLAUDE_ENV"

API Connectivity Test

bash
# Test API connection with current environment
claude --test-connection

# Validate configuration
claude --validate-config

# Check environment variables
env | grep CLAUDE_

Troubleshooting

Common Issues

IssueSymptomsResolution
Environment not loadingVariables not setCheck file permissions and syntax
API connection failedNetwork errorsVerify API key and network connectivity
Configuration conflictsUnexpected behaviorClear environment and reload
Permission deniedCannot create filesCheck directory permissions

Debug Commands

bash
# Debug environment loading
bash -x ~/.config/claude/load-env.sh development

# Check file permissions
ls -la ~/.config/claude/

# Validate environment files
for file in ~/.config/claude/*/*.env; do
    echo "Checking $file"
    bash -n "$file" && echo "✅ Valid" || echo "❌ Invalid"
done

Recovery Procedures

bash
# Reset environment configuration
rm -rf ~/.config/claude/current-env
claude-env switch dev

# Recreate configuration templates
mkdir -p ~/.config/claude/{dev,staging,prod}
# Re-run Step 1-2 procedures

See Also

Claude Code Documentation Hub