Tips for caching in claude code

Published on
Last updated on
Technical
AI

Claude Code Improved

It has been a long time since I started using Claude Code. The techniques I use most are:

  1. Use an agent team so that most of the time the context window stays around 40%~70%, which according to No Vibes Allowed is the best window.
  2. For a new task, create a new session or clear the session.
  3. Deliberate compact.

But today someone shared some more tips: 搞懂缓存机制,从Gemma4到Claude Code省80%Token

每次 API 调用,Claude Code 发送的是一个精心拼接的多层结构:
┌─────────────────────────────────────────────────┐
│ system(系统提示词,~20K tokens) │
│ Block 1: 计费归因头 → 不缓存 │
│ Block 2: CLI 前缀 → 不缓存 │
│ Block 3: 静态指令(行为规则等) → global 缓存 │ ← 全球所有用户共享!
│ ──── DYNAMIC_BOUNDARY ──── │
│ Block 4: 动态内容(CLAUDE.md 等) → org 缓存 │
├─────────────────────────────────────────────────┤
│ tools(工具 schema,session 内冻结) │
├─────────────────────────────────────────────────┤
│ messages(对话历史) │
│ 最后一条消息上放 cache_control 标记 │
└─────────────────────────────────────────────────┘
  1. One session should not last more than 1 hour.
  2. Don’t do the following things in the meanwhile:
    • Create a new session —> cold cache, ~20k token recalculation
    • Modify CLAUDE.md —> will discard block #4
    • Add/delete MCP —> tool schema changes = cache broken, so configure proper MCP before session start
    • Switch model —> completely discard, start from zero
    • /compact —> history changes = cache broken, useful when session > 100K
    • TTL > 1h —> cache expired, say something within 1 hour
  3. Prompt one time, then append multiple times.
  4. Edit the original prompt; do not send a new prompt to correct it.
  5. Give the exact path; don’t let AI search by itself.
  6. Exclude large files in CLAUDE.md.
  7. Task breakdown: break big tasks into small tasks.

Design

Google has revealed the DESIGN.md format to help create DESIGN.md, which is used to describe UI design. Now, more and more designs are extracted from all kinds of systems and applications.

Harness Engineering

Some books and articles that describe the principles for mastering Claude Code and harness principles:

Some implementations of harness agents:

reference articles

Recently, I came across Michael Polanyi’s concept of “tacit knowledge.”

When prompting AI to design an app interface, you don’t need to write thousands of words breaking down details like implicit user emotions, intuitive color choices, or interaction smoothness shaped by embodied memory. You can simply say, “Apply Polanyi’s tacit knowledge so the output simulates the accumulation of human experience and intuitive judgment that cannot be fully articulated,” and the AI can produce solutions that feel more human and less mechanical.

  • 迈克尔·波兰尼:隐性知识理论的奠基者
    • 我们拥有的知识远超我们能够明确表述的知识;而我们据以行动和判断的,恰恰在很大程度上是这些无法言传的知识
    • AI 所擅长的,恰恰是处理显性知识:那些已被编纂、可被形式化为规则的知识。它能模拟风格,能重组信息,能依照模板批量生产
    • AI 根据”创业失败经验总结”模板生成的文章,在信息层面或许相差无几,但在那个最关键的隐性维度上——痛感的真实性、细节的颗粒度、情绪转折的分寸感——却有着天壤之别
    • 实用的策略:不要试图把自己变成一台更高效的内容生产机器,而要将精力倾注于机器无法复制的维度——深化你的个人经验,磨砺你的审美直觉,培育你与受众之间那种基于真实生命接触的信任纽带
    • 在显性知识唾手可得的时代,隐性知识反而成了最稀缺的资源。
    • 隐性知识的方法:它可以通过”内居”来获得——通过深度浸入一个实践共同体,通过与有经验的从业者近距离互动,通过反复的亲身实践与观察。
      • 其一,大量阅读和观看优秀作品——不是以”拆解方法论”的分析姿态,而是以”内居”的姿态,让好的节奏、好的结构、好的表达渗透进你的感觉系统,成为你身体的一部分。
      • 其二,持续且大量地创作。隐性知识只能在实践中生长,每一次写作、每一次剪辑、每一次发布后对读者反应的细致观察,都在你的认知结构中沉淀新的隐性层。
      • 其三,寻找”师傅”与社群。
  • 苏格拉底追问、维特根斯坦拆解、波兰尼兜底——我的系统再次升级
    • 维特根斯坦能帮你发现”哪里模糊”,通过命题分解:开口之前,先把你要说的话拆成三类——
      • F(事实,可验证的客观信息)、
      • D(欲望,你希望达成的状态)、
      • Q(困惑,你自己也不确定的部分)
      • example: “帮我优化一下这篇文章”这句话举例,
        • F 是”有一篇已经写好的文章”,这个是清楚的,
        • D 是”想让它变好”,但”好”是什么意思?这就模糊了,
        • Q 是”不确定到底该改什么”,这更模糊
    • 反诘法(Socratic Method):苏格拉底式提问, 追问 → 把能问出来的都问出来
    • 波兰尼:
      • 第一,示范——你发一份你觉得”对”的报告给我看,我从里面提取你说不出来的偏好,比如冷色调、数据前置、段落短、结论先行。
      • 第二,反面——你说不出来你要什么,那你说不要什么,“不要花哨的、不要像公众号、不要抒情”,否定句往往比肯定句更容易把默会知识逼出来。
      • 第三,行为提取——你以前写过自己满意的东西吗?发给我三篇,我从你过去的行为模式里反向提取你的隐含规则,比如你喜欢短句开头、从不用”首先其次最后”、数据永远带出处,这些你自己都没意识到的偏好
  • 人类认知崩溃指南:六层深渊、一个信封,以及为什么你越确定自己是对的,就越可能是错的
Back to Blog