Tagging and scope¶
A brain holds the memory of all of a user's projects in one graph. Tags written in the
source_description of each episode say which project, client and persona a memory belongs to, and
the scope argument of the search tools uses them to filter what comes back. This page describes
the tag convention, what the server adds or removes on a write, and how a read is scoped.
The source_description convention¶
source_description is an argument of add_memory. Spongram reads it as a
list of key=value tokens separated by spaces:
Parsing rules: tokens are split on whitespace, a token without = is ignored, and when a key
appears twice the first occurrence wins. A value cannot contain a space.
| Tag | Written by | Meaning | Used by the server for |
|---|---|---|---|
project=<slug> |
The agent; completed by the server when missing | The project or topic the memory belongs to. global and desktop-inbox are special values, see below. |
Read scoping, project aliases, the project inventory. |
repo=<owner/name> |
The agent, from the plugin's project context | The git remote of the session. | Provenance only. |
branch=<name> |
The agent, from the plugin's project context | The git branch of the session. | Provenance only. |
client=<name> |
The agent; completed by the server for recognised clients | Which client wrote the memory: claude-code, codex, claude-desktop. |
Provenance, and the default project of an untagged write. Searches never filter by client. |
persona=<slug> |
The agent, while a persona is active; validated by the server | The memory was learned in that persona's role. | Read scoping, persona summaries. |
capture=auto |
The server | The episode was written by the out-of-band transcript capture (POST /v1/memory/distill), not by an agent call. |
Provenance only. |
tag=failure_pattern |
The server | The episode comes from reflect_on_failure. |
Provenance only. |
tag=skill |
The server | Written on skills stored by record_skill. |
Provenance only. |
The canonical order is project= first, then repo=, branch=, client=, then any other tag.
The tool description sent to agents asks for it; the server itself does not depend on the order.
What the server does to the tags of a write¶
On every add_memory, after authentication and before the episode enters the queue, the server
applies three steps in this order. reflect_on_failure goes through the same steps, because it is
rewritten into an add_memory first.
1. Client tag¶
When the request carries X-Spongram-Client: claude-code or X-Spongram-Client: codex and the
source_description has no client= tag, the server appends client=claude-code or
client=codex.
- A
client=tag that is already present is never changed, even when it contradicts the header. - A request without the header, or with any other value, gets no client tag from the server.
- The header only labels the write. It never authorises anything.
- Controlled by
SPONGRAM_CLIENT_TAG_ENABLED, on by default. Only an explicit0,false,nooroffturns it off.
2. Project tag¶
A write without a project= tag receives one, placed first. Which one depends on
SPONGRAM_TOPIC_SCOPING_ENABLED (off in the code, on in the container image built from
spongram_proxy/Dockerfile):
| Topic scoping | Write without project= |
Tag added |
|---|---|---|
| Off | Any | project=global |
| On | Tagged client=claude-code |
project=global |
| On | Tagged client=codex (client tagging on) |
project=global |
| On | Anything else | project=desktop-inbox |
A write that already carries a project= tag is left as it is in every case.
3. Persona tag¶
When SPONGRAM_PERSONAS_ENABLED is on, the server validates persona=:
- a
persona=tag that names the brain's active persona is kept, once; - any other
persona=tag is removed; - without an active persona, every
persona=tag is removed.
The server never adds this tag: the agent marks what it learned in the persona's role, and the server only refuses a label the brain does not currently wear. See personas.
Optional source policy¶
SPONGRAM_CONSTITUTION_ENABLED (off by default) adds a check after these three steps: with
SPONGRAM_CONSTITUTION_ALLOWED_CLIENTS set to a comma-separated list, a write whose client= tag
is not in the list is refused with HTTP 422 and never enters the queue.
Special project values¶
project=global¶
global is the scope for facts that are true whatever the project: personal preferences, working
rules, decisions that cut across all of the user's work. A scoped search always keeps global
results next to the current project's, which is how a preference stated in one place is found
everywhere, from every client.
project=desktop-inbox¶
desktop-inbox is a holding bucket for writes that arrive with no project and no code client, when
topic scoping is on. It exists so that nothing falls into global by accident. Agents are never
told to use it. It is a project like any other for read scoping: a search scoped to another project
does not return it.
global and desktop-inbox are reserved: neither can be a project alias or the target of one.
Untagged episodes¶
Episodes written before tagging existed, or imported without tags, carry no project= tag. Read
scoping keeps them in every search, because dropping them would hide memory with no way for the
agent to ask for it. An operator can assign them a project with the admin route
POST /admin/api/spongram/instances/{id}/episodes/backfill-project-tag, which reports the
untagged episodes by default and writes only when called with dry_run=false and a project; see
the admin API.
Topic scoping¶
Claude Code and Codex know which repository a session runs in, so their plugins tag every write with
a project. Clients without a project context (Claude Desktop, or any plain MCP client) do not. With
SPONGRAM_TOPIC_SCOPING_ENABLED on, Spongram asks those clients, through the initialize
instructions and the add_memory description, to classify each conversation themselves:
- deduce a short kebab-case topic slug for the conversation and tag every write
project=<topic-slug> client=claude-desktop; - use the suggested prefixes where they fit, or a concise free-form slug:
participation-<company>(equity stakes, acquisitions),client-<name>(client work),devis-<name>(quotes and pricing),formation-<name>(trainings); - reuse the same slug for the whole conversation;
- announce the slug in one line the first time a memory is saved, so the user can correct it;
- keep
project=globalfor universal facts only, never for client, commercial or training content.
When SPONGRAM_PROJECT_ALIASES_ENABLED is also on, the instructions add one step: call
list_project_aliases once per conversation before inventing a new slug, and reuse an existing
project's canonical slug when one matches the subject.
The server-side fallback of this policy is the desktop-inbox row of the table above. The full text
sent to clients is in client contract.
The scope argument on searches¶
With SPONGRAM_READ_SCOPING_ENABLED on (off in the code, on in the container image), the server
filters search results by the tags of the episodes they come from. search_nodes and
search_memory_facts gain a scope argument in tools/list:
{
"name": "search_memory_facts",
"arguments": {
"query": "how do we deploy",
"scope": {"project": "my-project"}
}
}
| Field | Type | Meaning |
|---|---|---|
scope.project |
string | Slug of the current project. Must match ^[a-z0-9][a-z0-9._-]{0,63}$; any other value is ignored. |
scope.all |
boolean, default false |
true for a cross-project search. Meant for an explicit request from the user. |
The argument is read by Spongram and removed before the call is forwarded.
Note
When the flag is off, scope is not part of the schema and nothing filters reads: an agent has
to keep the current project and global by itself, from the tags it wrote. Do not send scope
to a server whose tools/list does not show it.
What is kept¶
For each result, Spongram looks up the source_description of its source episodes: the episodes
listed on a fact, or the episodes that mention an entity. Each episode is judged, then the result
takes the most favourable decision among its episodes.
| Episode tagged | scope.project given |
No scope.project |
scope.all: true |
|---|---|---|---|
persona= of the active persona |
Kept, moved to the top | Kept, moved to the top | Kept, moved to the top |
persona= of another persona |
Dropped | Dropped | Kept |
No project= tag |
Kept | Kept | Kept |
project=global |
Kept | Kept | Kept |
project= the scoped project, or one of its aliases |
Kept | Kept | Kept |
project= another project |
Dropped | Kept | Kept |
Consequences worth knowing:
- A result supported by several episodes is kept as soon as one of them is kept. A fact stated in two projects shows up in both.
- A call without any
scopestill hides the memory of personas that are not active. It does not hide other projects. - Results kept for the active persona are placed first and survive the truncation to
max_nodesormax_facts. - A result whose episodes cannot be resolved is kept. If the tag lookup itself fails, the whole answer is returned unfiltered.
_spongram.filtered¶
Whenever the filter ran, the payload carries a _spongram block:
filtered is the number of results dropped. It is how an agent learns that something exists
outside its scope: when filtered is above zero and nothing useful came back, the tool description
tells the agent to offer a cross-project search and to run it with scope.all: true only if the
user agrees.
Project aliases¶
When SPONGRAM_PROJECT_ALIASES_ENABLED is on, scope.project is resolved before filtering:
- an alias is replaced by its canonical project, and the canonical project's aliases are kept too;
- resolution has one level, there are no chains of aliases;
_spongram.scopethen shows the canonicalprojectand the list ofaliasesthat were included;- if the alias table cannot be read, the search filters on the slug it was given, and never widens.
An alias acts on reads only. No episode is rewritten: an episode tagged project=old-name keeps
that tag and is found again through the alias. Aliases are managed with
set_project_alias and described in
project aliases.
How the plugins derive the project slug¶
The Claude Code plugin and the Codex adapter compute the project of a session with the same module,
lib/project_context.py, so both clients file their memories under the same slug. The first rule
that yields a value wins:
| Order | Source | Details |
|---|---|---|
| 1 | SPONGRAM_PROJECT environment variable |
Must match [a-z0-9][a-z0-9-]{0,99}. An invalid value is an error: the plugin then injects no project context for the session. |
| 2 | The nearest .spongram.json |
Searched from the session directory up to the git root, or up to the home directory outside a repository. The first file found is authoritative: an invalid one yields nothing rather than letting a parent's file win. |
| 3 | The name of the main repository's directory | A linked git worktree resolves to the main checkout; a submodule keeps its own name. |
| 4 | The name of the session directory | Used outside a git repository. |
A .spongram.json is a small JSON file (4096 bytes at most):
The values of rules 2 to 4 are normalised: lowercased, every run of characters other than a-z,
0-9 and - replaced by one -, leading and trailing - removed. A file value must give 1 to 64
characters. A repository directory named My_App.v2 therefore gives my-app-v2.
Keep slugs at 64 characters or fewer: scope.project accepts no more.
The module also reads two provenance tags from git, and omits each one that does not match a safe pattern (so that a remote URL with credentials or a value with a space never reaches a tag):
repo=<owner/name>from theoriginremote;branch=<name>from the current branch.
Its output is the source_description the agent copies on every write:
To make several directories or repositories count as one project, commit the same .spongram.json
in each of them. A session in a linked worktree only sees files present in that worktree, so the
file must be committed, not just created. To attach labels that already exist in the brain, use a
project alias instead: it needs no change in any repository.
The plugins are described in Claude Code and Codex.