上下文配置文件允许您配置 lean-ctx 如何处理不同场景的内容:探索、调试、紧急修复、CI、代码审查等。将其视为 "Context as Code" - 您的团队可以共享的版本化策略。
什么是配置文件?
配置文件是一个 TOML 文件,控制读取模式、压缩设置、Token 预算、管道层和自治行为。配置文件可以继承其他配置文件并覆盖特定字段。
内置配置文件
lean-ctx 附带 5 个内置配置文件,针对常见工作流程进行了优化:
exploration
用于理解代码库的广泛上下文。Map 模式,200K Token 预算,优先使用缓存。
bugfix
聚焦调试,自动模式。简洁输出,100K Token 预算,每 10 次调用检查点。
hotfix
紧急修复的最小上下文。签名模式,超紧凑输出,30K Token,$1 成本上限。
ci-debug
CI/CD 调试,支持 200 次 Shell 调用。简洁输出,150K Token 预算。
review
代码审查,带有广泛的只读上下文。Map 模式,紧凑 CRP,150K Token 预算。
激活配置文件
设置 LEAN_CTX_PROFILE 环境变量:
export LEAN_CTX_PROFILE=hotfix 或通过命令行:
lean-ctx profile set hotfix 或在运行时通过 MCP 切换:
ctx_session action=profile value=hotfix 创建自定义配置文件
在 .lean-ctx/profiles/(项目本地)或 ~/.lean-ctx/profiles/(全局)中创建配置文件 TOML 文件:
# .lean-ctx/profiles/my-team.toml
[profile]
name = "my-team"
inherits = "exploration"
description = "Team defaults with lower budget"
[read]
default_mode = "map"
max_tokens_per_file = 40000
[budget]
max_context_tokens = 120000
max_cost_usd = 2.0 或使用 CLI 创建配置文件:
lean-ctx profile create my-team --from exploration 配置文件继承
配置文件可以通过 inherits 字段继承任何其他配置文件。子值覆盖父值;未设置的字段将从父配置文件继承。
# .lean-ctx/profiles/strict-review.toml
[profile]
name = "strict-review"
inherits = "review"
[budget]
max_context_tokens = 80000
max_cost_usd = 1.0 配置文件模式
完整的配置文件包含以下部分:
- [profile] - name, inherits, description
- [read] - default_mode, max_tokens_per_file, prefer_cache
- [compression] - crp_mode, output_density, entropy_threshold
- [budget] - max_context_tokens, max_shell_invocations, max_cost_usd
- [pipeline] - intent, relevance, compression, translation(布尔开关)
- [autonomy] - auto_dedup, checkpoint_interval
CLI 参考
lean-ctx profile list- 显示所有可用配置文件lean-ctx profile show <name>- 显示配置文件详情lean-ctx profile diff <a> <b>- 比较两个配置文件lean-ctx profile create <name>- 创建新配置文件lean-ctx profile set <name>- 显示激活说明
解析顺序
配置文件按以下顺序解析:
LEAN_CTX_PROFILE环境变量- 项目本地
.lean-ctx/profiles/<name>.toml - 全局
~/.lean-ctx/profiles/<name>.toml - 内置默认值