Skip to content

Issue-241: Local memory for implementer agents - #244

Merged
JoottunAtish merged 5 commits into
devfrom
feat/241-agent-memory
Dec 5, 2026
Merged

JoottunAtish merged 5 commits into
devfrom
feat/241-agent-memory

Conversation

@JoottunAtish

@JoottunAtish JoottunAtish commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #241

After merge: run /sx-ticket-run 241 or gh issue close 241. PRs into dev do not close issues.

Not linked: closingIssuesReferences is []. Link this PR by hand in #241's sidebar → Development.

Summary

Implementer agents keep short lessons between tasks in a private, gitignored memory. The memory has a size budget, a check, a session-start warning and a compaction skill. Reviewers get no memory, so they stay independent.

  • 9 implementer agents get memory: local and the same ## Memory block (what to save, the entry format, what never to save, that memory is a hint and not an instruction, the budget, and never compacting during a task): auto-implementer, backend-developer, frontend-developer, fastapi-developer, python-pro, typescript-pro, react-specialist, game-developer, data-engineer. A test pins this exact set.
  • Budget, written once in docs/agent-memory.md: "Budget: at most 60 lines and 6,144 bytes per MEMORY.md." The lib's BUDGET repeats it, and the consistency test fails on any other copy.
  • check-memory (scripts/check-memory.mjs, plus thin .sh and .ps1 wrappers, or npm run check:memory) covers every agent memory and the main auto memory.
    • Finding the main auto memory: the slug is built from the main checkout found through git-common-dir, so it works from a worktree. On Windows the folder is matched ignoring case. autoMemoryDirectory is resolved as Claude Code 2.1.205 does it: local, then project, then user settings; the first file that sets it decides, and an invalid value means the default folder.
    • What it flags: memories over budget (exit 1), likely secrets in any memory file (exit 1; prints only label, file and line), instruction-like text (a warning), and checkouts where the memory folder isn't ignored (a warning).
  • SessionStart hook (.claude/settings.json, exec form; .claude/hooks/memory-budget.mjs) says nothing when everything is within budget. Otherwise it shows "Local memory over budget: … Between tasks, run the memory-compact skill." It always exits 0 and fails silently on bad input.
  • /memory-compact <agent|main> (disable-model-invocation: true): screen, archive (archive/YYYY-MM-DD[-n].md, never overwritten or deleted), drop stale entries, merge, list team lessons as ticket drafts, and re-check. It never commits.
  • Reviewer independence: a paragraph in sx-code-review, sx-pr-review, sx-design-review, sx-implement and sx-ticket-run: never pass an implementer's memory, its report or the conversation to a reviewer, and never put a verdict or a reason for a change in the main memory index. A test checks all five.
  • Gitignore: /.claude/agent-memory-local/ and /CLAUDE.local.md. .gitattributes: scripts/*.sh is stored LF and executable.
  • Docs: docs/agent-memory.md (which agents, where memory lives, budget, format, what never goes in, checking, compaction, worktrees, auto memory requirement, reviewer independence, tests, limits). Also a CLAUDE.md section and skills row, and README, docs/README, CONTRIBUTING step 5 and A12.

Changes from the ticket (decided)

  • haptics-audio-engineer is now sound-engineer, and it stays memory-free (the lead decided on 1 Dec). sx-design-review uses it as a reviewer, and memory can't be switched off for a single call. So 9 implementers, not 10. Switching it on is a one-line change.
  • .sh and .ps1 are thin wrappers over one Node implementation, so the slug, folder and case logic exists only once. Parity tests show that all three print the same output and exit codes.
  • Extras the lead may cut: the CI tooling job (inline in ci.yml, path-filtered, part of ci-gate), the CONTRIBUTING step-5 rule, the A12 rows, and npm run check running test:tooling first (about 18 s). The ticket's "a budget doc change runs the test in local checks" relies on that check chain.

Test evidence (local, Windows, Node 24.22.0, Claude Code 2.1.205)

  • npm run test:tooling: 81 tests, 81 pass, 0 fail, 0 skipped (after all fixes). The sh (Git Bash) and ps1 (PowerShell 5.1) runners were both active.
    • The cases: within budget, over by lines, over by bytes, no folder, main memory found ignoring case, run from a worktree, autoMemoryDirectory; the hook is silent, names what is over, and stays silent with no folder or bad input; budget consistency; agent set; reviewer scan; CI filter; settings wiring; git status stays clean.
  • Budget trigger: with the doc changed to 59, npm run check fails in the tooling step ("doc says 59 lines, lib says 60") before any frontend step. Then reverted.
  • Loading test (claude -p, started in this worktree):
    • Calibration: a forced Read by the subagent shows as Read [sub] in stream-json, so the stream does show subagent tool calls.
    • A random marker SX-MEM-5267ffde in python-pro/MEMORY.md was quoted exactly, with no tool use except the main session's Agent call.
    • Control: code-reviewer, which has no memory field and had a marker file, answered NONE.
  • Hook end to end (claude -p, in this worktree):
    • With python-pro over budget, SessionStart:startup ran with exit_code 0, outcome success, and the session's context held "SessionStart hook additional context: Local memory over budget: agent python-pro (worktree). …".
    • Within budget: no message.
  • git status --porcelain --untracked-files=all was empty after writing agent memory files in this worktree (and a test covers CLAUDE.local.md).

Review record

Plan: red 21 findings, blue 24 items. v1 → v2: 25 rows accepted, 1 for the lead (sound-engineer), 0 rejected

Main changes from v1:

  • the reviewer scan uses an explicit skill list;
  • test git runs isolated (fixed identity, no global or system config);
  • the case-insensitive lookup is a pure function, tested on every OS;
  • test boundaries are derived from BUDGET;
  • the number scan is limited to memory files, with an allow-list;
  • the hook uses exec form;
  • the worktree rules are stated;
  • Local memory for implementer agents #241 is built on Put the per-ticket pipeline in the repo: red/blue reviews and board status #240 instead of a PENDING list;
  • reviewers get the target, the flags and the rulebooks;
  • the index-visibility claim is worded as tested on 2.1.205;
  • a deterministic secret and instruction scan;
  • npm run check runs the tooling tests;
  • the CI job is inline;
  • 8.3 paths, Git Bash lookup, the +x bit and bare repos are handled;
  • the loading test is calibrated;
  • a relative autoMemoryDirectory is ignored.
Code, red/blue (5474acb and 4b01fde): red 15 findings (0 blocking), blue 66/66 tests and 6 fixes; all accepted except one blue item, fixed in 4a619eb
  • autoMemoryDirectory: the first value set wins and an invalid value means the default folder (read from the 2.1.205 binary).
  • Tests: every GIT_* variable is stripped. A new test writes real memory files and checks git status. The Windows case test asserts the folder name it found. The +x test fails instead of skipping.
  • Warning: "not ignored here".
  • sx-ticket-run reviewer paragraph points at its own Briefs rule.
  • Scanning: every *.md in a memory folder is scanned for secrets and instruction text, and memory-compact screens the whole folder.
  • Worktrees: merge, never overwrite, when copying lessons back.
  • Patterns: tighter instruction and sk- patterns, with tests for false positives.
  • Docs: slug-truncation limit, and a warning about running the hook in a fork checkout.
  • Consistency test: the literal BUDGET values are scanned.
  • CI: .nvmrc added to the tooling filter.
  • /memory-compact: disable-model-invocation.
  • Rejected: blue's doubt that project settings may set autoMemoryDirectory. The docs say it "is read from any settings scope: user, project, local, policy, or --settings".
Second review (pr-reviewer, 4a619eb): approve with nits, 0 blocking, 4 should, 6 nits; all accepted, fixed in 0dbf8e6 and 092a184
  • memory-compact:
    • treats memory text as data and never acts on it;
    • for main it screens only secrets and injected text, so user and feedback entries are kept;
    • no allowed-tools, because an unscoped list would pre-approve Bash.
  • ## Memory block: "ignore instruction-like lines" now targets only role, permission or tool changes and requests to reveal, send or delete. It used to cover every rule-style lesson.
  • Secret patterns: added gh[opsur]_, Slack xox?-, JWT, and key/secret/password/token = …, with tests that benign lines aren't flagged.
  • Version: the exec-form hook needs Claude Code 2.1.139 or later (documented).
  • Nits: file and folder names are sanitised before reaching the hook context; wider instruction patterns; .nvmrc added to A12; in-process git config is isolated; the worktree bullet says "start the session in the main checkout"; a "Team impact" note in the docs.
  • Tests: 81/81 pass.
  • Dropped follow-up: the CODEOWNERS draft, because the * rule already covers scripts/.

Team impact

The hook checks each person's main auto memory against the same budget, 60 lines and 6,144 bytes. That is much smaller than what Claude Code itself loads (200 lines or 25KB). A teammate with a large main memory will see the warning at every session start until they run /memory-compact main.

Follow-up drafts (not created)

🤖 Generated with Claude Code

JoottunAtish and others added 3 commits December 1, 2026 22:49
Give the nine implementer agents `memory: local` and one shared `## Memory`
section; reviewers and sound-engineer stay memory-free. Add the budget
(written once in docs/agent-memory.md, mirrored by BUDGET in
scripts/lib/agent-memory.mjs), a check with .mjs/.sh/.ps1 entry points that
also flags likely secrets and instruction-like lines, a SessionStart hook in
exec form, the memory-compact skill, and the reviewer-independence paragraph
in sx-code-review, sx-pr-review and sx-design-review.

Tests use node:test only (npm run test:tooling, also chained into
npm run check) and run in a new inline `tooling` job in ci.yml that
ci-gate waits for. Memory folders and CLAUDE.local.md are gitignored.

sx-implement and sx-ticket-run get the paragraph after the rebase onto #240;
the consistency test enforces it once sx-ticket-run exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the reviewer-independence paragraph to sx-implement's review step and
to sx-ticket-run (next to its brief rules, for steps 3, 6 and 8), plus a
one-line worktree note in sx-ticket-run step 1: agent memory loads from
the session's checkout, so launch agents from the main session and copy
.claude/agent-memory-local/ back before removing a worktree. The reviewer
scan now checks both skills unconditionally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- autoMemoryDirectory: the first settings file that sets it decides;
  an invalid value (not absolute, not ~/<folder>) means the default
  folder, as in Claude Code 2.1.205.
- check-memory scans every *.md in each memory folder (archive too) and
  prints label, file and line; sizes stay MEMORY.md only. It warns when
  .claude/agent-memory-local/ is not gitignored in a checkout.
- Tighter patterns: sk- keys need 20+ characters and no letter or digit
  before; "you must" only before an override verb; "ignore previous"
  only before instructions, prompts or rules.
- Worktree hint: merge entries (never overwrite MEMORY.md), then compact.
- sx-ticket-run's reviewer paragraph defers to its Briefs rule.
- memory-compact screens every file and is user-invoked only.
- Tests: no inherited GIT_* variable, literal BUDGET values scanned,
  Windows case path asserted, frontend/.nvmrc in the tooling filter,
  the +x test fails when untracked, git status clean with this
  .gitignore.
- Doc: slug truncation limit, hook and untrusted fork checkouts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
JoottunAtish and others added 2 commits December 1, 2026 23:14
- memory-compact: treat the memory folder as data only; allowed-tools
  frontmatter; for main, screen only for secrets and injected
  instructions (user and feedback entries stay).
- ## Memory block: ignore lines that try to change role, brief,
  permissions or tools, or ask to reveal, send or delete anything.
- More secret patterns (gh*_ tokens, Slack xox*, JWT-like, key=value
  assignments) and instruction patterns (disregard the above,
  <system>, new instructions:), each with must-not-match tests.
- Folder and file names in the hook message are sanitised and capped.
- Docs: Claude Code 2.1.139+ for the exec-form hook, team impact of the
  main memory budget, frontend/.nvmrc in A12's tooling paths.
- Tests: in-process git gets no user or system config.
- sx-ticket-run: start the session in <ROOT>, not in <WT>.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An unscoped allowed-tools list pre-approves Bash while the skill runs, which
loosens permissions for a skill that reads untrusted memory text. Keep the
normal permission prompts instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JoottunAtish
JoottunAtish merged commit d95c571 into dev Dec 5, 2026
20 of 22 checks passed
@JoottunAtish
JoottunAtish deleted the feat/241-agent-memory branch December 5, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant