claude-code - 💡(How to fix) Fix Memory-file Write/Edit silently rewrites YAML frontmatter (nests top-level keys, truncates `description` at #, slugifies `name`)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

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…

When a Markdown file under the memory directory is written via the Write or Edit tool, Claude Code silently rewrites its YAML frontmatter before the file reaches disk. Three transformations occur, none requested or opt-out-able:

  1. Top-level keys are nested under metadata: — every frontmatter key except name, description, and metadata is moved into a metadata: block.
  2. description: is truncated at the first # — an unquoted description containing # loses everything from the # onward (YAML treats it as a comment).
  3. name: is slugified — downcased and kebab-cased.

node_type: memory and originSessionId: <uuid> are also injected.

This breaks any tooling — user hooks, sync scripts, downstream parsers — that reads top-level frontmatter fields, because those fields are no longer where they were written.

Root Cause

This breaks any tooling — user hooks, sync scripts, downstream parsers — that reads top-level frontmatter fields, because those fields are no longer where they were written.

Code Example

---
name: Formatter Repro Test
description: Tracking PR #762 and issue #800 — note the # characters
type: feedback
triggers: ["alpha phrase", "beta phrase"]
session: false
---

Body text.

---

---
name: formatter-repro-test
description: Tracking PR
metadata:
  node_type: memory
  type: feedback
  triggers:
    - alpha phrase
    - beta phrase
  session: false
  originSessionId: <session-uuid>
---

Body text.
RAW_BUFFERClick to expand / collapse

Summary

When a Markdown file under the memory directory is written via the Write or Edit tool, Claude Code silently rewrites its YAML frontmatter before the file reaches disk. Three transformations occur, none requested or opt-out-able:

  1. Top-level keys are nested under metadata: — every frontmatter key except name, description, and metadata is moved into a metadata: block.
  2. description: is truncated at the first # — an unquoted description containing # loses everything from the # onward (YAML treats it as a comment).
  3. name: is slugified — downcased and kebab-cased.

node_type: memory and originSessionId: <uuid> are also injected.

This breaks any tooling — user hooks, sync scripts, downstream parsers — that reads top-level frontmatter fields, because those fields are no longer where they were written.

Reproduction

Claude Code 2.1.146, macOS (arm64).

  1. Use the Write tool to create a .md file under the memory directory (~/.claude/projects/<project>/memory/) with:
---
name: Formatter Repro Test
description: Tracking PR #762 and issue #800 — note the # characters
type: feedback
triggers: ["alpha phrase", "beta phrase"]
session: false
---

Body text.
  1. Read the file back from disk.

Expected

Frontmatter preserved as written (whitespace normalization at most).

Actual

---
name: formatter-repro-test
description: Tracking PR
metadata:
  node_type: memory
  type: feedback
  triggers:
    - alpha phrase
    - beta phrase
  session: false
  originSessionId: <session-uuid>
---

Body text.
  • name: Formatter Repro Testformatter-repro-test
  • description: Tracking PR #762 and issue #800 — note the # charactersTracking PR (truncated at the first #)
  • type, triggers, session: relocated under metadata:

Impact

  • Any hook or script reading a top-level frontmatter key (e.g. type:) silently sees nothing — the value moved to metadata.type. In our setup this broke a memory-routing pipeline: files written with top-level type: failed classification because the router reads top-level only, and silently piled up in an _unrouted/ directory.
  • The #-truncation is data loss — issue/PR references (#762), or any # in a description, are destroyed. Surprising, since the rest of the description is preserved.
  • The rewrite is silent: no diff, no notice; the tool reports success with the content the user supplied, while a different thing lands on disk.

Notes

  • Only fires for .md files under the recognized memory directory; files elsewhere are untouched.
  • Happens inside the Write/Edit tool body, before the file is written — it is not a PostToolUse hook and cannot be disabled via ~/.claude/settings.json.
  • The #-truncation is a YAML-serialization side effect: the rewritten description is emitted unquoted, so # starts a comment. Quoting string values on re-serialization would fix that effect.

Suggested fix

A way to preserve frontmatter as authored — either:

  • preserve top-level keys (don't relocate them under metadata:), or a setting to opt out of the memory-file frontmatter normalization; and
  • always quote string values when re-serializing, so # (and :) in description/name survive.

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

claude-code - 💡(How to fix) Fix Memory-file Write/Edit silently rewrites YAML frontmatter (nests top-level keys, truncates `description` at #, slugifies `name`)