codex - 💡(How to fix) Fix Topic-based memory directory with agent-initiated writes and /memory slash command [1 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#19758Fetched 2026-04-28 06:37:39
View on GitHub
Comments
0
Participants
1
Timeline
9
Reactions
0
Participants
Timeline (top)
labeled ×5unlabeled ×3subscribed ×1

Code Example

~/.codex/memories/
  MEMORY.md              # Compact index / entrypoint
  memory_summary.md      # Legacy fallback
  topics/
    coding_style.md
    test_preferences.md
    api_patterns.md
    user_profile.md

---

---
name: Coding Style
description: Preferred patterns for this repo
type: project   # user | feedback | project | reference
keywords: [rust, clippy]
source: auto    # auto | user
updated_at: 2026-04-26T14:00:00Z
---

---

{
  "topic": "test_preferences",
  "content": "Always use pytest with the -x flag",
  "append": true,
  "type": "project",
  "keywords": ["pytest", "testing"]
}
RAW_BUFFERClick to expand / collapse

What feature would you like to see?

A topic-based memory architecture that combines Claude Code's memdir layout with oh-my-codex-style agent-initiated memory writes, plus a user-facing /memory slash command.

Problem Statement

  1. Monolithic memory_summary.md does not scale: As memory grows, the single-file format becomes unwieldy for both the agent and users. It is hard to navigate, and loading the entire file into the system prompt wastes tokens.
  2. Agent is forbidden from writing memories: The current developer instructions explicitly tell the agent "Never update memories. You can only read them.". This means when a user says "remember that I prefer X", the agent cannot persist it directly. Users must either wait for the async Phase-1/2 consolidation pipeline or manually edit memory files.
  3. No CLI memory management: There is no slash command to list, edit, add, or clear memory topics without leaving the TUI.

Proposed Solution

1. Subfile Memory Directory (topics/*.md)

Introduce a topics/ subdirectory under ~/.codex/memories/ (and per-project memory roots) where each memory topic is an independent markdown file with YAML frontmatter:

~/.codex/memories/
  MEMORY.md              # Compact index / entrypoint
  memory_summary.md      # Legacy fallback
  topics/
    coding_style.md
    test_preferences.md
    api_patterns.md
    user_profile.md

Frontmatter schema:

---
name: Coding Style
description: Preferred patterns for this repo
type: project   # user | feedback | project | reference
keywords: [rust, clippy]
source: auto    # auto | user
updated_at: 2026-04-26T14:00:00Z
---

Benefits:

  • Relevance-based loading: scan frontmatter, inject only the top-N most relevant topics (plus MEMORY.md index) into the system prompt, reducing token usage.
  • Independent mutability: each topic can be read, written, or versioned independently.
  • Freshness awareness: memories older than a threshold get a <system-reminder> caveat about potential staleness.

2. /memory Slash Command

Add a /memory (or /memories) command to the TUI:

CommandAction
/memory listDisplay all topic names and descriptions
/memory edit <topic>Open $EDITOR to edit an existing topic
/memory add <topic>Create a new topic with a frontmatter template
/memory clearRemove all .md files under topics/

This mirrors Claude Code's /memory edit UX and gives users explicit, immediate control.

3. Agent-Initiated Memory Writes (memory_write tool)

Expose a new built-in tool memory_write to the agent so it can persist knowledge in real time:

{
  "topic": "test_preferences",
  "content": "Always use pytest with the -x flag",
  "append": true,
  "type": "project",
  "keywords": ["pytest", "testing"]
}

Behavior:

  • If append: true, append content to the existing topic body.
  • If append: false (default), overwrite the topic file with new frontmatter + content.
  • The tool writes only inside the memory root (~/.codex/memories/topics/), similar to how the consolidation sub-agent is sandboxed to the memory root.

Why this matters:

  • Users can naturally say "remember that I prefer 2-space indentation" and the agent persists it immediately.
  • Before context compaction, the agent can proactively checkpoint critical state.
  • The existing Phase-1/2 pipeline continues to run in the background for automatic extraction, but explicit writes are instant and user-driven.

4. Scoped Memory (complementary to #18343)

The topic directory naturally supports scoping:

  • Global memories: ~/.codex/memories/topics/
  • Project memories: <project-memory-dir>/topics/
  • Hybrid loading: load project topics first, then global topics, with project taking precedence.

Backward Compatibility

  • If topics/ is empty, the prompt injection falls back to the existing memory_summary.md.
  • Phase-1/2 consolidation can continue writing the old format while gradually migrating to topic files.
  • No breaking changes to existing AGENTS.md or memory_summary.md behavior.

Related Issues

  • #8368 — Long-term Memory (closed; this proposal extends the POC described there with a concrete directory structure and agent write capability)
  • #18343 — Scoped memory management for Codex (complementary; topic directories make scoping trivial)
  • #6532 — Add small list of commands to memory for common tool
  • #3043 — Add memory functionality similar to Claude code

Are you interested in implementing this feature?

I have a working prototype of the memdir layout and /memory slash command in a local fork. I am happy to share a detailed design doc, help with implementation, or iterate on the approach if the team sees value in this direction.

extent analysis

TL;DR

Implement a topic-based memory architecture with a subfile directory structure and agent-initiated memory writes to improve memory management and scalability.

Guidance

  • Introduce a topics/ subdirectory under ~/.codex/memories/ to store individual memory topics as markdown files with YAML frontmatter.
  • Implement the /memory slash command to provide users with explicit control over memory management, including listing, editing, adding, and clearing topics.
  • Expose a memory_write tool to the agent to enable real-time persistence of knowledge, allowing users to naturally interact with the system and persist preferences.
  • Ensure backward compatibility by maintaining support for the existing memory_summary.md format and Phase-1/2 consolidation pipeline.

Example

{
  "topic": "test_preferences",
  "content": "Always use pytest with the -x flag",
  "append": true,
  "type": "project",
  "keywords": ["pytest", "testing"]
}

This example demonstrates the format for the memory_write tool, which can be used to append or overwrite topic files.

Notes

The proposed solution builds upon existing issues and features, such as #8368 and #18343, and provides a concrete directory structure and agent write capability. The implementation should ensure seamless integration with the existing system and provide a smooth transition for users.

Recommendation

Apply the proposed solution, as it addresses the current limitations and provides a scalable and user-friendly memory management system. The introduction of the topics/ subdirectory and /memory slash command will improve the overall user experience, while the memory_write tool will enable real-time persistence of knowledge.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING