claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

Memory is not loaded automatically

Open 870561859 opened this issue 5 months ago • 1 comments

I encountered an issue while using the Agent Python SDK. My project contains a MEMORY.md file. When using different session IDs within the same project, the MEMORY.md content fails to load automatically. It only loads after I explicitly instruct Claude to access it. Could you explain why this happens?

870561859 avatar Jun 24 '26 08:06 870561859

This is the expected default behavior,

The MEMORY.md is a dynamic section of the claude_code system-prompt preset, and is documented in the exclude_dynamic_sections docstring at types.py#L43. The SDK defaults system_prompt=None, which sends an empty prompt with no preset, you can see this here subprocess_cli.py#L227-L228. As a result, the section is never injected and the model only sees MEMORY.md when it Reads the file.

You can opt into the preset and keep project in setting sources:

options = ClaudeAgentOptions(
    system_prompt={"type": "preset", "preset": "claude_code"},
    setting_sources=["user", "project", "local"],  # None also works; [] disables it
)

Magic-Man-us avatar Jun 27 '26 19:06 Magic-Man-us