Sharing rules

The rules engine watches your captured facts and nominates share-worthy moments — or, where you've explicitly said so, shares them automatically. This page is the complete specification of the rules file, share-rules.yml. It is written to be sufficient for an agent to set up or modify a user's rules correctly; the system overview lives at sharing.

Where the rules live

The rules live on your shmem server, in your account, which is where they run: shmem share rules shows them and shmem share rules --edit edits them, and an agent reads and changes them with the get_share_rules and set_share_rules tools. Both refuse a write based on rules that changed in the meantime, so two edits can't clobber each other. ~/.shmem/share-rules.yml is kept as a copy of the server's.

The first sharing command after you add a remote moves this machine's rules to the server, if you changed them from the starter rules and the server's are still the starter rules, along with the nominations you discarded, so what you turned down stays turned down. If you have your own rules on both, the server's apply: the command says so and keeps this machine's version in share-rules.yml.local. Pending nominations don't move; the server makes its own.

How the scan works

The server's scan (run after your writes arrive, by agents via scan_shares, or by hand with shmem share scan) gathers your new captures since the last scan, evaluates them against your rules, and produces nominations. Each one ships in the first of three forms that works:

  1. Raw: the span of existing facts, shared as-is, except that each tool call ships as its call line, its output left out (unless the rule sets tool-output: keep). Text the agent wrote through a call stays: a commit message, a PR or issue body or comment passed in a heredoc, and a Markdown or text file written with Write. A span that would ship only bare call lines isn't nominated. This is the default whenever nothing in the span breaks a never rule and the span is under 8,000 characters.
  2. Redacted: when some parts can't go but the rest can, the span itself with just those parts replaced: a name or figure by a placeholder such as [client], [amount], or [person], a whole sentence or paragraph that holds something a never rule covers, or is noise (an offer to do more, a tool-output dump), by [omitted]. Everything else, explanations and proposed fixes included, ships as written. It ships fact by fact, so readers still see who said what and when: a fact the redaction changed ships as a new fact with its redacted text, in its place and under its speaker, and a fact with nothing shareable left ships as [omitted]. A span over the raw limit is trimmed the same way, leaving its noise out until it fits. Your original facts are never edited. shmem checks each fact's redaction on its own: whitespace aside, it must be the original text with short parts swapped for placeholders and whole sentences or lines left out. A fact that fails is asked for once more, told what was wrong; if it fails again, that fact alone is narrated, in its place and under its speaker, and the rest of the span ships as redacted. Only when the span as a whole keeps less than 30% of its text (and under 2,000 characters) is the whole moment narrated instead.
  3. Narrated: when too little would be left, a record of what happened in reported speech, one line per step, labeled User or Agent (User asked…, Agent ran…, User decided…), with the protected content left out. Tool calls appear only as the action in an Agent step; routine reads and listings are left out. Each line ships as its own fact in the place of the step it reports: under its speaker, at that step's time, in its session. Every line is marked narrated, so readers know it paraphrases rather than quotes, and ask shows it as such (Dan [narrated]: User asked…). The first line leads with the record's headline (# Importer rows), so everyone who reads the space sees the moment by that title. The headline is part of the shipped text: the share filters and the share check read it like any other line.

A moment that matches rules aimed at different targets is nominated once per target, and each target gets the parts its rule covers. One model call labels every sentence of the span with the rules it belongs to (a sentence both audiences need, such as a shared cause, belongs to both; thanks and scheduling belong to neither and go to everyone) and with the never rules it breaks, including each target's own. Each target's copy is then built from those labels, fact by fact like a redaction: sentences that only concern another target become [omitted] (a fact that is all another target's ships as just [omitted]), and a kept sentence that breaks one of the target's never rules gets the word-level redaction above. A target whose copy keeps almost nothing, or whose redaction fails, gets a narrated record that leaves the other target's part out. If nothing needs leaving out for a target, it gets the moment as it would alone. A nomination remembers the other targets' rules, so when a later moment merges into it, the merged span is labeled again and the target still gets only its own parts.

In every form, paths leave your machine's details behind: a home directory ships as ~, and an agent's scratch or temp directory as <tmp>. So do links to your own agent sessions, routines and artifacts (claude.ai/code/session_…, claude.ai/code/routines/…, claude.ai/artifact/…): a Claude-Session: trailer on a commit message, or a line that is only such a link, is left out, and a link inside a sentence ships as [url]. Your own copy of the fact keeps them. A subagent's hand-back ships as its label and the report it carried, without the wrapping an agent harness puts around it. A fact you share by id ships as written.

A nomination is titled for what ships. The scan writes a headline from the span as it read it; when the shipped text says less (a redaction cut parts, or a raw span's tool output is left out), the headline is written again from the shipped text, so it never states a finding the note doesn't hold. A span that ships as the scan read it keeps the scan's headline, at no extra model call.

A nomination whose rule name is not one of your rules (a model sometimes answers with something else, such as another nomination's headline, or with nothing) is staged under no rule and with no target, never shared without review, whatever a project's mode says. Its note and a scan warning give the name the model answered; pick a target when you approve it. It is kept apart from nominations your rules aim: it never merges with one, and it is the first to go when an answer names more moments than the scan takes.

Nominations share nothing — they wait in shmem share for a decision. Only rules you explicitly set to mode: share share without review, and those are loud: a receipt in the scan output, a line in status, an entry in the log. A history replay (shmem share scan --since …) is the exception: it only nominates, so what a mode: share rule matches in older memory is staged for your review unless you start the replay with --auto-share.

Before a mode: share rule ships anything, a second model call checks what would ship against the target's never rules. If it finds a problem, the nomination is redrafted once, with the objection added to what the draft must leave out. A raw or redacted span is redacted (again), record by record; if that can't be done or is still flagged, or the nomination was narrated, it is redrafted as a narrated record. If the redraft is still flagged, or leaves nothing to share, or the check can't run, the nomination is held: it stays in shmem share as a draft, with a note saying what was flagged and, when the check thinks another rule fits better, a suggested target. Nothing is moved to another target on its own.

A target never rule titled <rule>-only (say team-only on a public target) means "anything that rule covers"; the drafter is given that rule's criteria, so the omission is concrete.

A nominated span starts with the request that set the work going. The evaluator includes your message in the span and judges it against never like everything else. If its pick still begins at the agent's first step, the nearest earlier message from you in the same session is added, unless another nomination or share already holds it. That message is first checked on its own against never, and left out if it breaks one, can't be checked, or is longer than a raw share holds (8,000 characters). One request starts at most one moment, so two pieces of work you asked for in one message stay separate nominations.

The scan and the share check read everything you and your agents wrote in a span, up to that 8,000-character limit, so nothing that ships goes unread. Tool output, which ships as its call line unless a rule keeps it, is read only in part. A raw or narrated draft isn't checked, since you review it. A redacted draft goes through the share check first: the redaction may have missed something it was told to hide, or put back a tool call's line it had dropped (a call line is kept so a reader can follow what was done). If the check flags it, the draft gets one redraft, and if that is flagged too it is held with a note saying why.

Deduplication is built in: a span you discarded never re-nominates (unless you forget the discard); overlapping nominations for the same target merge, and a merged nomination ships in the stricter of the two forms (raw, then redacted, then narrated), leaving out what either had to; already-shared content is skipped.

The file

# share-rules.yml

settings:
  status-window: 7d              # the window status counts recent shares in
  default-target: team-memories  # target when no --to / target: is given

rules:                           # global rules, evaluated on every scan
  - title: milestones            # unique name; nominations cite it
    criteria: something was merged, deployed, released, or a milestone completed
    mode: draft                  # nominate for review (the default)
  - title: gotchas
    criteria: bugs or gotchas that cost real time to figure out
    mode: draft
  - title: benchmarks
    criteria: benchmark results and the decisions they drove
    mode: share                  # share WITHOUT review — loudly
    target: perf-notes           # where this rule shares to
  - title: perf-findings
    criteria: performance regressions and their root causes
    mode: draft
    target: perf-notes           # a DRAFT rule's target pre-aims its
                                 # nominations: approving one shares
                                 # there, no --to needed

never:                           # GLOBAL: what must never be shared
  - title: credentials
    criteria: secrets, tokens, API keys, passwords, or connection strings
  - title: personal
    criteria: personal details about individuals, or personnel/HR matters

projects:                        # per-project configuration
  - project: shmem-perf
    mode: share                  # auto-share nominations from this project
    target: team-memories
    rules:                       # evaluated only against this project's facts
      - title: flamegraphs
        criteria: profiling results worth keeping
        mode: share
    never:                       # TARGET-scoped: applies to everything
      - title: off-topic         # shared INTO this project, from any
        criteria: anything unrelated to performance work   # source,
                                 # merged with the global never rules

Field reference

settings

Key Meaning Default
status-window The window shmem share counts recent shares in, and the --since its share log hint uses (48h, 7d, 2w) 7d
default-target Target when neither --to nor a rule/project target: applies team-memories

rules (and projects[].rules)

Key Meaning
title Unique name. Nominations and log entries cite it.
criteria Natural language: what the rule matches. The evaluator reads this verbatim.
mode draft (default): nominate for review. share: share immediately — loudly, revocably (a history replay stages its matches for review instead, unless started with --auto-share). A project's rules route only that project's facts: a moment of facts in no project is routed by global rules alone, and a moment whose facts come from more than one project (counting facts in no project) is always staged as a draft for you to aim. Write mode: draft explicitly; an explicit draft pins review even when a project-level mode: share would otherwise apply.
target Where the rule's matches go. On a share rule: where it shares. On a draft rule: pre-aims the nomination — approving it shares there without --to.
tool-output What a nomination keeps of each tool call. collapse (default): the call line alone ([Bash] go test ./...), with [output omitted] where its output was. keep: the output too, for a rule whose shares are about what a tool printed, such as bug reports quoting a command's exact output. Facts you share by id always ship as written.

never (global) and projects[].never

Key Meaning
title A name for the exclusion.
criteria Natural language: content that must not be shared.

Scoping semantics — this distinction matters:

  • Global never: is content-sensitivity policy. It applies to every scan, every nomination, every distillation, regardless of target.
  • projects[].never: protects a target: it applies to everything shared INTO that project, no matter which project the facts came from. Use it to keep a focused space on-topic ("nothing unrelated to performance") without touching global policy.

Never rules act at two points: the evaluator skips matching moments (or marks them to be redacted or narrated so the protected content is left out), and the merged never-criteria for the destination ride into every redaction and narration prompt as strict omissions. They are a belt, not suspenders — the deterministic .shmemignore filters (redact / substitute / drop) still run at the share boundary, fail-closed.

A manual single-fact share bypasses never-rule screening by design: naming a fact id is a deliberate act, and the system doesn't second-guess it. The .shmemignore filters still apply.

projects

Key Meaning
project The project name this entry configures.
mode share: nominations arising from this project's facts auto-share.
target Where those auto-shares go (default: settings.default-target).
rules Extra rules evaluated only against this project's facts.
never Target-scoped exclusions (see above).

Resolution order

For each nomination, the effective mode and target resolve as:

  1. The matched rule's own mode/target — an explicit mode: draft pins review even under a project mode: share; an explicit mode: share shares to the rule's target (or the default target).
  2. The source project's mode/target — an unmarked rule matching facts from a mode: share project auto-shares to that project's target.
  3. Draft to nowhere — nominate, let the user aim at share time.

An explicit --to on the share command beats everything.

Target validation

A foreign target (owner/name) is checked against the remote's shared-project listing at every surface that touches it before share time: the scan drops an unknown aim (the nomination stages unaimed for review, with the reason as its note — a share-mode rule falls back to draft rather than auto-sharing into a wall), shmem share rules warns after an --edit (and after a plain show), and shmem share marks a pending nomination whose aim no longer resolves. Wherever the listing offers an unambiguous near-match — the common case being a bare username where the server knows the full account identity — the message suggests it: did you mean "dan@example.com/shmem-team"?. The client never rewrites a target on its own; the server stays the authority, so when no remote is reachable the target is treated as unverifiable, not invalid.

A target whose owner is your own account is not foreign: you@example.com/team-memories, or you/team-memories by the part before the @, is the same target as the bare team-memories, in rules, in --to, and when unsharing. It is read as the bare name everywhere, so one moment is never nominated or shared twice under two spellings.

Note that a nomination keeps the target aimed at scan time: fixing a rule does not re-aim already-staged nominations — share those with an explicit --to.

Default rules

Your rules are the whole standard: shmem adds none of its own. The first scan writes a starter file whose milestones, decisions, dead-ends, and gotchas rules are explicit drafts you can edit or delete. A file with no rules nominates nothing.

A project's mode: share applies to the unmarked rules that match its facts, so a sharing project needs at least one rule without a mode (global, or in the project's own rules:).

The defaults framework, if you're writing rules for someone: prefer completion-anchored criteria (things that finished), high value to a teammate, low sensitivity, and precision over recall — an over-eager scanner trains people to bulk-discard, which is worse than missing a nomination.

Verifying a setup

$ shmem share rules          # print the active file (--edit to open it)
$ shmem share scan            # run the pipeline over what arrived since the last scan
$ shmem share scan --since all  # replay older memory under the current rules: nominates only
$ shmem share scan --since all --auto-share   # ...and let mode: share rules share what it finds
$ shmem share forget --all    # after changing rules: clear what awaits review, then replay
$ shmem share                # nominations waiting; footer shows
                             # "Rules: N draft · N share · N never."