-
Notifications
You must be signed in to change notification settings - Fork 1
Feature: Hygiene
Unless noted, client.* names below are the opencode v1 mapping; the v2 equivalents and degrades are in opencode-plugin.md.
Store maintenance signals surfaced at session start. The plugin never deletes memories itself — it surfaces problems and lets the agent tend the store.
- Three signals: duplicate candidates, stale entries, orphaned branch memories
- Runs at session start on all three hosts
- Only non-zero signals are reported (healthy stores stay silent)
- Standalone
thatch hygieneCLI command for manual inspection
-
Duplicate candidates —
db.findDuplicates(repo): near-duplicate memory pairs via cosine >= 0.85 pending review. These are the same pairs thatfind_duplicatessurfaces, but the hygiene report is a count-only summary, not the full pair list. -
Stale entries —
db.staleEntryCount(repo, cutoff): memories neither updated nor recalled in 90+ days (STALE_DAYS = 90). Usesrecall_countandlast_recalled_atcolumns. Archived memories are excluded (WHERE archived = 0). -
Orphaned branch memories —
db.branchesInStore(repo)cross-references againstgit.listBranches(worktree). Memories scoped to branches that no longer exist. Skipped when the worktree is not a git repo (listBranchesreturns[]) to avoid false positives — without a git repo, every branch-scoped memory would look orphaned.
-
opencode:
session.createdevent for top-level sessions (noparentID). The hygiene report is appended to the session-start reminder sent viaclient.session.prompt. -
Claude Code:
SessionStarthook →thatch reminder(runshygieneReport, appends to reminder text, prints to stdout). -
Cursor:
sessionStarthook →thatch reminder --json(same, wrapped asadditional_contextJSON). -
Standalone:
thatch hygieneCLI command (prints report or "Store is healthy." to stdout).
Only non-zero signals are reported. A healthy store produces no output (silent). The report is appended to the session-start reminder with instructions for the agent to tend the store when convenient.
hygieneReport(db, repo, worktree) in src/hygiene.ts is shared by:
- The opencode plugin's session-start hook (
src/runtime.ts) - The CLI's
thatch reminderandthatch hygienesubcommands (bin/thatch)
-
Deduplication: hygiene reports the count of pending dedup
pairs; the agent uses
find_duplicatesto see the actual pairs. -
Memory store: staleness uses
recall_countandlast_recalled_at; orphan check uses thebranchcolumn. - Session lifecycle: hygiene runs at
session.createdfor top-level sessions. - Nudge pipeline: hygiene is part of the session-start reminder, not the per-message nudge pipeline.
-
src/hygiene.ts—hygieneReportfunction -
src/db.ts—findDuplicates,staleEntryCount,branchesInStore -
src/git.ts—listBranches -
bin/thatch—hygieneandremindersubcommands
- The plugin never deletes memories. It surfaces problems; the agent tends the store.
- Only non-zero signals are reported.
- Orphan check is skipped outside a git repo.
- Archived memories are excluded from staleness and duplicate checks.
User
- Guide: Behavior Engine
- Guide: Cli
- Guide: Code Review
- Guide: Commands
- Guide: Cross Session Chat
- Guide: Deduplication
- Guide: Default Behaviors
- Guide: Extraction
- Guide: Hygiene
- Guide: Memory
- Guide: Notifications
- Guide: Prediction Engine
- Guide: Overview
- Guide: Setup
- Guide: Skills
- Guide: Watchers
Developer
Dev Feature Guides
- Feature: Behavior Engine
- Feature: Cicd
- Feature: Cli
- Feature: Commands
- Feature: Compaction Recovery
- Feature: Cross Session Chat
- Feature: Database
- Feature: Deduplication
- Feature: Extraction
- Feature: Hygiene
- Feature: Memory Store
- Feature: Multi Host
- Feature: Notifications
- Feature: Nudge Pipeline
- Feature: Opencode Plugin
- Feature: Prediction Engine
- Feature: Qa System
- Feature: Overview
- Feature: Repo Identity
- Feature: Session Lifecycle
- Feature: Setup
- Feature: Sideband
- Feature: Watchers