#learnings from code.

1 messages ยท Page 1 of 1 (latest)

brazen spoke
#

these are some changes I made based on what we learned about Claude code.

trail lava
#

gist gist gist gist gist

#

its a giant paste field that people can load and get a huge chunk of text ๐Ÿ™‚

brazen spoke
#

Here's a post for the OpenClaw Discord:


Post-Claude Code Leak: What We Actually Implemented

After the Claude Code source leak dropped last week, we did a gap analysis of Anthropic's internal system prompt patterns against our agent's constitution. Here's what we adopted and what we skipped.

Memory Architecture (inspired by Claude Code's 4-tier context management):

We implemented the full stack:

  • Tier 1-2: Session pruning โ€” contextPruning.mode: "cache-ttl" with 5m TTL, soft-trim at 30%, hard-clear at 10%. Old tool results get trimmed automatically instead of bloating context to 700K+ tokens.
  • Tier 3: Proactive compaction โ€” compaction.maxHistoryShare: 0.7 with custom instructions telling Sonnet what to preserve (decisions, corrections, task state) and what to drop (API responses, grep output). Compaction model is Sonnet, not the primary model.
  • Tier 4: Reactive โ€” already built into OpenClaw.

We also adopted Claude Code's MEMORY.md pointer pattern โ€” a lightweight ~80-line index file that's always in context and points to where actual knowledge lives. Survives compaction. Combined with a session_state.json for structured task/blocker tracking and a nightly distillation cron that consolidates daily logs into the pointer index.

The real impact: Our sessions were regularly hitting 700K tokens with the primary model doing all the heavy lifting. Now pruning keeps context lean, compaction triggers at 70% instead of emergency-only, and the compaction summary is higher quality because it's working with conversation + recent results, not 500KB of stale curl output.

Constitutional Upgrade (10 new operational rules from the leak analysis):

We reviewed 12 patterns from Anthropic's internal prompts and adopted 10. The ones that made the biggest difference:

  1. Outcome Honesty โ€” don't suppress failures, don't hedge successes. We caught that a "zero-cost" model routing had been silently failing for weeks, falling back to a paid model. Every heartbeat reported "OK" but the logs showed fetch failed on every request. This rule would have caught it day one.

  2. Diagnose Before Switching Tactics โ€” read the error before retrying. We had a sub-agent model routing issue where we tried 6 different config approaches over multiple days. One grep of the error log would have found the root cause immediately.

  3. Preserve Critical Data Through Compaction โ€” echo key facts in your response text, not just tool results. When pruning clears old tool output, the facts survive in the conversation if you stated them explicitly.

  4. Synthesize Before Delegating โ€” never write "based on your findings" in a sub-agent prompt. If you can't include the specific file paths, values, and actions, you didn't understand the findings. We were forwarding raw sub-agent output to the user without verifying โ€” that's how incorrect data (wrong employment status, wrong gender attributions) made it through.

  5. Validation Failure Mode Awareness โ€” two patterns to watch: (a) "verification avoidance" where you narrate what you'd test instead of running the test, and (b) "first-80% seduction" where surface-level results look clean but the deep quality is wrong.

What we skipped:

  • Action Reversibility (#10) โ€” already covered by our autonomous recovery authorization
  • Proactive Information Persistence (#12) โ€” already had "write to memory proactively" as a rule

Config changes that came from this:

{
  "compaction": {
    "mode": "default",
    "maxHistoryShare": 0.7,
    "keepRecentTokens": 50000,
    "recentTurnsPreserve": 4,
    "model": "sonnet",
    "customInstructions": "Preserve: xxx corrections, task state, findings, Notion IDs. Drop: tool output, API responses."
  },
  "contextPruning": {
    "mode": "cache-ttl",
    "ttl": "5m",
    "softTrimRatio": 0.3,
    "hardClearRatio": 0.1,
    "minPrunableToolChars": 500
  }
}

The constitutional rules are in our agent's operational config