Skip to main content

Module memory_dir_claims

Module memory_dir_claims 

Source
Expand description

Is a memory directory this agent’s alone? (SPEC_MEMORY_FOLLOWS_THE_AGENT_2026_09_24.md §2.1.2, phase M3b.)

A Claude memory directory is keyed by account + working directory, not by agent, so two agents can share one — the same account and working directory, or two unlinked agents with the same working directory. The memory record may project into, capture from, or delete in a directory only when it is proven exclusive; a shared one is left exactly as it is.

A directory is shared unless proven exclusive:

  1. Known shared locations — a blank working directory (the ~/.agentmux/agents/<slug> default, shared across same-name tabs), $HOME, or an ancestor of another agent’s working directory. And any folder the CLI keys by a whole repository rather than this working directory alone: a subdirectory or linked worktree of a repository, or a main checkout with linked worktrees (crate::backend::claude_layout::memory_project_root).
  2. Vetoes — any other agent whose directory resolves, by any route, to the same canonical directory. Guesses count here (a veto only ever removes a directory; the resolver never uses one to find memory).
  3. A machine-wide claim — zone memory-dir:<hash> in the global store. Every spawn that uses the folder records one, a shared one too: channels share projects/ folders, and an agent in another channel is visible here only through its claim. A claim by another UID makes the folder shared. A claim is released only by the channel store that wrote it, once that store no longer has the agent and no active shared definition does — another channel can’t tell a live agent of its neighbour’s from a deleted one.

Structs§

Claim 🔒
ClaimedFolder 🔒
A folder an agent has claimed, for the human “release this folder” action (spec §2.1.2).
Claims 🔒

Enums§

Exclusivity 🔒
SharedReason 🔒

Constants§

CLAIMS_FILE 🔒

Functions§

check_and_claim 🔒
Decide whether dir — the memory directory uid’s spawn uses, from working directory cwd — is exclusive to uid, recording uid’s claim. Checks that can’t finish by deadline leave the directory Unproven, i.e. shared.
claim_is_stale 🔒
Whether a claim can be shown to be stale: only the store that wrote it can say its agent is gone.
claims_of 🔒
Every folder uid holds a claim on, on this machine.
claims_zone 🔒
dir_id 🔒
A directory’s canonical form: symlinks resolved as far as the path exists (the per-channel projects/ links into the shared store), the rest kept as given. Two routes to one folder get one id.
held_exclusively 🔒
Whether uid still holds the only claim on dir — the re-check before every capture while the agent runs (spec §2.1.3). Read-only: the full check ran at spawn; this sees any agent that has claimed it since.
known_shared_or_vetoed 🔒
Rules 1 and 2: no store writes.
release 🔒
Remove uid’s claim in zone — a human released the folder. Returns whether there was one. The agent re-claims it at its next spawn there.
used_by_another 🔒
Whether another agent uses dir: it has claimed it (in any channel), or resolves to it in this channel’s store. Read-only. For offering a folder for adoption (spec §2.1.4), which must exclude folders shared with another agent.