Module: Clacky::ClaudeCodeEnv

Defined in:
lib/clacky/agent_config.rb

Overview

ClaudeCode environment variable compatibility layer Provides configuration detection from ClaudeCode’s environment variables

Constant Summary collapse

ENV_API_KEY =

Environment variable names used by ClaudeCode

"ANTHROPIC_API_KEY"
ENV_AUTH_TOKEN =
"ANTHROPIC_AUTH_TOKEN"
ENV_BASE_URL =
"ANTHROPIC_BASE_URL"
DEFAULT_BASE_URL =

Default Anthropic API endpoint

"https://api.anthropic.com"

Class Method Summary collapse

Class Method Details

.api_keyObject

Get API key - prefer ANTHROPIC_API_KEY, fallback to ANTHROPIC_AUTH_TOKEN



25
26
27
28
29
30
31
# File 'lib/clacky/agent_config.rb', line 25

def api_key
  if ENV[ENV_API_KEY] && !ENV[ENV_API_KEY].empty?
    ENV[ENV_API_KEY]
  elsif ENV[ENV_AUTH_TOKEN] && !ENV[ENV_AUTH_TOKEN].empty?
    ENV[ENV_AUTH_TOKEN]
  end
end

.base_urlObject

Get base URL from environment, or return default Anthropic API URL



34
35
36
# File 'lib/clacky/agent_config.rb', line 34

def base_url
  ENV[ENV_BASE_URL] && !ENV[ENV_BASE_URL].empty? ? ENV[ENV_BASE_URL] : DEFAULT_BASE_URL
end

.configured?Boolean

Check if any ClaudeCode authentication is configured

Returns:

  • (Boolean)


20
21
22
# File 'lib/clacky/agent_config.rb', line 20

def configured?
  !api_key.nil? && !api_key.empty?
end

.to_hObject

Get configuration as a hash (includes configured values) Returns api_key and base_url (always available as there’s a default)



40
41
42
43
44
45
# File 'lib/clacky/agent_config.rb', line 40

def to_h
  {
    "api_key" => api_key,
    "base_url" => base_url
  }.compact
end