Module native_memory_handlers

Module native_memory_handlers 

Source
Expand description

Native memory RPCs — read/write the agent’s ~/.claude/projects/<sanitized>/memory/ folder that Claude Code uses for autonomous, cross-session fact storage.

Three commands: agent:memory:list — list *.md files in the memory dir agent:memory:read_file — read one file by filename (no path traversal) agent:memory:write_file — write/create one file atomically (tmp→rename)

Spec: docs/specs/SPEC_AGENT_PANE_MEMORY_IDENTITY_MODALS_2026_06_19.md §7

Functions§

djb2_hash 🔒
Hash matching Claude Code’s sessionStoragePortable.ts implementation. JS charCodeAt() iterates UTF-16 code units (two surrogates per non-BMP char); Rust chars() iterates Unicode scalar values — they diverge for emoji/non-BMP. encode_utf16() produces the same UTF-16 unit stream as JS, so the hashes match.
memory_dir_for_cwd 🔒
Compute ~/.claude/projects/<sanitized>/memory/ for the given working directory.
parse_frontmatter_type 🔒
Extract metadata.type from YAML frontmatter. Claude Code memory files nest the type under metadata:: metadata: type: user A top-level type: key is NOT the correct field.
radix_36 🔒
Convert a u32 to a base-36 string (lowercase, same as Number.toString(36) in JS).
register_native_memory_handlers
validate_filename 🔒
Validate a filename: alphanumeric + -_, must end with .md, no path separators.