Skip to content

Overview

contox_hygiene runs the Memory Hygiene Agent to analyze and propose cleanup actions for memory items. The agent identifies issues like duplicate entries, outdated information, poor titles, missing tags, exposed secrets, and quality problems.

The tool uses a two-phase workflow:

  1. Analyze — Call without apply to get a HygienePlan with proposed actions
  2. Apply — Call with apply and the plan to execute selected actions

The agent never auto-applies changes. Every action must be explicitly selected for application.

Parameters

NameTypeRequiredDefaultDescription
modeenumNo"quick"Analysis mode: "quick" (20 most recent items) or "weekly" (all items updated in the last 7 days)
schemaKeyPrefixstringNoFilter items by schemaKey prefix (e.g., "root/bugs")
applystring[]NoAction IDs to apply from a previous plan. Omit to analyze only
planstringNoJSON-stringified HygienePlan from a previous analyze call. Required when applying
dryRunbooleanNoIf true, show what would be applied without executing

Action types

The hygiene agent can propose the following types of actions:

ActionDescription
RenameImprove a memory item's title for clarity
RetagAdd, remove, or update tags on a memory item
MergeCombine duplicate or overlapping memory items
DeprecateMark superseded or outdated items as deprecated
RedactRemove sensitive information (secrets, keys, passwords)
Flag qualityFlag items with quality issues for manual review

Return value

Analyze mode (no apply)

Returns a formatted report including:

FieldDescription
totalMemoriesNumber of items analyzed
actionsCountNumber of proposed actions
promptTokensTokens used for analysis prompt
completionTokensTokens used for analysis response
summaryHuman-readable summary of findings
warningsAny warnings encountered during analysis
actionsDetailed list of proposed actions grouped by type

Each action includes:

FieldTypeDescription
actionIdstringUnique action identifier
typestringAction type (rename, retag, merge, deprecate, redact, flag)
reasonstringWhy this action is proposed
confidencenumberConfidence score (0-1)
requiresHumanApprovalbooleanWhether human review is recommended before applying
targetMemoryIdsstring[]IDs of the memory items affected

Apply mode (with apply)

Returns:

FieldTypeDescription
appliedActionIdsstring[]IDs of successfully applied actions
skippedActionIdsstring[]IDs of skipped actions
errorsarrayErrors encountered during application

Usage examples

Phase 1: Analyze memory

User: Check my memory for cleanup opportunities

Claude calls: contox_hygiene({ mode: "quick" })

Response:
Memory Hygiene Report (quick mode)
────────────────────────────────────
Items analyzed: 20
Actions proposed: 4
Tokens: 1200+350

3 items could benefit from improved titles. 1 potential duplicate found.

rename (2)
  - Title "stuff" is too vague, should be "JWT Token Rotation Implementation" (confidence: 0.92)
    id: action_abc | targets: mem_123
  - Title "fix" should be "Fix Session Refresh Race Condition" (confidence: 0.88)
    id: action_def | targets: mem_456

merge (1)
  - Two entries about auth middleware can be combined (confidence: 0.85) [NEEDS APPROVAL]
    id: action_ghi | targets: mem_789, mem_012

deprecate (1)
  - "Old migration notes" superseded by updated schema docs (confidence: 0.90)
    id: action_jkl | targets: mem_345

To apply actions, call contox_hygiene with:
  apply: [actionId1, actionId2, ...]
  plan: '<full JSON plan>'

Phase 2: Apply selected actions

User: Apply the renames and the deprecation, but skip the merge

Claude calls: contox_hygiene({
  apply: ["action_abc", "action_def", "action_jkl"],
  plan: "<JSON from previous response>"
})

Response:
Hygiene Apply Result:
- Applied: 3
- Skipped: 0
- Errors: 0

Dry run before applying

Claude calls: contox_hygiene({
  apply: ["action_abc"],
  plan: "<JSON>",
  dryRun: true
})

Response:
Hygiene Apply (DRY RUN) Result:
- Applied: 1
- Skipped: 0
- Errors: 0

Filtering by area

Claude calls: contox_hygiene({
  mode: "weekly",
  schemaKeyPrefix: "root/bugs"
})

Notes

  • The plan parameter is required when using apply. It must be the full JSON-stringified HygienePlan from the analyze phase.
  • Actions with requiresHumanApproval: true are flagged for manual review. They can still be applied programmatically, but the flag indicates the AI recommends human oversight.
  • The quick mode analyzes only the 20 most recent items, making it fast and low-cost. The weekly mode is more thorough but processes more data.
  • Use schemaKeyPrefix to focus the analysis on a specific area of the brain (e.g., only bugs, only implementation log).
  • The dryRun option in apply mode shows what would be changed without actually modifying any data.