AI 编程省 Token 与高缓存命中率配置模板库
基于 T Salon TokenRank 实测数据提炼:只需将以下 4 份标准化配置文件放入仓库根目录,即可将 Prompt Cache 命中率稳定在 85% 以上,并将 5 小时滚动窗口续航提升 2.5 倍。
1. CLAUDE.md — 静态前缀锁死与 5 小时窗口省额度配置
专为 Claude Code 设计:固定系统规则头部顺序、禁止全仓盲扫、限定单次输出行数,并强制在上下文达到 90k tokens 或每完成一个子模块时执行 /compact。
# CLAUDE.md — High-Cache-Stability & Quota-Efficient Engineering Protocol
# Keep sections 1-3 strictly static. Do NOT inject dynamic timestamps or git hashes here.
## 1. Repository Architecture & Commands (Static Prefix)
- Package Manager & Build: `npm run build` | Validation: `npm test`
- Primary Source Root: `src/` | Tests: `scripts/`
- Never read `node_modules/`, `dist/`, `.astro/`, or lockfiles.
## 2. Prompt Cache & Context Hygiene Rules
1. **Preserve Prefix Stability**: Never mutate system prompt ordering or toggle MCP servers mid-session.
2. **Targeted File Reads Only**: Always specify line ranges (`sed -n '1,120p'` or line-bounded reads) instead of dumping files > 300 lines into context.
3. **Cap Command Output**: Pipe verbose test/build logs through `| tail -n 60` so raw stack traces do not pollute the sliding context window.
4. **Checkpoint & Compact**: After completing each self-contained sub-task (or when context exceeds ~90k tokens), write state to `REFACTOR_PLAN.md` and run `/compact`.
## 3. Verification Discipline
- Run unit tests on the touched module first before running full-site builds.
- Never end markdown headings (`#`, `##`, `###`) with trailing periods.2. AGENTS.md — 跨窗口三阶段磁盘检查点重构工作流
兼容 OpenAI Codex CLI、Claude Code 与 Antigravity:将长程重构拆解为「接口契约 → 3-5 文件微批次 → 增量测试闭环」,即使遭遇 429 限流也能零损耗续跑。
# AGENTS.md — 3-Stage Disk-Checkpointed Refactoring Protocol
## Stage 1: Dependency Graph & Contract Freeze (Budget <= 15% of 5h Window)
- Before editing implementation files, update `REFACTOR_PLAN.md` with:
- [ ] Shared types / schema changes
- [ ] Ordered micro-batches of 3–5 files each
- [ ] Verification command per batch
## Stage 2: Micro-Batch Execution (3–5 Files per Session)
- Process ONE micro-batch at a time.
- After passing the batch verification command:
1. Mark the batch `[x]` in `REFACTOR_PLAN.md`.
2. Record any edge cases under `## Handover Notes` in `REFACTOR_PLAN.md`.
3. Clear or compact conversation history before starting the next batch.
## Stage 3: Quota-Aware Model Routing
- Reserve high-weight reasoning models (Opus 4.6 / GPT-5.4 high-effort / Gemini 2.5 Pro) strictly for Stage 1 architecture design.
- Execute Stage 2 file migrations and test fixes with high-efficiency coding models (Sonnet 4.6 / Codex standard / Gemini 2.5 Flash).3. .cursorrules — 抑制多轮重发与 Max Mode 额度暴增规则
针对 Cursor Pro 每月 500 次 Fast Requests 设计:通过一次性计划确认、精确文件引用与终端报错截断,避免因反复修正消耗 3–5 倍快速请求。
# .cursorrules — Cursor Fast Request & Context Efficiency Rules
1. **Plan Before Multi-File Edits**:
- If a request touches > 2 files, list the exact target files and function signatures in 5 bullet points before applying edits.
2. **Surgical Context Attachment**:
- Read only the relevant symbol or 80-line window rather than attaching entire directories.
- Exclude generated assets (`dist/`, `coverage/`, `*.min.js`, `package-lock.json`).
3. **Single-Pass Verification**:
- Group related edits in the same file into a single atomic change to minimize round-trip tool turns.
- When terminal commands fail, inspect only the first error and the last 40 lines of output.4. .mcp.json — 接入 T Salon WhenReset 实时重置雷达 MCP Server
零鉴权接入 T Salon 官方 Streamable HTTP MCP 端点:让 Claude Code、Cursor 或 Antigravity 在启动大规模任务前自动查询当前是否处于双倍额度窗口或距每日重置还有多久。
{
"mcpServers": {
"tsalon-whenreset": {
"type": "http",
"url": "https://www.tsalon.tech/api/reset/mcp"
}
}
}常见问题解答 (FAQ)
为什么固定 CLAUDE.md 的前三节顺序能大幅提升 Prompt Cache 命中率?
因为 Anthropic、OpenAI 与 DeepSeek 的 Prompt Caching 均采用「严格前缀匹配(Exact Prefix Matching)」。只要系统提示词、工具定义(MCP)与 CLAUDE.md 头部字节完全不变,后续每一轮对话都能直接复用 90% 折扣(Anthropic/DeepSeek)或 50%–75% 折扣(OpenAI)的缓存块。
这些配置文件应该放在项目仓库的哪个位置?
将 `CLAUDE.md`、`AGENTS.md`、`.cursorrules` 与 `.mcp.json` 直接放在 Git 仓库根目录下。Claude Code 会自动加载 `CLAUDE.md` 与 `.mcp.json`,OpenAI Codex CLI 与 Antigravity 会自动读取 `AGENTS.md`,Cursor 会自动应用 `.cursorrules`。
配置 .mcp.json 接入 tsalon-whenreset 后可以调用哪些工具?
支持调用 `get_reset_radar`(查询 Claude / Codex / Gemini / Grok 实时重置状态与 2x 促销活动)、`get_google_daily_reset`(查询距离北京时间 15:00/16:00 太平洋午夜重置的精确秒数)以及 `calculate_weekly_burn`(计算 7 天滚动窗口剩余安全消耗速率)。
