Skip to main content

Environment Variables

Configure the Claude Code Templates CLI and Claude Code using environment variables for authentication, API keys, and runtime settings.

Authentication Variables

ANTHROPIC_API_KEY

string
required
Anthropic API key for Claude Code authentication
Usage:
Purpose:
  • Authenticate Claude Code CLI
  • Enable API-based authentication
  • Alternative to OAuth authentication
Obtain Key:
  1. Visit https://console.anthropic.com/
  2. Navigate to API Keys section
  3. Create new API key
  4. Copy and set as environment variable
Priority: Environment variable takes precedence over ~/.claude.json API key. Security:
  • Never commit to git
  • Use .env files with .gitignore
  • Rotate keys regularly
  • Use different keys for dev/prod
Example .env file:
Load in shell:

ANTHROPIC_AUTH_TOKEN

string
Alternative authentication token (if using OAuth)
Usage:
Purpose: Alternative authentication method for enterprise setups.

Sandbox Variables

E2B_API_KEY

string
E2B API key for sandbox execution
Usage:
Purpose:
  • Enable E2B sandbox execution
  • Required for --sandbox e2b flag
Obtain Key:
  1. Visit https://e2b.dev/
  2. Sign up for account
  3. Create API key
  4. Set as environment variable
Example:
Alternative: Use --e2b-api-key flag:

CLOUDFLARE_TUNNEL_TOKEN

string
Cloudflare Tunnel token for remote access (optional)
Usage:
Purpose:
  • Use custom Cloudflare Tunnel
  • Persistent tunnel URLs
  • Team access to dashboards
Obtain Token:
  1. Create Cloudflare account
  2. Install cloudflared
  3. Create tunnel: cloudflared tunnel create my-tunnel
  4. Get token from tunnel config
Note: The CLI uses temporary tunnels by default. This is only needed for persistent URLs.

Runtime Configuration

PORT

number
Port for analytics dashboard and web interfaces
Usage:
Default: 3333 Purpose:
  • Change default port if 3333 is in use
  • Run multiple dashboards simultaneously
Example:

NODE_ENV

string
Node.js environment (development, production, test)
Usage:
Values:
  • development - Development mode (verbose logging)
  • production - Production mode (minimal logging)
  • test - Testing mode
Purpose:
  • Control logging verbosity
  • Enable debug features
  • Configure behavior

DEBUG

string
Enable debug logging for specific modules
Usage:
Purpose:
  • Detailed debugging output
  • Module-specific logs
  • Troubleshooting
Examples:

CCT_DEBUG

string
Enable Claude Code Templates debug logging
Usage:
Purpose:
  • Show tracking debug messages
  • Display non-critical errors
  • Troubleshoot analytics issues
Example:

CCT_NO_TRACKING

string
Disable usage tracking and analytics
Usage:
Purpose:
  • Opt out of anonymous usage analytics
  • Disable component download tracking
  • Privacy-focused installations
Example:

CCT_NO_ANALYTICS

string
Alias for CCT_NO_TRACKING (disables analytics)
Usage:
Purpose:
  • Same as CCT_NO_TRACKING
  • Alternative environment variable name
  • Disables all telemetry
Note: Setting either CCT_NO_TRACKING or CCT_NO_ANALYTICS to true will disable tracking.

Shell Configuration

PATH

string
System PATH for global agent executables
Usage:
Purpose:
  • Make global agents accessible
  • Enable command-line execution
  • Required for user-directory installations
Add to Shell Config: Bash (~/.bashrc or ~/.bash_profile):
Zsh (~/.zshrc):
Fish (~/.config/fish/config.fish):
Apply Changes:

SHELL

string
Current shell (automatically set by system)
Values:
  • /bin/bash
  • /bin/zsh
  • /usr/bin/fish
Purpose:
  • Detect shell for PATH configuration
  • Shell-specific features
  • Autocompletion setup

CI

string
Continuous Integration environment indicator
Values:
  • true - Running in CI environment
  • Unset - Local development
Purpose:
  • Automatically disables tracking in CI/CD
  • Prevents analytics in automated environments
  • Skips interactive prompts
Set by: GitHub Actions, GitLab CI, CircleCI, Jenkins, and other CI platforms automatically set this variable. Manual Override:

Project-Specific Variables

These can be set in .claude/settings.json under the env field:
Variable Expansion: Use ${VAR_NAME} to reference system environment variables.

Environment Variable Precedence

When multiple sources define the same variable:
  1. Command-line flags (highest priority)
  2. Environment variables
  3. Local settings (.claude/settings.local.json)
  4. Project settings (.claude/settings.json)
  5. User settings (~/.claude/settings.json) (lowest priority)
Example:

.env Files

Project .env

Store environment variables in .env file:
Load with dotenv:
Load in shell:

.env.example

Create template for team:
Usage:

Gitignore

Always exclude .env from git:

CI/CD Configuration

GitHub Actions

Set secrets in repository settings:
Set Secrets:
  1. Go to repository Settings > Secrets and variables > Actions
  2. Add ANTHROPIC_API_KEY secret
  3. Reference with ${{ secrets.ANTHROPIC_API_KEY }}

GitLab CI

Set Variables:
  1. Go to Settings > CI/CD > Variables
  2. Add ANTHROPIC_API_KEY (protected, masked)

Docker Configuration

Dockerfile

docker-compose.yml

Run:

Security Best Practices

1. Never Commit Secrets

2. Use Separate Keys

  • Development: Personal API key
  • Staging: Team staging key
  • Production: Production key (rotate regularly)

3. Restrict Permissions

4. Rotate Keys Regularly

5. Use Key Management Systems

AWS Secrets Manager:
HashiCorp Vault:

Troubleshooting

Variables Not Loading

Check if variable is set:
Source shell config:
Verify .env file:

Authentication Fails

Test API key:
Check key format:
  • Should start with sk-ant-
  • No whitespace or special characters
  • Not expired

PATH Not Working

Verify PATH includes bin directory:
Add to PATH manually:
Check executable exists:

Permission Denied

Fix file permissions:

Next Steps