Skip to content

MEMORY.md is fully injected into system prompt despite memory_search/memory_get being available #26949

@cclank

Description

@cclank

MEMORY.md is fully injected into system prompt despite memory_search/memory_get being available

Summary

MEMORY.md is unconditionally injected in full into the system prompt as part of Project Context → Workspace Files. At the same time, the system prompt also instructs the model to use memory_search and memory_get tools for memory recall. This creates a paradox: if the model is expected to search memory on demand, why is the entire memory file pre-loaded into the context on every request?

For users who accumulate substantial long-term memory (rules, milestones, project states, lessons learned), MEMORY.md can easily grow to 9,000+ characters (~2,300–3,800 tokens), making it one of the largest contributors to system prompt cost.

Observed behavior

In a captured request payload from a clean conversation:

  • MEMORY.md full content (~9k chars) is injected under # Project Context in the system prompt
  • The system prompt also contains ## Memory Recall rules instructing the model to run memory_searchmemory_get before answering memory-related questions
  • memory_search and memory_get are both available in body.tools[]

This means the model receives the same information twice: once passively via system prompt injection, and once actively via the search/retrieval tools.

Expected behavior

Ideally, users should have the option to control whether MEMORY.md is fully injected or only accessible via memory_search/memory_get. A possible approach:

Option A: Configuration flag

Add a workspace-level or agent-level config option, e.g.:

workspace_files:
  MEMORY.md:
    inject: false  # do not inject into system prompt; rely on memory_search/memory_get

When inject: false, the file is still indexed by memory_search but not included in the system prompt.

Option B: Encourage content tiering (documentation)

As an interim solution, document the best practice of keeping MEMORY.md lean (only critical, high-frequency rules) and moving detailed/historical content to memory/*.md daily log files, which are not auto-injected but are searchable via memory_search.

Impact

Scenario MEMORY.md size Tokens saved per request
Light user ~2k chars ~500–800
Power user ~9k+ chars ~2,300–3,800

For power users on pay-per-token providers, this adds up quickly across hundreds of daily interactions.

Environment

  • OpenClaw: latest (self-hosted)
  • Debug method: custom model provider proxy (modelbox) to capture full request payloads

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions