[BUG] Auto-memory doesn't work in pipe mode (`-p`) when `--system-prompt` is passed

Resolved 💬 3 comments Opened Mar 8, 2026 by jwross24 Closed Apr 9, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Auto-memory files are never written in pipe mode. I traced through the compiled bundle (v2.1.71) and found two internal gates that contradict each other.

The system prompt only includes memory instructions when m5q() returns true (CLAUDE_COWORK_MEMORY_PATH_OVERRIDE is set):

n = typeof Y === "string" && m5q() ? $kq() : null
e = f4([...typeof Y === "string" ? [Y] : g, ...n ? [n] : [], ...D ? [D] : []])
// e is the systemPrompt passed to the API loop

But the write permission handler only allows memory writes when m5q() returns false (env var NOT set):

if (!m5q() && lI_(path))
  return { behavior: "allow", reason: "auto memory files are allowed for writing" }

Without the env var: write permission works, but Claude never gets memory instructions, so it never tries to write.
With the env var: Claude gets memory instructions, but the write permission check blocks the file write.

No configuration satisfies both gates. Interactive mode is fine because its system prompt builder (TM function) calls kq_("memory", () => $kq()) unconditionally, no m5q() gate.

What Should Happen?

Auto-memory should work in pipe mode the same way it does interactively. Claude should get auto-memory instructions in its system prompt AND have write permission to the memory directory. The fix is probably just removing the m5q() gate from the system prompt inclusion in the pipe mode path, so it matches what TM already does for interactive mode.

Error Messages/Logs

Steps to Reproduce

  1. Run any prompt in pipe mode:

``bash
echo "Create a hello world script" | claude -p
``

  1. Check the auto-memory directory (~/.claude/projects/<project-path>/memory/)
  2. No memory files are written

Alternatively, set CLAUDE_COWORK_MEMORY_PATH_OVERRIDE and repeat:

  1. ```bash

CLAUDE_COWORK_MEMORY_PATH_OVERRIDE=/tmp/memory echo "Create a hello world script" | claude -p
```

  1. Claude now tries to write memory but gets a permission denial

Neither configuration produces working auto-memory.

Workaround: --append-system-prompt bypasses the broken gate. The append parameter (D in the minified source) is added to the system prompt without checking m5q(). Combined with NOT setting the env var, write permissions pass:

echo "do something" | claude -p --append-system-prompt "You have a persistent auto memory directory at /path/to/memory/. Save patterns and insights to memory files using the Write tool."

Claude Model

None

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.71 (also confirmed in 2.1.69)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

Also reproduced inside Docker containers (Ubuntu). The bug is in the pipe mode code path and is not platform-specific.

I traced this by reading the compiled SEA binary and following the minified function calls. The relevant functions in v2.1.71:

  • m5q(): returns true when CLAUDE_COWORK_MEMORY_PATH_OVERRIDE is set
  • $kq(): builds the auto-memory prompt (calls VA() then Dq$())
  • RF8(): file write permission handler
  • TM(): interactive mode system prompt builder (no m5q gate)
  • submitMessage(): pipe mode system prompt builder (has m5q gate)

In v2.1.69, same functions exist with different names (Fq1 for m5q, MD1 for $kq).

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗