Anthropic recently released its auto memory feature, which boils down to nothing more than a paragraph in the system prompt You have a persistent Auto Memory directory at {DIR}. Its contents persist across conversations. As you work, consult your memory files to build on previous experience. When you encounter a mistake that seems like it could be common, check your Auto Memory for relevant notes — and if nothing is written yet, record what you learned… But we already know from experience that system-prompts and CLAUDE.md don’t work well enough – you need hooks to keep reminding the agent to do stuff. So I created a reminder hook which fires once every 10 agent turns, and works well in subagents. https://gist.github.com/ljw1004/ebd96122641074ea884aa68e277fb7c7 Download this gist to ~/.claude/learning-hook.py and chmod it executable Tell claude “please install a personal PostToolUse hook to run ~/.claude/learning-hook.py” From now on, if your project (i.e. claude startup directory) has a LEARNINGS.md file, then Claude will be told and reminded to use it. This hook is novel in two ways: I think that for swarms of subagents, it’s vital that the subagents can participate in memory too. But the Claude hook API is “global” – there’s no way to know whether your hook is running for the main agent or a subagent, and if so which one. There are quite a few open github issues complaining about this. I found a workaround: I use a PostToolUseHook, and it scans all transcript for an assistant message with the same tool_use_id, and hence it can learn which agent or subagent was the one who triggered the hook. I think that form swarms of subagents, it’s vital that reminders come even to the autonomous agents running in their agentic loop. But the Claude hook API doesn’t offer any way to do this: it only allows for hooks that run on user prompts (which autonomous agents don’t even have) or on every tool-use (which is far too frequent for reminders). I wanted a reminder about once every 10 turns even while the agent is within its agentic loop. I found a workaround: even though my PostToolUseHook is invoked for every single tool use, I coded in the invariant that only the first hook to be invoked every 10th assistant message should deliver the reminder; all others should stay silent. This is nice because my hook can be entirely stateless. I’m using this in my Claude swarms to have the workers be better able to (more likely to) contribute to the shared auto-memory. submitted by /u/lucianw
Originally posted by u/lucianw on r/ClaudeCode
