我的个人 Claude Code 配置——通过规则、Agent 和记忆机制来工程化 AI 行为。
claude-code-config/
├── CLAUDE.md # 每次会话自动加载的全局行为规则
├── settings.json # 权限、模型、插件与环境变量配置
├── .gitignore
├── ghostty/ # Ghostty 终端配置(git submodule → bi-boo/ghostty-config)
├── statusline/ # 自定义终端状态栏
│ └── statusline-command.sh # 模型名 / token 统计 / context 占用 / 订阅用量
├── rules/ # 按需加载的规则文件(由 CLAUDE.md 索引引用,16 个)
│ ├── 调试升级策略.md # 4 级调试升级路径 + 7 项强制检查清单
│ ├── 会话交接规则.md # 会话交接协议(7 段式断点文档格式)
│ ├── 代码工作纪律.md # 诊断/实现模式切换、3 次失败停手等
│ ├── Git分支工作流规则.md # main/master 上动手前提醒开 feature 分支
│ ├── 通用工作流规则.md # Git 提交推送 / 命令执行方式默认值
│ ├── HTML设计准则.md # 前端 / HTML / 幻灯片视觉规范
│ ├── 单文件大小与拆分.md # 各类文件行数红线
│ ├── 图表与汇报图规范.md # Mermaid / 汇报图 / 可视化规范
│ ├── 构建发布规范.md # 多平台构建 + GitHub Releases
│ ├── 系统提示词优化规范.md # CLAUDE.md / rules 文件重构纪律
│ ├── Markdown格式规范.md # 加粗 / 高亮 / callout 选用
│ ├── Markdown命名规范.md # 文件命名规范
│ ├── Skill安装与管理规范.md
│ ├── MCP使用经验.md # MCP server 故障排查
│ ├── 文档维护规则.md # 代码项目文档何时更新
│ └── 文档输出规则.md # 文档整理输出路径
├── agents/
│ ├── analyst.md # Opus 模型驱动的深度分析 Agent
│ └── explorer.md # Haiku 模型驱动的轻量文件探索 Agent
└── memory/
├── MEMORY.md # 每次自动加载的持久化知识索引
├── 当前任务断点.md # 进行中任务的交接文档(7 段式模板)
└── 项目运维示例.md # 项目级运维知识文件的示例结构
1. 通过 CLAUDE.md 工程化 AI 行为
核心行为规则写入 CLAUDE.md,每次对话自动加载。包括:先计划后执行、高危操作前确认、结构化输出要求等。不依赖每次手动提示词。
2. 调试升级策略(4 级 + 7 项清单)
rules/调试升级策略.md 定义了一套强制升级机制:连续失败 2 次必须换思路,失败 4 次触发 7 项检查清单。杜绝在同一错误假设上无限微调。
3. 跨会话任务交接
rules/会话交接规则.md 定义了 7 段式断点文档(当前任务断点.md),Claude 在复杂任务进行中静默更新,包含目标、进展、关键发现、风险等。新会话自动检测并加载,实现真正的跨 context 连续性。
4. 模型分级 Agent
两个自定义 Agent 分工不同:explorer 使用 Haiku 快速搜索文件;analyst 使用 Opus 处理架构决策和深度推理。轻量任务高效低成本,复杂任务全力以赴。
5. 自定义状态栏:实时订阅用量
Claude Code 支持通过 settings.json 的 statusLine.command 接入自定义 shell 脚本,每隔约 300ms 调用一次,将输出渲染到终端底栏。
我的状态栏显示:
claude-sonnet-4-6 | ↑ 15.0K ↓ 3.0K | ↕ 23% | 88%(46m) 54%(7d)
- 模型名:按模型系列着色(Opus 紫、Sonnet 蓝、Haiku 绿)
- ↑↓ token 数:本次会话累计输入/输出,自动换算 K/M 单位
- ↕ context 占用:上下文窗口使用率,绿/黄/红三色预警
- 订阅用量:5h 配额显示剩余重置时间(88%(46m)),7d 配额显示周期消耗(54%(7d))
用量数据来源:Claude Code 2.x 起会把 rate_limits.five_hour 和 rate_limits.seven_day 字段通过 stdin JSON 直接注入 statusline 命令,状态栏每次渲染从这个字段直接 jq 取值即可,无需自己异步调 OAuth 端点、无需本地缓存。
仅适用于用 claude.ai 账号登录的 Pro/Max/Team 订阅用户。使用 API Key 登录的用户不会显示用量(按量付费,没有配额概念)。
6. Rules 按需加载机制
CLAUDE.md 保持精简,只放高频规则。专项规则(调试、文档格式、命名规范)放在 rules/ 目录,通过路径引用按需加载——对话不需要就不加载,节省 context 窗口。
我用 Ghostty 作为唯一终端,并将其直接绑定为 Claude Code 的专用启动器。
核心配置:
command = ~/.local/bin/claude
quit-after-last-window-closed = true
效果:打开 Ghostty = 启动 Claude Code,关闭最后一个窗口 = 退出应用。不需要先打开终端再手动输入 claude,两者合二为一。
其他关键配置:
- 自定义
Claude主题:暖米色背景(#FDFCFA)+ 赭石光标(#D97757),长时间使用不疲劳 Cmd+D横向分屏,多个 Claude Code 会话并排工作Ctrl+Shift+↑↓在命令提示符之间跳转,快速回溯历史输出notify-on-command-finish = always:长任务完成后系统通知提醒
安装 Ghostty 配置(submodule,可独立升级):
# 克隆本仓库时连同 submodule 一起拉取
git clone --recurse-submodules https://github.com/YOUR_USERNAME/claude-code-config.git
# 已克隆的话,单独拉 submodule
git submodule update --init ghostty
# 软链接到 Ghostty 配置目录
ln -sf "$(pwd)/ghostty" ~/.config/ghostty# 1. Fork 并克隆本仓库(含 ghostty submodule)
git clone --recurse-submodules https://github.com/YOUR_USERNAME/claude-code-config.git
# 2. 将文件复制到 Claude 配置目录
cp -r claude-code-config/rules ~/.claude/rules
cp -r claude-code-config/agents ~/.claude/agents
cp -r claude-code-config/memory ~/.claude/memory
cp -r claude-code-config/statusline ~/.claude/statusline
cp claude-code-config/CLAUDE.md ~/.claude/CLAUDE.md
cp claude-code-config/settings.json ~/.claude/settings.json
# 3. 状态栏脚本需要可执行权限
chmod +x ~/.claude/statusline/statusline-command.sh
# 4. (可选)软链接 Ghostty 配置
ln -sf "$(pwd)/claude-code-config/ghostty" ~/.config/ghostty
CLAUDE.md和rules/的具体内容应根据自己的工作方式调整。真正的价值在于这套结构本身,而不是某条具体规则。
My personal Claude Code configuration — how I engineer AI behavior through rules, agents, and memory.
1. Behavior engineering via CLAUDE.md — Core behaviors encoded as rules, loaded automatically in every conversation. No per-session prompting needed.
2. Tiered debugging escalation — 4-level escalation path with a mandatory 7-item checklist after 4 failures. Prevents infinite loops of micro-adjustments on broken assumptions.
3. Persistent session handoff — A 7-section handoff document silently updated throughout complex tasks. New sessions detect and load it automatically, enabling continuity across context resets.
4. Model-tiered agents — explorer (Haiku) for fast file search; analyst (Opus) for deep reasoning. Lightweight tasks stay cheap; complex work gets full power.
5. Custom statusline with live subscription usage — A shell script renders a status bar at the bottom of the terminal every ~300ms: model name (color-coded by tier), token counts (↑↓), context window usage (↕, green/yellow/red), and subscription quota consumption (e.g. 88%(46m) 54%(7d)). Since Claude Code 2.x, rate_limits.five_hour and rate_limits.seven_day are injected into the statusline's stdin JSON directly — no OAuth fetch, no local cache. Pro/Max/Team subscribers only.
6. On-demand rules with lazy loading — CLAUDE.md stays lean. Specialized rules live in rules/ and are loaded only when referenced — saving context window space.
Terminal: Ghostty as a Claude Code launcher — Ghostty is configured with command = ~/.local/bin/claude so opening the terminal directly launches Claude Code. Custom warm-cream theme, split panes with Cmd+D, and prompt-jumping with Ctrl+Shift+↑↓.