🦞OpenClaw Guide
← Back to BlogOptimization

OpenClaw Session Initialization: How to Cut Context Size by 80% (Stop Loading 50KB Every Message)

2026-03-177 min read

OpenClaw Session Initialization: How to Cut Context Size by 80% (Stop Loading 50KB Every Message)

Target keywords: openclaw session initialization, openclaw context size


$0.40 per session vs $0.05 per session

That's not a rounding error. That's an 8x cost difference — and it comes down to one thing: what your agent loads when a session starts.

By default, OpenClaw is eager. It tries to be helpful by pulling in everything it might need: your full memory file, session history, prior tool outputs, previous messages. The thinking is reasonable — your agent should have context. The problem is it does this on every single message, every single session, whether the context is relevant or not.

The result? You're burning 2–3 million tokens per session on history your agent probably doesn't need. At $0.003 per 1K tokens (Sonnet pricing), that's $0.40 per session, $4/day if you're running sessions throughout the day. Scale that up and you're looking at $100+/month just on context overhead — before you've done a single useful task.

This guide covers exactly how to fix it with a session initialization rule: a simple set of instructions you add to your system prompt that tells your agent what to load (and what to skip) at session start.


What Session Initialization Is — and Why the Default Is Expensive

Every time you start a session with OpenClaw, your agent initializes its context. Without explicit rules, it defaults to loading as much relevant history as it can find. This includes:

  • Your full MEMORY.md file (can be 10–30KB+ once you've been using the agent for a few weeks)
  • Recent session history and prior messages
  • Previous tool outputs
  • Any files referenced in your workspace

The intent is good: give the agent context so it can pick up where you left off. The execution is expensive: you're paying for every token in that initial context load, every time.

Here's what makes this particularly wasteful: most of that history is irrelevant to what you're about to do. If you're asking your agent to draft an email, it doesn't need your conversation from three days ago about a deployment issue. If you're checking on a project, it doesn't need the full output of a web search you ran last Tuesday.

The 50KB context load is a blunt instrument. You need a scalpel.


The Exact Session Initialization Rule

This is the full prompt block you add to your SOUL.md or system prompt. Copy it verbatim:

SESSION INITIALIZATION RULE:
On every session start:
1. Load ONLY these files:
   - SOUL.md
   - USER.md
   - IDENTITY.md
   - memory/YYYY-MM-DD.md (if it exists)
2. DO NOT auto-load:
   - MEMORY.md
   - Session history
   - Prior messages
   - Previous tool outputs
3. When user asks about prior context:
   - Use memory_search() on demand
   - Pull only the relevant snippet with memory_get()
   - Don't load the whole file
4. Update memory/YYYY-MM-DD.md at end of session with:
   - What you worked on
   - Decisions made
   - Leads generated
   - Blockers
   - Next steps
This saves 80% on context overhead.

That's it. No scripts, no config changes, no infrastructure. Just these instructions in your system prompt, and your agent knows exactly what to load.


Line-by-Line: What Each Rule Does

Rule 1: Load ONLY these files

SOUL.md, USER.md, and IDENTITY.md are your essential context. They define who the agent is, who you are, and how it should behave. These are small (typically 1–3KB each), stable, and genuinely needed on every session. Today's daily note (memory/YYYY-MM-DD.md) is also worth loading — it gives the agent a quick snapshot of what happened recently without pulling in weeks of history.

Total startup context: ~5–8KB. That's it.

Rule 2: DO NOT auto-load these

This is the high-value rule. MEMORY.md (your accumulated knowledge graph) can grow to 30KB+. Session history across dozens of past conversations can be even larger. Previous tool outputs (web search results, API responses, file contents) add bulk with zero value on the next session.

Banning these from auto-load is where you recover the majority of your wasted tokens.

Rule 3: On-demand memory retrieval

When you ask the agent about something from the past, it doesn't load the whole MEMORY.md — it uses memory_search() to find the relevant snippet, then memory_get() to pull only that piece. This is the key insight: you get the benefit of the memory system without the cost of loading all of it upfront.

You're switching from "load everything, use what's relevant" to "load nothing, fetch what's needed." This is how well-designed database systems work. It works for agent memory too.

Rule 4: End-of-session memory update

This closes the loop. Instead of loading history at the start, you write a compact summary at the end — what you worked on, decisions made, blockers, next steps. Tomorrow's session loads this tiny file and gets everything it needs. The daily note format keeps the total footprint small even as you use the agent over months.


How to Implement It

Option 1: Add to SOUL.md

Open your ~/clawd/SOUL.md and paste the SESSION INITIALIZATION RULE block under an ## Operational Rules section. This is the recommended approach — your SOUL.md is already loaded at session start, so the rule will always be active.

## Operational Rules

### Session Initialization
SESSION INITIALIZATION RULE:
On every session start:
1. Load ONLY these files:
   - SOUL.md
   - USER.md
   - IDENTITY.md
   - memory/YYYY-MM-DD.md (if it exists)
[... full rule block ...]

Option 2: Add directly to system prompt

If you're running OpenClaw with a custom system prompt, add the rule block there. It works anywhere your agent reads instructions at startup.

Verify it's working:

openclaw shell
session_status
# Look for: Context size: 2-8KB (not 50KB+)

If context size is still 40–50KB, check that your SOUL.md is being loaded and the rule block wasn't accidentally truncated.


Before vs After: The Numbers

❌ Before✓ After
Context on startup50KB8KB
Tokens loaded per session2–3M~200K
Cost per session (Sonnet)~$0.40~$0.05
History behaviorAuto-loaded alwaysFetched on demand
Works with all interfaces

The 80% reduction in context size maps directly to an 80% reduction in startup token cost. For power users running multiple sessions per day, this is the single highest-impact optimization in the whole guide.

At 10 sessions/day: $0.40 × 10 = $4.00/day before. $0.05 × 10 = $0.50/day after.

That's $105/month saved from a 10-line prompt addition.


What "On-Demand Memory" Means and Why It Works

The conceptual shift here is important. You're not giving your agent less memory — you're giving it smarter memory access.

Think of it like the difference between carrying a library in your backpack vs knowing how to use a library catalog. The backpack approach loads everything upfront. The catalog approach loads nothing upfront and retrieves exactly what you need, when you need it.

memory_search() is the catalog. It scans your full MEMORY.md semantically and returns the relevant snippet — typically 200–500 tokens — instead of the whole 30KB file. If you ask your agent "what did we decide about the database architecture?" it searches, finds that specific entry, and returns it. You pay for 400 tokens instead of 30,000.

The daily notes pattern (memory/YYYY-MM-DD.md) reinforces this. Instead of one growing monolith that gets more expensive to load every day, you have small daily files that stay compact. Recent sessions load naturally. Older history stays archived and only loads when explicitly searched.

This architecture scales indefinitely. The cost of a session start doesn't grow as you use the agent more — it stays flat at ~8KB because the initialization rule is fixed and the daily note is always a fresh, small file.


Key Takeaways

  • The default is expensive by design: OpenClaw loads everything it might need. You need to tell it what to actually load.
  • The rule is in the prompt, not the config: No scripts, no file changes. Just add the SESSION INITIALIZATION RULE block to SOUL.md.
  • 8KB vs 50KB: That's your new baseline. Session starts clean, every time.
  • On-demand beats preloaded: memory_search() + memory_get() gives you the benefits of full memory at a fraction of the cost.
  • Daily notes are the glue: They keep your cross-session continuity tight without accumulating into an expensive blob.
  • Verify with session_status: After implementing, confirm context size drops to 2–8KB.

This is step one of five optimizations that combined take you from $1,500+/month to under $50/month. It's also the fastest to implement — less than five minutes to add the rule, immediate results on the next session start.

Learn alongside 1,000+ operators

Ask questions, share workflows, and get help from people running OpenClaw every day.