configuring

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Configuring

Configuring工具配置指南

Unified configuration management across AI coding environments. Load environment variables, secrets, and other opinionated configuration setups from any AI coding platform.
跨AI编码环境的统一配置管理。可从任意AI编码平台加载环境变量、密钥以及其他定制化配置。

Quick Start

快速开始

python
import sys
sys.path.insert(0, '/path/to/claude-skills')  # or wherever skills are installed
from configuring import get_env, detect_environment
python
import sys
sys.path.insert(0, '/path/to/claude-skills')  # 或技能安装的其他路径
from configuring import get_env, detect_environment

Get a variable (searches all sources automatically)

获取变量(自动搜索所有来源)

token = get_env("TURSO_TOKEN", required=True)
token = get_env("TURSO_TOKEN", required=True)

With default

带默认值

port = get_env("PORT", default="8080")
port = get_env("PORT", default="8080")

What environment are we in?

检测当前运行环境

env = detect_environment() # "claude.ai", "claude-code-desktop", "codex", "jules", etc.
undefined
env = detect_environment() # 返回 "claude.ai", "claude-code-desktop", "codex", "jules" 等
undefined

Supported Environments

支持的环境

EnvironmentConfig Sources
Claude.ai Projects
/mnt/project/*.env
,
/mnt/project/*-token.txt
Claude Code
~/.claude/settings.json
(
env
block),
.claude/settings.json
OpenAI Codex
~/.codex/config.toml
, setup script →
~/.bashrc
,
shell_snapshots/*.sh
JulesEnvironment settings UI,
.env
in repo
Universal
os.environ
,
.env
,
.env.local
环境配置来源
Claude.ai Projects
/mnt/project/*.env
,
/mnt/project/*-token.txt
Claude Code
~/.claude/settings.json
env
块),
.claude/settings.json
OpenAI Codex
~/.codex/config.toml
, 安装脚本 →
~/.bashrc
,
shell_snapshots/*.sh
Jules环境设置UI, 仓库中的
.env
文件
通用环境
os.environ
,
.env
,
.env.local

API Reference

API参考

python
undefined
python
undefined

Core

核心方法

get_env(key, default=None, *, required=False, validator=None) -> str | None load_env(path) -> dict[str, str] # Load specific file load_all(force_reload=False) -> dict # Load all sources
get_env(key, default=None, *, required=False, validator=None) -> str | None load_env(path) -> dict[str, str] # 加载指定文件 load_all(force_reload=False) -> dict # 加载所有来源

Utilities

工具方法

detect_environment() -> str # Current platform mask_secret(value, show_chars=4) -> str # Safe logging debug_info() -> dict # Troubleshooting get_loaded_sources() -> list[str] # What was checked
undefined
detect_environment() -> str # 当前运行平台 mask_secret(value, show_chars=4) -> str # 安全日志输出(隐藏密钥) debug_info() -> dict # 故障排查信息 get_loaded_sources() -> list[str] # 已检查的配置来源
undefined

Credential File Formats

凭证文件格式

.env
files
(KEY=value):
TURSO_TOKEN=eyJhbGciOiJFZERTQSI...
EMBEDDING_API_KEY=sk-svcacct-...
Single-value files (
*-token.txt
,
*-key.txt
):
eyJhbGciOiJFZERTQSI...
Filename becomes key:
turso-token.txt
TURSO_TOKEN
Claude Code settings.json:
json
{
  "env": {
    "TURSO_TOKEN": "eyJhbGciOiJFZERTQSI..."
  }
}
.env
文件
(KEY=value格式):
TURSO_TOKEN=eyJhbGciOiJFZERTQSI...
EMBEDDING_API_KEY=sk-svcacct-...
单值文件
*-token.txt
,
*-key.txt
格式):
eyJhbGciOiJFZERTQSI...
文件名会作为键名:例如
turso-token.txt
TURSO_TOKEN
Claude Code settings.json格式
json
{
  "env": {
    "TURSO_TOKEN": "eyJhbGciOiJFZERTQSI..."
  }
}

Priority Order

加载优先级

Later sources override earlier:
  1. OS environment variables
  2. Platform-specific sources (detected automatically)
  3. .env
    files in cwd
  4. OS environment variables (again - explicit exports always win)
后续来源的配置会覆盖之前的:
  1. 系统环境变量
  2. 平台专属配置来源(自动检测)
  3. 当前目录下的
    .env
    文件
  4. 系统环境变量(再次生效 - 显式导出的配置始终优先级最高)

Debugging

调试

python
import sys
sys.path.insert(0, '/path/to/claude-skills')
from configuring import debug_info
print(debug_info())
python
import sys
sys.path.insert(0, '/path/to/claude-skills')
from configuring import debug_info
print(debug_info())

{'environment': 'claude.ai', 'sources': ['os.environ', 'claude.ai:/mnt/project/'], ...}

返回结果示例: {'environment': 'claude.ai', 'sources': ['os.environ', 'claude.ai:/mnt/project/'], ...}


CLI:
```bash
cd /path/to/claude-skills/configuring
python scripts/getting_env.py                    # Show debug info
python scripts/getting_env.py TURSO_TOKEN        # Get specific key

命令行工具:
```bash
cd /path/to/claude-skills/configuring
python scripts/getting_env.py                    # 显示调试信息
python scripts/getting_env.py TURSO_TOKEN        # 获取指定键的值

Migration from api-credentials / getting-env

从api-credentials/getting-env迁移

Replace:
python
undefined
替换旧代码:
python
undefined

Old (api-credentials)

旧代码(api-credentials)

from credentials import get_anthropic_api_key key = get_anthropic_api_key()
from credentials import get_anthropic_api_key key = get_anthropic_api_key()

Old (getting-env)

旧代码(getting-env)

from getting_env import get_env key = get_env("ANTHROPIC_API_KEY")
from getting_env import get_env key = get_env("ANTHROPIC_API_KEY")

New (configuring)

新代码(configuring)

import sys sys.path.insert(0, '/path/to/claude-skills') from configuring import get_env key = get_env("ANTHROPIC_API_KEY", required=True)
undefined
import sys sys.path.insert(0, '/path/to/claude-skills') from configuring import get_env key = get_env("ANTHROPIC_API_KEY", required=True)
undefined