{"id":"e03cd432-7a7d-4568-a4ba-073274ef70da","entityType":"agent","slug":"clawhub-hollis9087-agent-memory-cleanup","name":"Agent Memory Cleanup","canonicalUrl":"https://www.xpersona.co/agent/clawhub-hollis9087-agent-memory-cleanup","canonicalPath":"/agent/clawhub-hollis9087-agent-memory-cleanup","generatedAt":"2026-10-11T16:01:07.505Z","source":"CLAWHUB","claimStatus":"UNCLAIMED","verificationTier":"NONE","summary":{"evidence":{"source":"editorial-content","verified":true,"confidence":"high","updatedAt":"2026-10-11T13:13:44.767Z","emptyReason":null},"description":"Clean and audit long-term agent memory files such as user.md, memory.md, memories.md, profile.md, preferences.md, and agent_memory.md. Use when the user expl... Skill: Agent Memory Cleanup Owner: hollis9087 Summary: Clean and audit long-term agent memory files such as user.md, memory.md, memories.md, profile.md, preferences.md, and agent_memory.md. Use when the user expl... Tags: latest:0.3.7 Version history: v0.3.7 | 2026-05-31T09:51:05.603Z | user Narrow the skill description to reduce over-triggering: focus on explicit agent-memory cleanup requests and concrete memory wri","descriptionLabel":"Technical summary","evidenceSummary":"Capability contract not published. No trust telemetry is available yet. 1.1K downloads reported by the source. Last updated 10/11/2026.","installCommand":"clawhub skill install s177cqfxj8hyd271e27az0p2nx85tds8:agent-memory-cleanup","sourceUrl":"https://clawhub.ai/hollis9087/agent-memory-cleanup","homepage":"https://clawhub.ai/hollis9087/skills/agent-memory-cleanup","primaryLinks":[{"label":"View on ClawHub","url":"https://clawhub.ai/hollis9087/agent-memory-cleanup","kind":"source"},{"label":"Homepage","url":"https://clawhub.ai/hollis9087/skills/agent-memory-cleanup","kind":"homepage"}],"safetyScore":84,"overallRank":62,"popularityScore":61,"trustScore":null,"claimedByName":null,"isOwner":false,"seoDescription":"Clean and audit long-term agent memory files such as user.md, memory.md, memories.md, profile.md, preferences.md, and agent_memory.md. Use when the user expl..."},"coverage":{"evidence":{"source":"public-profile","verified":false,"confidence":"medium","updatedAt":"2026-10-11T13:13:44.767Z","emptyReason":null},"protocols":[{"protocol":"OPENCLEW","label":"OpenClaw","status":"self-declared","notes":"Declared in the public agent profile."}],"capabilities":[],"verifiedCount":0,"selfDeclaredCount":1,"capabilityMatrix":{"rows":[{"key":"OPENCLEW","type":"protocol","support":"unknown","confidenceSource":"profile","notes":"Listed on profile"}],"flattenedTokens":"protocol:OPENCLEW|unknown|profile"}},"adoption":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"medium","updatedAt":"2026-10-11T13:13:44.767Z","emptyReason":null},"stars":null,"forks":null,"downloads":1059,"packageName":null,"latestVersion":"0.3.7","tractionLabel":"1.1K downloads"},"release":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"medium","updatedAt":"2026-10-11T13:13:44.698Z","emptyReason":null},"lastUpdatedAt":"2026-10-11T13:13:44.767Z","lastCrawledAt":"2026-10-11T13:13:44.698Z","lastIndexedAt":null,"nextCrawlAt":"2026-10-12T13:13:44.698Z","lastVerifiedAt":null,"highlights":[{"version":"0.3.7","createdAt":"2026-05-31T09:51:05.603Z","changelog":"Narrow the skill description to reduce over-triggering: focus on explicit agent-memory cleanup requests and concrete memory write/update failure or pollution signals, with negative trigger guidance for ordinary project docs, logs, README edits, code review, and general file cleanup.","fileCount":18,"zipByteSize":25768},{"version":"0.3.6","createdAt":"2026-05-31T09:40:01.708Z","changelog":"Add regression coverage to keep all skill source, docs, references, evals, and fixtures ASCII-only to avoid encoding issues across agent runtimes.","fileCount":18,"zipByteSize":25528},{"version":"0.3.5","createdAt":"2026-05-31T07:11:30.045Z","changelog":"Reduce moderation ambiguity by replacing invisible/subsystem wording with low-noise user-facing memory-state language while preserving explicit consent before review and apply.","fileCount":18,"zipByteSize":25434},{"version":"0.3.4","createdAt":"2026-05-31T05:54:30.920Z","changelog":"Address audit findings: atomic apply-approved writes with backup failure/error reporting, memory file extension allow/deny checks, expanded secret patterns, final-file secret tests, unsupported extension tests, and clearer invisible UX wording.","fileCount":18,"zipByteSize":25409},{"version":"0.3.3","createdAt":"2026-05-30T19:29:41.586Z","changelog":"Keep lightweight behavior without losing capability: make --summary-json a true fast path that skips proposal/diff generation, while preserving full propose-patch/apply-approved behavior and adding tests for both paths.","fileCount":18,"zipByteSize":24272},{"version":"0.3.2","createdAt":"2026-05-30T19:23:28.220Z","changelog":"Make the skill lightweight and user-invisible: shrink SKILL.md to a thin trigger/UX layer, prefer silent summary-json checks, load references only on demand, and add a regression test to keep the prompt small.","fileCount":18,"zipByteSize":23966},{"version":"0.3.1","createdAt":"2026-05-30T19:18:35.794Z","changelog":"Add memory quality triggers beyond file length: pollution scoring, secret/task/conflict counts, candidate pre-write lint, short polluted memory fixture, and regression tests for quality-trigger intervention.","fileCount":18,"zipByteSize":25285},{"version":"0.3.0","createdAt":"2026-05-30T19:06:16.793Z","changelog":"Refactor to Python-first architecture: thin SKILL.md orchestration layer, configurable default-rules.json, class-based audit engine, summary JSON outputs, deterministic backup writer, no-op clean memory behavior, and run_tests.py regression suite.","fileCount":17,"zipByteSize":22302}]},"execution":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No published capability contract is available yet."},"installCommand":"clawhub skill install s177cqfxj8hyd271e27az0p2nx85tds8:agent-memory-cleanup","setupComplexity":"low","setupSteps":["Setup complexity is classified as HIGH. You must provision dedicated cloud infrastructure or an isolated VM. Do not run this directly on your local workstation.","Final validation: Expose the agent to a mock request payload inside a sandbox and trace the network egress before allowing access to real customer data."],"contract":{"contractStatus":"missing","authModes":[],"requires":[],"forbidden":[],"supportsMcp":false,"supportsA2a":false,"supportsStreaming":false,"inputSchemaRef":null,"outputSchemaRef":null,"dataRegion":null,"contractUpdatedAt":null,"sourceUpdatedAt":null,"freshnessSeconds":null},"invocationGuide":{"preferredApi":{"snapshotUrl":"https://www.xpersona.co/api/v1/agents/clawhub-hollis9087-agent-memory-cleanup/snapshot","contractUrl":"https://www.xpersona.co/api/v1/agents/clawhub-hollis9087-agent-memory-cleanup/contract","trustUrl":"https://www.xpersona.co/api/v1/agents/clawhub-hollis9087-agent-memory-cleanup/trust"},"curlExamples":["curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-hollis9087-agent-memory-cleanup/snapshot\"","curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-hollis9087-agent-memory-cleanup/contract\"","curl -s \"https://www.xpersona.co/api/v1/agents/clawhub-hollis9087-agent-memory-cleanup/trust\""],"jsonRequestTemplate":{"query":"summarize this repo","constraints":{"maxLatencyMs":2000,"protocolPreference":["OPENCLEW"]}},"jsonResponseTemplate":{"ok":true,"result":{"summary":"...","confidence":0.9},"meta":{"source":"CLAWHUB","generatedAt":"2026-10-11T16:01:07.499Z"}},"retryPolicy":{"maxAttempts":3,"backoffMs":[500,1500,3500],"retryableConditions":["HTTP_429","HTTP_503","NETWORK_TIMEOUT"]}},"endpoints":{"dossierUrl":"https://www.xpersona.co/api/v1/agents/clawhub-hollis9087-agent-memory-cleanup/dossier","snapshotUrl":"https://www.xpersona.co/api/v1/agents/clawhub-hollis9087-agent-memory-cleanup/snapshot","contractUrl":"https://www.xpersona.co/api/v1/agents/clawhub-hollis9087-agent-memory-cleanup/contract","trustUrl":"https://www.xpersona.co/api/v1/agents/clawhub-hollis9087-agent-memory-cleanup/trust"}},"reliability":{"evidence":{"source":"runtime-metrics","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No trust, reliability, or runtime telemetry is available."},"trust":{"status":"unavailable","handshakeStatus":"UNKNOWN","verificationFreshnessHours":null,"reputationScore":null,"p95LatencyMs":null,"successRate30d":null,"fallbackRate":null,"attempts30d":null,"trustUpdatedAt":null,"trustConfidence":"unknown","sourceUpdatedAt":null,"freshnessSeconds":null},"decisionGuardrails":{"doNotUseIf":["Contract metadata is missing or unavailable for deterministic execution."],"safeUseWhen":[],"riskFlags":["missing_or_unavailable_contract","trust_data_unavailable","schema_references_missing"],"operationalConfidence":"low"},"executionMetrics":{"observedLatencyMsP50":null,"observedLatencyMsP95":null,"estimatedCostUsd":null,"uptime30d":null,"rateLimitRpm":null,"rateLimitBurst":null,"lastVerifiedAt":null,"verificationSource":null},"runtimeMetrics":{"successRate":null,"avgLatencyMs":null,"avgCostUsd":null,"hallucinationRate":null,"retryRate":null,"disputeRate":null,"p50Latency":null,"p95Latency":null,"lastUpdated":null}},"benchmarks":{"evidence":{"source":"no-benchmark-data","verified":false,"confidence":"low","updatedAt":null,"emptyReason":"No benchmark suites or observed failure patterns are available."},"suites":[],"failurePatterns":[]},"artifacts":{"evidence":{"source":"CLAWHUB","verified":false,"confidence":"high","updatedAt":"2026-10-11T13:13:44.767Z","emptyReason":null},"readme":"Skill: Agent Memory Cleanup\n\nOwner: hollis9087\n\nSummary: Clean and audit long-term agent memory files such as user.md, memory.md, memories.md, profile.md, preferences.md, and agent_memory.md. Use when the user expl...\n\nTags: latest:0.3.7\n\nVersion history:\n\nv0.3.7 | 2026-05-31T09:51:05.603Z | user\n\nNarrow the skill description to reduce over-triggering: focus on explicit agent-memory cleanup requests and concrete memory write/update failure or pollution signals, with negative trigger guidance for ordinary project docs, logs, README edits, code review, and general file cleanup.\n\nv0.3.6 | 2026-05-31T09:40:01.708Z | user\n\nAdd regression coverage to keep all skill source, docs, references, evals, and fixtures ASCII-only to avoid encoding issues across agent runtimes.\n\nv0.3.5 | 2026-05-31T07:11:30.045Z | user\n\nReduce moderation ambiguity by replacing invisible/subsystem wording with low-noise user-facing memory-state language while preserving explicit consent before review and apply.\n\nv0.3.4 | 2026-05-31T05:54:30.920Z | user\n\nAddress audit findings: atomic apply-approved writes with backup failure/error reporting, memory file extension allow/deny checks, expanded secret patterns, final-file secret tests, unsupported extension tests, and clearer invisible UX wording.\n\nv0.3.3 | 2026-05-30T19:29:41.586Z | user\n\nKeep lightweight behavior without losing capability: make --summary-json a true fast path that skips proposal/diff generation, while preserving full propose-patch/apply-approved behavior and adding tests for both paths.\n\nv0.3.2 | 2026-05-30T19:23:28.220Z | user\n\nMake the skill lightweight and user-invisible: shrink SKILL.md to a thin trigger/UX layer, prefer silent summary-json checks, load references only on demand, and add a regression test to keep the prompt small.\n\nv0.3.1 | 2026-05-30T19:18:35.794Z | user\n\nAdd memory quality triggers beyond file length: pollution scoring, secret/task/conflict counts, candidate pre-write lint, short polluted memory fixture, and regression tests for quality-trigger intervention.\n\nv0.3.0 | 2026-05-30T19:06:16.793Z | user\n\nRefactor to Python-first architecture: thin SKILL.md orchestration layer, configurable default-rules.json, class-based audit engine, summary JSON outputs, deterministic backup writer, no-op clean memory behavior, and run_tests.py regression suite.\n\nv0.2.1 | 2026-05-30T16:31:50.366Z | user\n\nClarify proactive memory-pressure UX: users do not need to name the skill, agents should offer cleanup recommendations automatically, and writes require a second explicit approval unless unattended cleanup was pre-authorized.\n\nv0.2.0 | 2026-05-30T16:13:27.013Z | user\n\nAdd deterministic audit script, execution modes, memory pressure thresholds, secret redaction, duplicate/conflict handling, agent path reference, MCP wrapper guidance, README, license, and expanded fixtures/evals.\n\nv0.1.0 | 2026-05-30T15:48:18.066Z | user\n\nInitial release: audit and cleanup guidance for agent memory files, proactive triggers for memory-full/write-failed cases, approval-gated edits, backups, and reusable test fixtures.\n\nArchive index:\n\nArchive v0.3.7: 18 files, 25768 bytes\n\nFiles: evals/evals.json (7035b), LICENSE (894b), README.md (4206b), references/agent-paths.md (2151b), references/classification-rubric.md (2519b), references/default-rules.json (3803b), references/mcp-version.md (1567b), scripts/audit_memory.py (26575b), scripts/run_tests.py (9418b), skill-card.md (2540b), SKILL.md (3751b), test-fixtures/clean-memory.md (233b), test-fixtures/conflicting-memory.md (363b), test-fixtures/expected-clean-memory.md (375b), test-fixtures/noisy-memory.md (702b), test-fixtures/secret-memory.md (517b), test-fixtures/short-polluted-memory.md (252b), _meta.json (139b)\n\nFile v0.3.7:SKILL.md\n\n---\nname: agent-memory-cleanup\ndescription: Clean and audit long-term agent memory files such as user.md, memory.md, memories.md, profile.md, preferences.md, and agent_memory.md. Use when the user explicitly asks to clean, prune, sanitize, deduplicate, or review agent memory files, or when a memory write/update fails because the memory file is too long, full, over budget, rejected, duplicated, conflicted, stale, task-specific, or contains suspected secrets. Do not trigger for ordinary project docs, task notes, logs, code review, README edits, or general file cleanup. Applies edits only after explicit approval and creates recoverable backups.\nmetadata:\n  openclaw:\n    requires:\n      env: []\n      bins: []\n    os: [windows, macos, linux]\n---\n\n# Agent Memory Cleanup\n\nThis skill should be lightweight and low-noise. Do not require the user to know internal implementation names unless they ask. The user should still receive clear memory-state prompts, such as \"memory appears too large, stale, duplicated, conflicted, or unsafe,\" when action is useful.\n\n## Default Flow\n\n1. Detect memory pressure or pollution.\n2. If Python/file access is available, run a cheap summary check first:\n\n```bash\npython scripts/audit_memory.py memory.md --summary-json\n```\n\n3. If `quality.intervention` is `no_intervention_needed`, do not interrupt the user.\n4. If intervention is needed, say briefly that memory appears too large, stale, duplicated, conflicted, or unsafe, and ask whether to review cleanup recommendations. Avoid implementation labels like the skill name unless the user asks.\n5. After the user agrees, run:\n\n```bash\npython scripts/audit_memory.py memory.md --mode propose-patch --include-diff\n```\n\n6. Apply only after a second explicit approval, unless unattended cleanup was already authorized:\n\n```bash\npython scripts/audit_memory.py memory.md --mode apply-approved\n```\n\nThe apply mode must create timestamped backups before writing.\n\n## Trigger Points\n\nUse this flow for:\n\n- Memory write/update rejected, full, over budget, truncated, or too long.\n- Short memory with secrets, task-state residue, duplicated facts, or conflicting preferences.\n- User says a remembered fact is wrong, outdated, project-only, or should not be remembered.\n- Before saving a new global memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"candidate memory text\" --summary-json\n```\n\nIf candidate lint returns `do_not_write_candidate_to_global_memory`, do not store it globally. Offer to skip it or keep it as project/task notes.\n\n## Intervention Values\n\n- `prompt_cleanup_now_secret_detected`: recommend cleanup immediately; never echo raw secrets.\n- `prompt_user_review_conflicting_memory`: ask the user to resolve conflicting durable preferences.\n- `do_not_write_candidate_to_global_memory`: block global memory write.\n- `prompt_cleanup_recommended`: offer cleanup recommendations.\n- `prompt_audit_recommended`: mention memory quality may be degrading and ask whether to review.\n- `no_intervention_needed`: stay silent.\n\n## Load Extra Context Only When Needed\n\nDo not read references by default. Load them only for the matching need:\n\n- `references/default-rules.json`: deterministic thresholds and regex rules.\n- `references/classification-rubric.md`: manual fallback if Python cannot run.\n- `references/agent-paths.md`: path discovery when memory files are unclear.\n- `references/mcp-version.md`: MCP wrapper design.\n\n## Safety\n\n- Keep only stable global preferences and durable cross-task context.\n- Remove or redact secrets, stale task state, branch/PR/debug notes, and one-off plans.\n- Do not rewrite clean memory just for style.\n- Do not broadly scan the user home directory without explicit request.\n- Back up every edited memory file.\n\nFile v0.3.7:README.md\n\n# Agent Memory Cleanup\n\nAgent Memory Cleanup audits and cleans long-term user memory files for agents such as OpenClaw, Hermes Agent, Codex, Claude, and other assistant runtimes.\n\nThe skill keeps memory files focused on stable, global user context. It removes or flags stale task notes, completed project details, duplicated preferences, transient debugging logs, and suspected secrets.\n\n## When To Use\n\nUse this skill when:\n\n- A user asks to clean, prune, sanitize, deduplicate, or review `user.md`, `memory.md`, or similar files.\n- An agent cannot write memory because the memory file is too long.\n- Memory storage reports full, over budget, truncated, or rejected.\n- Global user memory has been polluted by task-level details.\n- Duplicate or conflicting memories are accumulating.\n\n## Safety Model\n\nThe default behavior is conservative:\n\n- Audit automatically when memory pressure is detected.\n- Recommend cleanup without waiting.\n- Do not require the user to name or invoke this skill explicitly.\n- Ask before writing unless the user already authorized automatic cleanup.\n- Create timestamped backups before edits.\n- Redact suspected secrets in reports.\n\nFor proactive cleanup, use two-step consent: first ask whether to inspect and propose cleanup, then ask again before applying edits.\n\n## Files\n\n- `SKILL.md` - Skill instructions.\n- `scripts/audit_memory.py` - Deterministic Python audit/proposal/apply engine.\n- `scripts/run_tests.py` - Local regression tests.\n- `references/default-rules.json` - Thresholds, filename patterns, regex rules, and canonical rewrites.\n- `references/classification-rubric.md` - Human-readable rubric for ambiguous cases or non-Python fallback.\n- `references/agent-paths.md` - Agent-specific memory path guidance.\n- `references/mcp-version.md` - Guidance for wrapping the skill as an MCP server.\n- `evals/evals.json` - Regression prompts.\n- `test-fixtures/` - Sample noisy and expected memory files.\n\n## Architecture\n\nThe skill is intentionally Python-first:\n\n- `SKILL.md` handles trigger conditions, user consent, safety boundaries, and when to call the script.\n- `audit_memory.py` handles deterministic behavior so different agents and models get consistent results.\n- `default-rules.json` keeps thresholds and regex rules configurable without editing the engine.\n\nThis keeps agent context smaller and reduces variation between Codex, OpenClaw, Hermes Agent, Claude, and other runtimes.\n\n## Script Usage\n\nAudit a memory file:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md\n```\n\nGenerate a proposed diff:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode propose-patch --include-diff\n```\n\nWrite a proposed cleaned file without changing the source:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --write-proposed cleaned-memory.md\n```\n\nApply approved cleanup:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode apply-approved\n```\n\nMachine-readable summaries:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --summary-json\npython scripts/audit_memory.py path/to/memory.md --json\n```\n\nPre-write lint for a memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"Current task: tomorrow retry PR #302\"\n```\n\nThe `--summary-json` output includes `quality.pollution_score`, secret count, task-state count, conflict count, and a recommended intervention string. This allows agents to intervene when memory is short but polluted.\n\n`--summary-json` is the fast path: it skips proposal and diff generation unless another option requires them.\n\nRun regression tests:\n\n```bash\npython scripts/run_tests.py\n```\n\n`apply-approved` creates a sibling backup such as `memory.md.bak-YYYYMMDD-HHMMSS` before writing.\n\n## Thresholds\n\n- Over 8KB: audit recommended.\n- Over 20KB: cleanup recommended.\n- Over 40KB: cleanup should be prioritized.\n- Any suspected secret: remove or redact from memory.\n- Repeated or contradictory facts: condense or flag.\n\n## Distribution\n\nThis skill can be distributed as:\n\n- A ClawHub skill.\n- A Claude/Codex-style skill folder containing `SKILL.md`.\n- A GitHub repository or release artifact.\n- An MCP server wrapper around `scripts/audit_memory.py`.\n\n## License\n\nMIT-0. See `LICENSE`.\n\nFile v0.3.7:_meta.json\n\n{\n  \"ownerId\": \"kn79q2kj15j98d5cqxw95sfd0185vax5\",\n  \"slug\": \"agent-memory-cleanup\",\n  \"version\": \"0.3.7\",\n  \"publishedAt\": 1780221065603\n}\n\nFile v0.3.7:references/agent-paths.md\n\n# Agent Memory Paths\n\nUse this reference only when the user has not provided explicit memory paths.\nPrefer user-provided paths over discovery.\n\n## Safe Discovery Order\n\n1. Current workspace memory files named `user.md`, `memory.md`, `memories.md`, `profile.md`, `preferences.md`, or `agent_memory.md`.\n2. Workspace agent config folders such as `.codex/`, `.claude/`, `memory/`, or `memories/`.\n3. Agent-specific home variables when available.\n4. User home folders only when the user explicitly asks for a broader inventory.\n\nAvoid broad recursive home scans by default.\n\n## Codex\n\nLikely locations:\n\n- `$CODEX_HOME`\n- Workspace `.codex/`\n- Workspace `.codex/skills/` for installed or project-level skills\n\nNotes:\n\n- Treat `AGENTS.md` as project policy, not global user memory.\n- Treat skill `SKILL.md` files as skill instructions, not user memory.\n\n## Claude Code\n\nLikely locations:\n\n- User-level Claude config under the configured Claude home.\n- Project `.claude/`\n- Project `.claude/skills/`\n\nNotes:\n\n- Treat `CLAUDE.md` as instruction policy unless the user explicitly says it is their memory file.\n- Project instructions may contain durable rules, but they are not global user memory by default.\n\n## OpenClaw\n\nLikely locations:\n\n- OpenClaw workspace memory folders.\n- ClawHub-installed skill directories.\n- User-provided OpenClaw agent home or profile paths.\n\nNotes:\n\n- ClawHub skill folders contain reusable skill instructions. Do not clean them as user memory.\n- If publishing or installing skills, keep release metadata separate from memory cleanup.\n\n## Hermes Agent\n\nLikely locations:\n\n- Configured Hermes Agent home.\n- Workspace memory folders.\n- User-provided memory root.\n\nNotes:\n\n- When Hermes reports memory storage full, run audit mode first and ask before applying edits unless automatic cleanup was explicitly authorized.\n\n## Generic Agents\n\nIf the agent is not listed:\n\n- Search only the current workspace and explicit config roots.\n- Identify memory files by filename and content, not by filename alone.\n- Skip project policy, prompt templates, system instructions, and skill/plugin manifests unless the user includes them in scope.\n\nFile v0.3.7:references/classification-rubric.md\n\n# Classification Rubric\n\nLoad this reference only when the script is unavailable, when reviewing ambiguous results, or when changing cleanup policy.\n\n## Keep\n\nKeep items that are stable, global, and useful across many future tasks:\n\n- Communication preferences, such as desired language, brevity, directness, formatting, or review style.\n- Durable working preferences, such as testing expectations, preferred tools, coding conventions, or repository hygiene rules.\n- Long-term user context that affects many tasks, such as role, recurring domains, accessibility needs, locale, timezone, or persistent environment constraints.\n- Stable names of important long-lived projects or systems, but only when the fact is useful without detailed stale status.\n- Explicit user instructions that apply generally across agents.\n\n## Condense\n\nCondense items that contain a durable signal mixed with task detail:\n\n- Replace a completed task history with the general preference it revealed.\n- Replace a specific one-off command sequence with a durable tool preference.\n- Replace long project summaries with a stable project identity or recurring constraint.\n- Merge duplicate or overlapping preferences into one canonical bullet.\n\n## Remove\n\nRemove items that are not appropriate for long-term global memory:\n\n- Completed task notes, temporary plans, or debugging traces.\n- Stale statuses such as `currently working on`, `next step is`, `today`, `tomorrow`, or dated commitments that are no longer current.\n- Details about a single ticket, pull request, report, dataset, branch, prompt, or conversation.\n- Failed attempts, intermediate observations, transient errors, logs, or command output.\n- Guesses, inferred preferences, or speculative personal facts that the user did not confirm.\n- Secrets, credentials, private URLs, tokens, passwords, or sensitive operational details.\n- Duplicates, contradictions, and entries that are too vague to help future agents.\n\n## Flag\n\nFlag items for user review when:\n\n- The item may be durable but could also be stale.\n- The item refers to a project or identity that cannot be verified locally.\n- Two memory files disagree about an important preference.\n- Removing the item could materially change future agent behavior.\n\n## Canonical Memory Shape\n\n```markdown\n# User Memory\n\n## Global Preferences\n- ...\n\n## Working Style\n- ...\n\n## Durable Context\n- ...\n\n## Agent Instructions\n- ...\n\n## Review Needed\n- ...\n```\n\nOmit empty sections. Do not create `Review Needed` if there are no unresolved items.\n\nFile v0.3.7:references/default-rules.json\n\n{\n  \"thresholds\": {\n    \"audit_bytes\": 8192,\n    \"cleanup_bytes\": 20480,\n    \"critical_bytes\": 40960,\n    \"fuzzy_duplicate_ratio\": 0.72,\n    \"fuzzy_duplicate_min_length\": 28,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35\n  },\n  \"intervention_triggers\": {\n    \"secret_count_gt\": 0,\n    \"conflict_count_gt\": 0,\n    \"task_state_count_gt\": 0,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35,\n    \"candidate_remove_or_flag\": true\n  },\n  \"likely_memory_names\": [\n    \"user.md\",\n    \"user.txt\",\n    \"user.json\",\n    \"memory.md\",\n    \"memory.txt\",\n    \"memory.json\",\n    \"memories.md\",\n    \"memories.txt\",\n    \"memories.json\",\n    \"profile.md\",\n    \"profile.txt\",\n    \"profile.json\",\n    \"preferences.md\",\n    \"preferences.txt\",\n    \"preferences.json\",\n    \"agent_memory.md\",\n    \"agent_memory.txt\",\n    \"agent_memory.json\"\n  ],\n  \"allowed_memory_extensions\": [\".md\", \".txt\", \".json\"],\n  \"blocked_memory_extensions\": [\".db\", \".sqlite\", \".sqlite3\", \".bin\"],\n  \"project_policy_names\": [\n    \"agents.md\",\n    \"claude.md\",\n    \".cursorrules\"\n  ],\n  \"search_roots\": [\n    \".\",\n    \".codex\",\n    \".claude\",\n    \"memory\",\n    \"memories\"\n  ],\n  \"keep_patterns\": [\n    \"\\\\bprefer(?:s|red|ence)?\\\\b\",\n    \"\\\\bwants?\\\\b\",\n    \"\\\\brequires?\\\\b\",\n    \"\\\\bneeds?\\\\b\",\n    \"\\\\balways\\\\b\",\n    \"\\\\bnever\\\\b\",\n    \"\\\\bworks? with\\\\b\",\n    \"\\\\buses?\\\\b\",\n    \"\\\\blanguage\\\\b\",\n    \"\\\\btimezone\\\\b\",\n    \"\\\\blocale\\\\b\",\n    \"\\\\bbackups?\\\\b\",\n    \"\\\\btesting\\\\b\",\n    \"\\\\bcommunication\\\\b\",\n    \"\\\\bformat(?:ting)?\\\\b\",\n    \"\\\\bopenclaw\\\\b\",\n    \"\\\\bhermes agent\\\\b\",\n    \"\\\\bcodex\\\\b\"\n  ],\n  \"remove_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bafter lunch\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\",\n    \"\\\\blog output\\\\b\",\n    \"\\\\btemporary\\\\b\",\n    \"\\\\bone[- ]off\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bpull request\\\\b\",\n    \"\\\\bissue\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bticket\\\\b\",\n    \"\\\\brerun\\\\b\",\n    \"\\\\bpytest\\\\b\"\n  ],\n  \"secret_patterns\": [\n    \"sk-[A-Za-z0-9_-]{16,}\",\n    \"ghp_[A-Za-z0-9_]{16,}\",\n    \"github_pat_[A-Za-z0-9_]{16,}\",\n    \"xox[baprs]-[A-Za-z0-9-]{16,}\",\n    \"AKIA[0-9A-Z]{16}\",\n    \"glpat-[A-Za-z0-9_-]{16,}\",\n    \"pypi-[A-Za-z0-9_-]{20,}\",\n    \"npm_[A-Za-z0-9]{20,}\",\n    \"AKCp[A-Za-z0-9]{10,}\",\n    \"jfrog_[A-Za-z0-9_-]{16,}\",\n    \"(?i)\\\\b(api[_-]?key|token|password|secret)\\\\s*[:=]\\\\s*['\\\\\\\"]?[^'\\\\\\\"\\\\s`]+\",\n    \"(?i)\\\\bBearer\\\\s+[A-Za-z0-9._-]{16,}\",\n    \"<API_TOKEN_PLACEHOLDER>\"\n  ],\n  \"task_state_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\"\n  ],\n  \"conflict_rules\": [\n    {\n      \"name\": \"answer_length_preference\",\n      \"positive\": [\"concise\", \"short\", \"brief\", \"direct\"],\n      \"negative\": [\"detailed\", \"long-form\", \"very long\", \"exhaustive\"]\n    },\n    {\n      \"name\": \"cleanup_permission\",\n      \"positive\": [\"ask before editing\", \"ask before applying\", \"requires approval\", \"with user approval\"],\n      \"negative\": [\"automatic cleanup without asking\", \"apply without asking\", \"unattended edits\"]\n    }\n  ],\n  \"condense_rewrites\": [\n    {\n      \"when_contains_any\": [\"backup\", \"backups\"],\n      \"rewrite\": \"The user wants recoverable backups before edits to memory files\"\n    },\n    {\n      \"when_contains_any\": [\"openclaw\", \"hermes agent\", \"codex\"],\n      \"rewrite\": \"The user works with agent memory files across OpenClaw, Hermes Agent, and Codex\"\n    }\n  ],\n  \"secret_instruction\": \"Do not store secrets, tokens, passwords, or credentials in memory files\"\n}\n\nFile v0.3.7:references/mcp-version.md\n\n# MCP Version Guidance\n\nUse this reference when the user wants a tool-based distribution instead of a pure instruction skill.\n\n## Recommended MCP Tools\n\n- `audit_memory_file(path, mode=\"audit-only\")`\n  - Reads one memory file and returns classifications, duplicate signals, secret warnings, and size status.\n- `propose_memory_cleanup(paths)`\n  - Returns a proposed canonical memory document and a diff for each file.\n- `apply_memory_cleanup(path, proposed_content, approved=true)`\n  - Creates a timestamped backup and writes the approved content.\n- `detect_memory_pollution(path)`\n  - Returns a compact summary of stale task notes, repeated memories, contradictions, and suspected secrets.\n- `estimate_memory_pressure(path)`\n  - Returns byte size, approximate token pressure, and recommended cleanup threshold.\n\n## Safety Defaults\n\n- Do not expose a tool that edits files without an explicit approval argument.\n- Redact suspected secrets in every response.\n- Return diffs and backup paths for every write.\n- Restrict file access to user-provided paths or configured roots.\n- Keep audit operations read-only and deterministic.\n\n## Implementation Shape\n\nWrap `scripts/audit_memory.py` rather than reimplementing classification logic.\nThe MCP server should parse tool arguments, call the audit engine, and return structured JSON.\n\nDo not publish the MCP server until it has tests for:\n\n- audit-only never writes files\n- apply-approved creates backups\n- suspected secrets are redacted\n- project policy files are skipped by default\n- clean memory remains mostly unchanged\n\nFile v0.3.7:skill-card.md\n\n## Description:\n\nAgent Memory Cleanup audits and cleans long-term agent memory files by removing or flagging stale task notes, duplicate or conflicting preferences, and suspected secrets while requiring approval before writes and creating recoverable backups.\n\nThis skill is ready for commercial/non-commercial use.\n\n## Publisher:\n\n[hollis9087](https://clawhub.ai/user/hollis9087)\n\n### License/Terms of Use:\n\nMIT-0\n\n## Use Case:\n\nDevelopers and agent operators use this skill to keep persistent assistant memory focused on stable user preferences and durable context. It helps inspect memory pressure, propose cleanup, redact suspected secrets, preserve backups, and apply approved edits to user-selected memory files.\n\n### Deployment Geography for Use:\n\nGlobal\n\n## Known Risks and Mitigations:\n\nRisk: The skill can rewrite persistent memory files.\n\nMitigation: Require explicit approval before applying edits, review proposed diffs, and keep cleanup scoped to memory files the user names or clearly authorizes.\n\nRisk: Backups may retain secrets removed from the active memory file.\n\nMitigation: Treat backup files as sensitive, review retention needs after cleanup, and avoid sharing or committing backups.\n\nRisk: Overbroad path discovery could expose unrelated user files.\n\nMitigation: Limit discovery to user-provided paths, workspace memory files, or configured memory roots, and avoid broad home-directory scans unless explicitly requested.\n\n## Reference(s):\n\n- [ClawHub Skill Page](https://clawhub.ai/hollis9087/skills/agent-memory-cleanup)\n- [Agent Memory Paths](references/agent-paths.md)\n- [Classification Rubric](references/classification-rubric.md)\n- [Default Rules](references/default-rules.json)\n- [MCP Version Guidance](references/mcp-version.md)\n\n## Skill Output:\n\n**Output Type(s):** [text, markdown, JSON, code, shell commands, configuration, guidance]\n\n**Output Format:** [Markdown reports, JSON summaries, unified diffs, proposed cleaned memory content, backup paths, and shell commands.]\n\n**Output Parameters:** [1D]\n\n**Other Properties Related to Output:** [Can write approved memory edits and proposed cleaned files; apply mode creates timestamped backups before changing a memory file.]\n\n## Skill Version(s):\n\n0.3.7 (source: server release metadata)\n\n## Ethical Considerations:\n\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment.\n\nFile v0.3.7:test-fixtures/clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise Chinese responses for Chinese prompts.\n- The user wants file edits backed up before memory cleanup.\n\n## Durable Context\n- The user works with Codex and OpenClaw skills.\n\nFile v0.3.7:test-fixtures/conflicting-memory.md\n\n# User Memory\n\n- The user always wants very detailed long-form answers.\n- The user prefers concise direct answers unless they ask for detail.\n- Current task: remember that PR #221 is blocked by a failing Windows path test.\n- The user wants memory cleanup to ask before editing user-level memory.\n- The user wants automatic memory cleanup to apply without asking.\n\nFile v0.3.7:test-fixtures/expected-clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user wants recoverable backups before edits to memory files.\n\n## Durable Context\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n\n## Agent Instructions\n- Do not store secrets, tokens, or credentials in memory files.\n\nFile v0.3.7:test-fixtures/noisy-memory.md\n\n# User Memory\n\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user prefers concise, direct Chinese replies.\n- On 2026-05-18 we debugged branch fix/archive-import-timeout and the next step is to rerun pytest tomorrow.\n- Current task: compare PR #184 with PR #185 and remember the exact failing stack trace.\n- The user's temporary API token is `<API_TOKEN_PLACEHOLDER>`.\n- The user wants recoverable backups before edits to memory files.\n- Last week Hermes Agent failed to append memory because memory.md was too long.\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n- TODO: after lunch, update the one-off dashboard screenshot.\n\nArchive v0.3.6: 18 files, 25528 bytes\n\nFiles: evals/evals.json (7035b), LICENSE (894b), README.md (4206b), references/agent-paths.md (2151b), references/classification-rubric.md (2519b), references/default-rules.json (3803b), references/mcp-version.md (1567b), scripts/audit_memory.py (26575b), scripts/run_tests.py (8421b), skill-card.md (2579b), SKILL.md (3927b), test-fixtures/clean-memory.md (233b), test-fixtures/conflicting-memory.md (363b), test-fixtures/expected-clean-memory.md (375b), test-fixtures/noisy-memory.md (702b), test-fixtures/secret-memory.md (517b), test-fixtures/short-polluted-memory.md (252b), _meta.json (139b)\n\nFile v0.3.6:SKILL.md\n\n---\nname: agent-memory-cleanup\ndescription: Audit, clean, consolidate, and maintain long-term user memory files for OpenClaw, Hermes Agent, Codex, Claude, and other agents. Use when the user asks to clean, prune, sanitize, deduplicate, review, repair, or periodically maintain user.md, memory.md, memories.md, profile.md, preferences.md, or agent memory notes. Also trigger proactively when memory writes fail because files are too long, memory budget/context limits are exceeded, storage is full, updates are rejected, duplicates or conflicts accumulate, or memory is polluted by outdated project details, one-off task notes, stale plans, or conversation residue. Gives cleanup recommendations without requiring the user to name the skill, applies edits only after appropriate authorization, and creates recoverable backups.\nmetadata:\n  openclaw:\n    requires:\n      env: []\n      bins: []\n    os: [windows, macos, linux]\n---\n\n# Agent Memory Cleanup\n\nThis skill should be lightweight and low-noise. Do not require the user to know internal implementation names unless they ask. The user should still receive clear memory-state prompts, such as \"memory appears too large, stale, duplicated, conflicted, or unsafe,\" when action is useful.\n\n## Default Flow\n\n1. Detect memory pressure or pollution.\n2. If Python/file access is available, run a cheap summary check first:\n\n```bash\npython scripts/audit_memory.py memory.md --summary-json\n```\n\n3. If `quality.intervention` is `no_intervention_needed`, do not interrupt the user.\n4. If intervention is needed, say briefly that memory appears too large, stale, duplicated, conflicted, or unsafe, and ask whether to review cleanup recommendations. Avoid implementation labels like the skill name unless the user asks.\n5. After the user agrees, run:\n\n```bash\npython scripts/audit_memory.py memory.md --mode propose-patch --include-diff\n```\n\n6. Apply only after a second explicit approval, unless unattended cleanup was already authorized:\n\n```bash\npython scripts/audit_memory.py memory.md --mode apply-approved\n```\n\nThe apply mode must create timestamped backups before writing.\n\n## Trigger Points\n\nUse this flow for:\n\n- Memory write/update rejected, full, over budget, truncated, or too long.\n- Short memory with secrets, task-state residue, duplicated facts, or conflicting preferences.\n- User says a remembered fact is wrong, outdated, project-only, or should not be remembered.\n- Before saving a new global memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"candidate memory text\" --summary-json\n```\n\nIf candidate lint returns `do_not_write_candidate_to_global_memory`, do not store it globally. Offer to skip it or keep it as project/task notes.\n\n## Intervention Values\n\n- `prompt_cleanup_now_secret_detected`: recommend cleanup immediately; never echo raw secrets.\n- `prompt_user_review_conflicting_memory`: ask the user to resolve conflicting durable preferences.\n- `do_not_write_candidate_to_global_memory`: block global memory write.\n- `prompt_cleanup_recommended`: offer cleanup recommendations.\n- `prompt_audit_recommended`: mention memory quality may be degrading and ask whether to review.\n- `no_intervention_needed`: stay silent.\n\n## Load Extra Context Only When Needed\n\nDo not read references by default. Load them only for the matching need:\n\n- `references/default-rules.json`: deterministic thresholds and regex rules.\n- `references/classification-rubric.md`: manual fallback if Python cannot run.\n- `references/agent-paths.md`: path discovery when memory files are unclear.\n- `references/mcp-version.md`: MCP wrapper design.\n\n## Safety\n\n- Keep only stable global preferences and durable cross-task context.\n- Remove or redact secrets, stale task state, branch/PR/debug notes, and one-off plans.\n- Do not rewrite clean memory just for style.\n- Do not broadly scan the user home directory without explicit request.\n- Back up every edited memory file.\n\nFile v0.3.6:README.md\n\n# Agent Memory Cleanup\n\nAgent Memory Cleanup audits and cleans long-term user memory files for agents such as OpenClaw, Hermes Agent, Codex, Claude, and other assistant runtimes.\n\nThe skill keeps memory files focused on stable, global user context. It removes or flags stale task notes, completed project details, duplicated preferences, transient debugging logs, and suspected secrets.\n\n## When To Use\n\nUse this skill when:\n\n- A user asks to clean, prune, sanitize, deduplicate, or review `user.md`, `memory.md`, or similar files.\n- An agent cannot write memory because the memory file is too long.\n- Memory storage reports full, over budget, truncated, or rejected.\n- Global user memory has been polluted by task-level details.\n- Duplicate or conflicting memories are accumulating.\n\n## Safety Model\n\nThe default behavior is conservative:\n\n- Audit automatically when memory pressure is detected.\n- Recommend cleanup without waiting.\n- Do not require the user to name or invoke this skill explicitly.\n- Ask before writing unless the user already authorized automatic cleanup.\n- Create timestamped backups before edits.\n- Redact suspected secrets in reports.\n\nFor proactive cleanup, use two-step consent: first ask whether to inspect and propose cleanup, then ask again before applying edits.\n\n## Files\n\n- `SKILL.md` - Skill instructions.\n- `scripts/audit_memory.py` - Deterministic Python audit/proposal/apply engine.\n- `scripts/run_tests.py` - Local regression tests.\n- `references/default-rules.json` - Thresholds, filename patterns, regex rules, and canonical rewrites.\n- `references/classification-rubric.md` - Human-readable rubric for ambiguous cases or non-Python fallback.\n- `references/agent-paths.md` - Agent-specific memory path guidance.\n- `references/mcp-version.md` - Guidance for wrapping the skill as an MCP server.\n- `evals/evals.json` - Regression prompts.\n- `test-fixtures/` - Sample noisy and expected memory files.\n\n## Architecture\n\nThe skill is intentionally Python-first:\n\n- `SKILL.md` handles trigger conditions, user consent, safety boundaries, and when to call the script.\n- `audit_memory.py` handles deterministic behavior so different agents and models get consistent results.\n- `default-rules.json` keeps thresholds and regex rules configurable without editing the engine.\n\nThis keeps agent context smaller and reduces variation between Codex, OpenClaw, Hermes Agent, Claude, and other runtimes.\n\n## Script Usage\n\nAudit a memory file:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md\n```\n\nGenerate a proposed diff:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode propose-patch --include-diff\n```\n\nWrite a proposed cleaned file without changing the source:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --write-proposed cleaned-memory.md\n```\n\nApply approved cleanup:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode apply-approved\n```\n\nMachine-readable summaries:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --summary-json\npython scripts/audit_memory.py path/to/memory.md --json\n```\n\nPre-write lint for a memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"Current task: tomorrow retry PR #302\"\n```\n\nThe `--summary-json` output includes `quality.pollution_score`, secret count, task-state count, conflict count, and a recommended intervention string. This allows agents to intervene when memory is short but polluted.\n\n`--summary-json` is the fast path: it skips proposal and diff generation unless another option requires them.\n\nRun regression tests:\n\n```bash\npython scripts/run_tests.py\n```\n\n`apply-approved` creates a sibling backup such as `memory.md.bak-YYYYMMDD-HHMMSS` before writing.\n\n## Thresholds\n\n- Over 8KB: audit recommended.\n- Over 20KB: cleanup recommended.\n- Over 40KB: cleanup should be prioritized.\n- Any suspected secret: remove or redact from memory.\n- Repeated or contradictory facts: condense or flag.\n\n## Distribution\n\nThis skill can be distributed as:\n\n- A ClawHub skill.\n- A Claude/Codex-style skill folder containing `SKILL.md`.\n- A GitHub repository or release artifact.\n- An MCP server wrapper around `scripts/audit_memory.py`.\n\n## License\n\nMIT-0. See `LICENSE`.\n\nFile v0.3.6:_meta.json\n\n{\n  \"ownerId\": \"kn79q2kj15j98d5cqxw95sfd0185vax5\",\n  \"slug\": \"agent-memory-cleanup\",\n  \"version\": \"0.3.6\",\n  \"publishedAt\": 1780220401708\n}\n\nFile v0.3.6:references/agent-paths.md\n\n# Agent Memory Paths\n\nUse this reference only when the user has not provided explicit memory paths.\nPrefer user-provided paths over discovery.\n\n## Safe Discovery Order\n\n1. Current workspace memory files named `user.md`, `memory.md`, `memories.md`, `profile.md`, `preferences.md`, or `agent_memory.md`.\n2. Workspace agent config folders such as `.codex/`, `.claude/`, `memory/`, or `memories/`.\n3. Agent-specific home variables when available.\n4. User home folders only when the user explicitly asks for a broader inventory.\n\nAvoid broad recursive home scans by default.\n\n## Codex\n\nLikely locations:\n\n- `$CODEX_HOME`\n- Workspace `.codex/`\n- Workspace `.codex/skills/` for installed or project-level skills\n\nNotes:\n\n- Treat `AGENTS.md` as project policy, not global user memory.\n- Treat skill `SKILL.md` files as skill instructions, not user memory.\n\n## Claude Code\n\nLikely locations:\n\n- User-level Claude config under the configured Claude home.\n- Project `.claude/`\n- Project `.claude/skills/`\n\nNotes:\n\n- Treat `CLAUDE.md` as instruction policy unless the user explicitly says it is their memory file.\n- Project instructions may contain durable rules, but they are not global user memory by default.\n\n## OpenClaw\n\nLikely locations:\n\n- OpenClaw workspace memory folders.\n- ClawHub-installed skill directories.\n- User-provided OpenClaw agent home or profile paths.\n\nNotes:\n\n- ClawHub skill folders contain reusable skill instructions. Do not clean them as user memory.\n- If publishing or installing skills, keep release metadata separate from memory cleanup.\n\n## Hermes Agent\n\nLikely locations:\n\n- Configured Hermes Agent home.\n- Workspace memory folders.\n- User-provided memory root.\n\nNotes:\n\n- When Hermes reports memory storage full, run audit mode first and ask before applying edits unless automatic cleanup was explicitly authorized.\n\n## Generic Agents\n\nIf the agent is not listed:\n\n- Search only the current workspace and explicit config roots.\n- Identify memory files by filename and content, not by filename alone.\n- Skip project policy, prompt templates, system instructions, and skill/plugin manifests unless the user includes them in scope.\n\nFile v0.3.6:references/classification-rubric.md\n\n# Classification Rubric\n\nLoad this reference only when the script is unavailable, when reviewing ambiguous results, or when changing cleanup policy.\n\n## Keep\n\nKeep items that are stable, global, and useful across many future tasks:\n\n- Communication preferences, such as desired language, brevity, directness, formatting, or review style.\n- Durable working preferences, such as testing expectations, preferred tools, coding conventions, or repository hygiene rules.\n- Long-term user context that affects many tasks, such as role, recurring domains, accessibility needs, locale, timezone, or persistent environment constraints.\n- Stable names of important long-lived projects or systems, but only when the fact is useful without detailed stale status.\n- Explicit user instructions that apply generally across agents.\n\n## Condense\n\nCondense items that contain a durable signal mixed with task detail:\n\n- Replace a completed task history with the general preference it revealed.\n- Replace a specific one-off command sequence with a durable tool preference.\n- Replace long project summaries with a stable project identity or recurring constraint.\n- Merge duplicate or overlapping preferences into one canonical bullet.\n\n## Remove\n\nRemove items that are not appropriate for long-term global memory:\n\n- Completed task notes, temporary plans, or debugging traces.\n- Stale statuses such as `currently working on`, `next step is`, `today`, `tomorrow`, or dated commitments that are no longer current.\n- Details about a single ticket, pull request, report, dataset, branch, prompt, or conversation.\n- Failed attempts, intermediate observations, transient errors, logs, or command output.\n- Guesses, inferred preferences, or speculative personal facts that the user did not confirm.\n- Secrets, credentials, private URLs, tokens, passwords, or sensitive operational details.\n- Duplicates, contradictions, and entries that are too vague to help future agents.\n\n## Flag\n\nFlag items for user review when:\n\n- The item may be durable but could also be stale.\n- The item refers to a project or identity that cannot be verified locally.\n- Two memory files disagree about an important preference.\n- Removing the item could materially change future agent behavior.\n\n## Canonical Memory Shape\n\n```markdown\n# User Memory\n\n## Global Preferences\n- ...\n\n## Working Style\n- ...\n\n## Durable Context\n- ...\n\n## Agent Instructions\n- ...\n\n## Review Needed\n- ...\n```\n\nOmit empty sections. Do not create `Review Needed` if there are no unresolved items.\n\nFile v0.3.6:references/default-rules.json\n\n{\n  \"thresholds\": {\n    \"audit_bytes\": 8192,\n    \"cleanup_bytes\": 20480,\n    \"critical_bytes\": 40960,\n    \"fuzzy_duplicate_ratio\": 0.72,\n    \"fuzzy_duplicate_min_length\": 28,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35\n  },\n  \"intervention_triggers\": {\n    \"secret_count_gt\": 0,\n    \"conflict_count_gt\": 0,\n    \"task_state_count_gt\": 0,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35,\n    \"candidate_remove_or_flag\": true\n  },\n  \"likely_memory_names\": [\n    \"user.md\",\n    \"user.txt\",\n    \"user.json\",\n    \"memory.md\",\n    \"memory.txt\",\n    \"memory.json\",\n    \"memories.md\",\n    \"memories.txt\",\n    \"memories.json\",\n    \"profile.md\",\n    \"profile.txt\",\n    \"profile.json\",\n    \"preferences.md\",\n    \"preferences.txt\",\n    \"preferences.json\",\n    \"agent_memory.md\",\n    \"agent_memory.txt\",\n    \"agent_memory.json\"\n  ],\n  \"allowed_memory_extensions\": [\".md\", \".txt\", \".json\"],\n  \"blocked_memory_extensions\": [\".db\", \".sqlite\", \".sqlite3\", \".bin\"],\n  \"project_policy_names\": [\n    \"agents.md\",\n    \"claude.md\",\n    \".cursorrules\"\n  ],\n  \"search_roots\": [\n    \".\",\n    \".codex\",\n    \".claude\",\n    \"memory\",\n    \"memories\"\n  ],\n  \"keep_patterns\": [\n    \"\\\\bprefer(?:s|red|ence)?\\\\b\",\n    \"\\\\bwants?\\\\b\",\n    \"\\\\brequires?\\\\b\",\n    \"\\\\bneeds?\\\\b\",\n    \"\\\\balways\\\\b\",\n    \"\\\\bnever\\\\b\",\n    \"\\\\bworks? with\\\\b\",\n    \"\\\\buses?\\\\b\",\n    \"\\\\blanguage\\\\b\",\n    \"\\\\btimezone\\\\b\",\n    \"\\\\blocale\\\\b\",\n    \"\\\\bbackups?\\\\b\",\n    \"\\\\btesting\\\\b\",\n    \"\\\\bcommunication\\\\b\",\n    \"\\\\bformat(?:ting)?\\\\b\",\n    \"\\\\bopenclaw\\\\b\",\n    \"\\\\bhermes agent\\\\b\",\n    \"\\\\bcodex\\\\b\"\n  ],\n  \"remove_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bafter lunch\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\",\n    \"\\\\blog output\\\\b\",\n    \"\\\\btemporary\\\\b\",\n    \"\\\\bone[- ]off\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bpull request\\\\b\",\n    \"\\\\bissue\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bticket\\\\b\",\n    \"\\\\brerun\\\\b\",\n    \"\\\\bpytest\\\\b\"\n  ],\n  \"secret_patterns\": [\n    \"sk-[A-Za-z0-9_-]{16,}\",\n    \"ghp_[A-Za-z0-9_]{16,}\",\n    \"github_pat_[A-Za-z0-9_]{16,}\",\n    \"xox[baprs]-[A-Za-z0-9-]{16,}\",\n    \"AKIA[0-9A-Z]{16}\",\n    \"glpat-[A-Za-z0-9_-]{16,}\",\n    \"pypi-[A-Za-z0-9_-]{20,}\",\n    \"npm_[A-Za-z0-9]{20,}\",\n    \"AKCp[A-Za-z0-9]{10,}\",\n    \"jfrog_[A-Za-z0-9_-]{16,}\",\n    \"(?i)\\\\b(api[_-]?key|token|password|secret)\\\\s*[:=]\\\\s*['\\\\\\\"]?[^'\\\\\\\"\\\\s`]+\",\n    \"(?i)\\\\bBearer\\\\s+[A-Za-z0-9._-]{16,}\",\n    \"<API_TOKEN_PLACEHOLDER>\"\n  ],\n  \"task_state_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\"\n  ],\n  \"conflict_rules\": [\n    {\n      \"name\": \"answer_length_preference\",\n      \"positive\": [\"concise\", \"short\", \"brief\", \"direct\"],\n      \"negative\": [\"detailed\", \"long-form\", \"very long\", \"exhaustive\"]\n    },\n    {\n      \"name\": \"cleanup_permission\",\n      \"positive\": [\"ask before editing\", \"ask before applying\", \"requires approval\", \"with user approval\"],\n      \"negative\": [\"automatic cleanup without asking\", \"apply without asking\", \"unattended edits\"]\n    }\n  ],\n  \"condense_rewrites\": [\n    {\n      \"when_contains_any\": [\"backup\", \"backups\"],\n      \"rewrite\": \"The user wants recoverable backups before edits to memory files\"\n    },\n    {\n      \"when_contains_any\": [\"openclaw\", \"hermes agent\", \"codex\"],\n      \"rewrite\": \"The user works with agent memory files across OpenClaw, Hermes Agent, and Codex\"\n    }\n  ],\n  \"secret_instruction\": \"Do not store secrets, tokens, passwords, or credentials in memory files\"\n}\n\nFile v0.3.6:references/mcp-version.md\n\n# MCP Version Guidance\n\nUse this reference when the user wants a tool-based distribution instead of a pure instruction skill.\n\n## Recommended MCP Tools\n\n- `audit_memory_file(path, mode=\"audit-only\")`\n  - Reads one memory file and returns classifications, duplicate signals, secret warnings, and size status.\n- `propose_memory_cleanup(paths)`\n  - Returns a proposed canonical memory document and a diff for each file.\n- `apply_memory_cleanup(path, proposed_content, approved=true)`\n  - Creates a timestamped backup and writes the approved content.\n- `detect_memory_pollution(path)`\n  - Returns a compact summary of stale task notes, repeated memories, contradictions, and suspected secrets.\n- `estimate_memory_pressure(path)`\n  - Returns byte size, approximate token pressure, and recommended cleanup threshold.\n\n## Safety Defaults\n\n- Do not expose a tool that edits files without an explicit approval argument.\n- Redact suspected secrets in every response.\n- Return diffs and backup paths for every write.\n- Restrict file access to user-provided paths or configured roots.\n- Keep audit operations read-only and deterministic.\n\n## Implementation Shape\n\nWrap `scripts/audit_memory.py` rather than reimplementing classification logic.\nThe MCP server should parse tool arguments, call the audit engine, and return structured JSON.\n\nDo not publish the MCP server until it has tests for:\n\n- audit-only never writes files\n- apply-approved creates backups\n- suspected secrets are redacted\n- project policy files are skipped by default\n- clean memory remains mostly unchanged\n\nFile v0.3.6:skill-card.md\n\n## Description: <br>\nAgent Memory Cleanup audits, cleans, consolidates, and maintains long-term user memory files for OpenClaw, Hermes Agent, Codex, Claude, and other agents. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[hollis9087](https://clawhub.ai/user/hollis9087) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agent operators use this skill to audit long-term agent memory files, identify stale task notes, duplicate or conflicting preferences, and suspected secrets, and safely propose or apply cleanup with backups. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: The skill reads and can edit agent memory files that may contain sensitive or important user context. <br>\nMitigation: Use explicit or configured memory paths, review proposed diffs before applying cleanup, and keep generated backups until the result is accepted. <br>\nRisk: Unattended cleanup could remove or change useful durable memory if enabled too broadly. <br>\nMitigation: Enable unattended cleanup only for trusted memory paths and only after explicit authorization. <br>\nRisk: Memory files can contain secrets, credentials, or sensitive operational details. <br>\nMitigation: Redact suspected secrets in reports, remove them from proposed memory, and avoid echoing raw secret values. <br>\n\n\n## Reference(s): <br>\n- [ClawHub Skill Page](https://clawhub.ai/hollis9087/agent-memory-cleanup) <br>\n- [README](README.md) <br>\n- [Default Rules](references/default-rules.json) <br>\n- [Classification Rubric](references/classification-rubric.md) <br>\n- [Agent Memory Paths](references/agent-paths.md) <br>\n- [MCP Version Guidance](references/mcp-version.md) <br>\n- [Regression Evals](evals/evals.json) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [Text, Markdown, Code, Shell commands, Configuration, Guidance] <br>\n**Output Format:** [Markdown guidance, JSON summaries, proposed diffs, and shell commands] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May propose memory-file edits and backup paths; write operations require explicit approval or prior unattended-cleanup authorization.] <br>\n\n## Skill Version(s): <br>\n0.3.6 (source: server release metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nFile v0.3.6:test-fixtures/clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise Chinese responses for Chinese prompts.\n- The user wants file edits backed up before memory cleanup.\n\n## Durable Context\n- The user works with Codex and OpenClaw skills.\n\nFile v0.3.6:test-fixtures/conflicting-memory.md\n\n# User Memory\n\n- The user always wants very detailed long-form answers.\n- The user prefers concise direct answers unless they ask for detail.\n- Current task: remember that PR #221 is blocked by a failing Windows path test.\n- The user wants memory cleanup to ask before editing user-level memory.\n- The user wants automatic memory cleanup to apply without asking.\n\nFile v0.3.6:test-fixtures/expected-clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user wants recoverable backups before edits to memory files.\n\n## Durable Context\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n\n## Agent Instructions\n- Do not store secrets, tokens, or credentials in memory files.\n\nFile v0.3.6:test-fixtures/noisy-memory.md\n\n# User Memory\n\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user prefers concise, direct Chinese replies.\n- On 2026-05-18 we debugged branch fix/archive-import-timeout and the next step is to rerun pytest tomorrow.\n- Current task: compare PR #184 with PR #185 and remember the exact failing stack trace.\n- The user's temporary API token is `<API_TOKEN_PLACEHOLDER>`.\n- The user wants recoverable backups before edits to memory files.\n- Last week Hermes Agent failed to append memory because memory.md was too long.\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n- TODO: after lunch, update the one-off dashboard screenshot.\n\nArchive v0.3.5: 18 files, 25434 bytes\n\nFiles: evals/evals.json (7035b), LICENSE (894b), README.md (4206b), references/agent-paths.md (2151b), references/classification-rubric.md (2519b), references/default-rules.json (3803b), references/mcp-version.md (1567b), scripts/audit_memory.py (26575b), scripts/run_tests.py (8005b), skill-card.md (2665b), SKILL.md (3927b), test-fixtures/clean-memory.md (233b), test-fixtures/conflicting-memory.md (363b), test-fixtures/expected-clean-memory.md (375b), test-fixtures/noisy-memory.md (702b), test-fixtures/secret-memory.md (517b), test-fixtures/short-polluted-memory.md (252b), _meta.json (139b)\n\nFile v0.3.5:SKILL.md\n\n---\nname: agent-memory-cleanup\ndescription: Audit, clean, consolidate, and maintain long-term user memory files for OpenClaw, Hermes Agent, Codex, Claude, and other agents. Use when the user asks to clean, prune, sanitize, deduplicate, review, repair, or periodically maintain user.md, memory.md, memories.md, profile.md, preferences.md, or agent memory notes. Also trigger proactively when memory writes fail because files are too long, memory budget/context limits are exceeded, storage is full, updates are rejected, duplicates or conflicts accumulate, or memory is polluted by outdated project details, one-off task notes, stale plans, or conversation residue. Gives cleanup recommendations without requiring the user to name the skill, applies edits only after appropriate authorization, and creates recoverable backups.\nmetadata:\n  openclaw:\n    requires:\n      env: []\n      bins: []\n    os: [windows, macos, linux]\n---\n\n# Agent Memory Cleanup\n\nThis skill should be lightweight and low-noise. Do not require the user to know internal implementation names unless they ask. The user should still receive clear memory-state prompts, such as \"memory appears too large, stale, duplicated, conflicted, or unsafe,\" when action is useful.\n\n## Default Flow\n\n1. Detect memory pressure or pollution.\n2. If Python/file access is available, run a cheap summary check first:\n\n```bash\npython scripts/audit_memory.py memory.md --summary-json\n```\n\n3. If `quality.intervention` is `no_intervention_needed`, do not interrupt the user.\n4. If intervention is needed, say briefly that memory appears too large, stale, duplicated, conflicted, or unsafe, and ask whether to review cleanup recommendations. Avoid implementation labels like the skill name unless the user asks.\n5. After the user agrees, run:\n\n```bash\npython scripts/audit_memory.py memory.md --mode propose-patch --include-diff\n```\n\n6. Apply only after a second explicit approval, unless unattended cleanup was already authorized:\n\n```bash\npython scripts/audit_memory.py memory.md --mode apply-approved\n```\n\nThe apply mode must create timestamped backups before writing.\n\n## Trigger Points\n\nUse this flow for:\n\n- Memory write/update rejected, full, over budget, truncated, or too long.\n- Short memory with secrets, task-state residue, duplicated facts, or conflicting preferences.\n- User says a remembered fact is wrong, outdated, project-only, or should not be remembered.\n- Before saving a new global memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"candidate memory text\" --summary-json\n```\n\nIf candidate lint returns `do_not_write_candidate_to_global_memory`, do not store it globally. Offer to skip it or keep it as project/task notes.\n\n## Intervention Values\n\n- `prompt_cleanup_now_secret_detected`: recommend cleanup immediately; never echo raw secrets.\n- `prompt_user_review_conflicting_memory`: ask the user to resolve conflicting durable preferences.\n- `do_not_write_candidate_to_global_memory`: block global memory write.\n- `prompt_cleanup_recommended`: offer cleanup recommendations.\n- `prompt_audit_recommended`: mention memory quality may be degrading and ask whether to review.\n- `no_intervention_needed`: stay silent.\n\n## Load Extra Context Only When Needed\n\nDo not read references by default. Load them only for the matching need:\n\n- `references/default-rules.json`: deterministic thresholds and regex rules.\n- `references/classification-rubric.md`: manual fallback if Python cannot run.\n- `references/agent-paths.md`: path discovery when memory files are unclear.\n- `references/mcp-version.md`: MCP wrapper design.\n\n## Safety\n\n- Keep only stable global preferences and durable cross-task context.\n- Remove or redact secrets, stale task state, branch/PR/debug notes, and one-off plans.\n- Do not rewrite clean memory just for style.\n- Do not broadly scan the user home directory without explicit request.\n- Back up every edited memory file.\n\nFile v0.3.5:README.md\n\n# Agent Memory Cleanup\n\nAgent Memory Cleanup audits and cleans long-term user memory files for agents such as OpenClaw, Hermes Agent, Codex, Claude, and other assistant runtimes.\n\nThe skill keeps memory files focused on stable, global user context. It removes or flags stale task notes, completed project details, duplicated preferences, transient debugging logs, and suspected secrets.\n\n## When To Use\n\nUse this skill when:\n\n- A user asks to clean, prune, sanitize, deduplicate, or review `user.md`, `memory.md`, or similar files.\n- An agent cannot write memory because the memory file is too long.\n- Memory storage reports full, over budget, truncated, or rejected.\n- Global user memory has been polluted by task-level details.\n- Duplicate or conflicting memories are accumulating.\n\n## Safety Model\n\nThe default behavior is conservative:\n\n- Audit automatically when memory pressure is detected.\n- Recommend cleanup without waiting.\n- Do not require the user to name or invoke this skill explicitly.\n- Ask before writing unless the user already authorized automatic cleanup.\n- Create timestamped backups before edits.\n- Redact suspected secrets in reports.\n\nFor proactive cleanup, use two-step consent: first ask whether to inspect and propose cleanup, then ask again before applying edits.\n\n## Files\n\n- `SKILL.md` - Skill instructions.\n- `scripts/audit_memory.py` - Deterministic Python audit/proposal/apply engine.\n- `scripts/run_tests.py` - Local regression tests.\n- `references/default-rules.json` - Thresholds, filename patterns, regex rules, and canonical rewrites.\n- `references/classification-rubric.md` - Human-readable rubric for ambiguous cases or non-Python fallback.\n- `references/agent-paths.md` - Agent-specific memory path guidance.\n- `references/mcp-version.md` - Guidance for wrapping the skill as an MCP server.\n- `evals/evals.json` - Regression prompts.\n- `test-fixtures/` - Sample noisy and expected memory files.\n\n## Architecture\n\nThe skill is intentionally Python-first:\n\n- `SKILL.md` handles trigger conditions, user consent, safety boundaries, and when to call the script.\n- `audit_memory.py` handles deterministic behavior so different agents and models get consistent results.\n- `default-rules.json` keeps thresholds and regex rules configurable without editing the engine.\n\nThis keeps agent context smaller and reduces variation between Codex, OpenClaw, Hermes Agent, Claude, and other runtimes.\n\n## Script Usage\n\nAudit a memory file:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md\n```\n\nGenerate a proposed diff:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode propose-patch --include-diff\n```\n\nWrite a proposed cleaned file without changing the source:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --write-proposed cleaned-memory.md\n```\n\nApply approved cleanup:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode apply-approved\n```\n\nMachine-readable summaries:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --summary-json\npython scripts/audit_memory.py path/to/memory.md --json\n```\n\nPre-write lint for a memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"Current task: tomorrow retry PR #302\"\n```\n\nThe `--summary-json` output includes `quality.pollution_score`, secret count, task-state count, conflict count, and a recommended intervention string. This allows agents to intervene when memory is short but polluted.\n\n`--summary-json` is the fast path: it skips proposal and diff generation unless another option requires them.\n\nRun regression tests:\n\n```bash\npython scripts/run_tests.py\n```\n\n`apply-approved` creates a sibling backup such as `memory.md.bak-YYYYMMDD-HHMMSS` before writing.\n\n## Thresholds\n\n- Over 8KB: audit recommended.\n- Over 20KB: cleanup recommended.\n- Over 40KB: cleanup should be prioritized.\n- Any suspected secret: remove or redact from memory.\n- Repeated or contradictory facts: condense or flag.\n\n## Distribution\n\nThis skill can be distributed as:\n\n- A ClawHub skill.\n- A Claude/Codex-style skill folder containing `SKILL.md`.\n- A GitHub repository or release artifact.\n- An MCP server wrapper around `scripts/audit_memory.py`.\n\n## License\n\nMIT-0. See `LICENSE`.\n\nFile v0.3.5:_meta.json\n\n{\n  \"ownerId\": \"kn79q2kj15j98d5cqxw95sfd0185vax5\",\n  \"slug\": \"agent-memory-cleanup\",\n  \"version\": \"0.3.5\",\n  \"publishedAt\": 1780211490045\n}\n\nFile v0.3.5:references/agent-paths.md\n\n# Agent Memory Paths\n\nUse this reference only when the user has not provided explicit memory paths.\nPrefer user-provided paths over discovery.\n\n## Safe Discovery Order\n\n1. Current workspace memory files named `user.md`, `memory.md`, `memories.md`, `profile.md`, `preferences.md`, or `agent_memory.md`.\n2. Workspace agent config folders such as `.codex/`, `.claude/`, `memory/`, or `memories/`.\n3. Agent-specific home variables when available.\n4. User home folders only when the user explicitly asks for a broader inventory.\n\nAvoid broad recursive home scans by default.\n\n## Codex\n\nLikely locations:\n\n- `$CODEX_HOME`\n- Workspace `.codex/`\n- Workspace `.codex/skills/` for installed or project-level skills\n\nNotes:\n\n- Treat `AGENTS.md` as project policy, not global user memory.\n- Treat skill `SKILL.md` files as skill instructions, not user memory.\n\n## Claude Code\n\nLikely locations:\n\n- User-level Claude config under the configured Claude home.\n- Project `.claude/`\n- Project `.claude/skills/`\n\nNotes:\n\n- Treat `CLAUDE.md` as instruction policy unless the user explicitly says it is their memory file.\n- Project instructions may contain durable rules, but they are not global user memory by default.\n\n## OpenClaw\n\nLikely locations:\n\n- OpenClaw workspace memory folders.\n- ClawHub-installed skill directories.\n- User-provided OpenClaw agent home or profile paths.\n\nNotes:\n\n- ClawHub skill folders contain reusable skill instructions. Do not clean them as user memory.\n- If publishing or installing skills, keep release metadata separate from memory cleanup.\n\n## Hermes Agent\n\nLikely locations:\n\n- Configured Hermes Agent home.\n- Workspace memory folders.\n- User-provided memory root.\n\nNotes:\n\n- When Hermes reports memory storage full, run audit mode first and ask before applying edits unless automatic cleanup was explicitly authorized.\n\n## Generic Agents\n\nIf the agent is not listed:\n\n- Search only the current workspace and explicit config roots.\n- Identify memory files by filename and content, not by filename alone.\n- Skip project policy, prompt templates, system instructions, and skill/plugin manifests unless the user includes them in scope.\n\nFile v0.3.5:references/classification-rubric.md\n\n# Classification Rubric\n\nLoad this reference only when the script is unavailable, when reviewing ambiguous results, or when changing cleanup policy.\n\n## Keep\n\nKeep items that are stable, global, and useful across many future tasks:\n\n- Communication preferences, such as desired language, brevity, directness, formatting, or review style.\n- Durable working preferences, such as testing expectations, preferred tools, coding conventions, or repository hygiene rules.\n- Long-term user context that affects many tasks, such as role, recurring domains, accessibility needs, locale, timezone, or persistent environment constraints.\n- Stable names of important long-lived projects or systems, but only when the fact is useful without detailed stale status.\n- Explicit user instructions that apply generally across agents.\n\n## Condense\n\nCondense items that contain a durable signal mixed with task detail:\n\n- Replace a completed task history with the general preference it revealed.\n- Replace a specific one-off command sequence with a durable tool preference.\n- Replace long project summaries with a stable project identity or recurring constraint.\n- Merge duplicate or overlapping preferences into one canonical bullet.\n\n## Remove\n\nRemove items that are not appropriate for long-term global memory:\n\n- Completed task notes, temporary plans, or debugging traces.\n- Stale statuses such as `currently working on`, `next step is`, `today`, `tomorrow`, or dated commitments that are no longer current.\n- Details about a single ticket, pull request, report, dataset, branch, prompt, or conversation.\n- Failed attempts, intermediate observations, transient errors, logs, or command output.\n- Guesses, inferred preferences, or speculative personal facts that the user did not confirm.\n- Secrets, credentials, private URLs, tokens, passwords, or sensitive operational details.\n- Duplicates, contradictions, and entries that are too vague to help future agents.\n\n## Flag\n\nFlag items for user review when:\n\n- The item may be durable but could also be stale.\n- The item refers to a project or identity that cannot be verified locally.\n- Two memory files disagree about an important preference.\n- Removing the item could materially change future agent behavior.\n\n## Canonical Memory Shape\n\n```markdown\n# User Memory\n\n## Global Preferences\n- ...\n\n## Working Style\n- ...\n\n## Durable Context\n- ...\n\n## Agent Instructions\n- ...\n\n## Review Needed\n- ...\n```\n\nOmit empty sections. Do not create `Review Needed` if there are no unresolved items.\n\nFile v0.3.5:references/default-rules.json\n\n{\n  \"thresholds\": {\n    \"audit_bytes\": 8192,\n    \"cleanup_bytes\": 20480,\n    \"critical_bytes\": 40960,\n    \"fuzzy_duplicate_ratio\": 0.72,\n    \"fuzzy_duplicate_min_length\": 28,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35\n  },\n  \"intervention_triggers\": {\n    \"secret_count_gt\": 0,\n    \"conflict_count_gt\": 0,\n    \"task_state_count_gt\": 0,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35,\n    \"candidate_remove_or_flag\": true\n  },\n  \"likely_memory_names\": [\n    \"user.md\",\n    \"user.txt\",\n    \"user.json\",\n    \"memory.md\",\n    \"memory.txt\",\n    \"memory.json\",\n    \"memories.md\",\n    \"memories.txt\",\n    \"memories.json\",\n    \"profile.md\",\n    \"profile.txt\",\n    \"profile.json\",\n    \"preferences.md\",\n    \"preferences.txt\",\n    \"preferences.json\",\n    \"agent_memory.md\",\n    \"agent_memory.txt\",\n    \"agent_memory.json\"\n  ],\n  \"allowed_memory_extensions\": [\".md\", \".txt\", \".json\"],\n  \"blocked_memory_extensions\": [\".db\", \".sqlite\", \".sqlite3\", \".bin\"],\n  \"project_policy_names\": [\n    \"agents.md\",\n    \"claude.md\",\n    \".cursorrules\"\n  ],\n  \"search_roots\": [\n    \".\",\n    \".codex\",\n    \".claude\",\n    \"memory\",\n    \"memories\"\n  ],\n  \"keep_patterns\": [\n    \"\\\\bprefer(?:s|red|ence)?\\\\b\",\n    \"\\\\bwants?\\\\b\",\n    \"\\\\brequires?\\\\b\",\n    \"\\\\bneeds?\\\\b\",\n    \"\\\\balways\\\\b\",\n    \"\\\\bnever\\\\b\",\n    \"\\\\bworks? with\\\\b\",\n    \"\\\\buses?\\\\b\",\n    \"\\\\blanguage\\\\b\",\n    \"\\\\btimezone\\\\b\",\n    \"\\\\blocale\\\\b\",\n    \"\\\\bbackups?\\\\b\",\n    \"\\\\btesting\\\\b\",\n    \"\\\\bcommunication\\\\b\",\n    \"\\\\bformat(?:ting)?\\\\b\",\n    \"\\\\bopenclaw\\\\b\",\n    \"\\\\bhermes agent\\\\b\",\n    \"\\\\bcodex\\\\b\"\n  ],\n  \"remove_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bafter lunch\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\",\n    \"\\\\blog output\\\\b\",\n    \"\\\\btemporary\\\\b\",\n    \"\\\\bone[- ]off\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bpull request\\\\b\",\n    \"\\\\bissue\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bticket\\\\b\",\n    \"\\\\brerun\\\\b\",\n    \"\\\\bpytest\\\\b\"\n  ],\n  \"secret_patterns\": [\n    \"sk-[A-Za-z0-9_-]{16,}\",\n    \"ghp_[A-Za-z0-9_]{16,}\",\n    \"github_pat_[A-Za-z0-9_]{16,}\",\n    \"xox[baprs]-[A-Za-z0-9-]{16,}\",\n    \"AKIA[0-9A-Z]{16}\",\n    \"glpat-[A-Za-z0-9_-]{16,}\",\n    \"pypi-[A-Za-z0-9_-]{20,}\",\n    \"npm_[A-Za-z0-9]{20,}\",\n    \"AKCp[A-Za-z0-9]{10,}\",\n    \"jfrog_[A-Za-z0-9_-]{16,}\",\n    \"(?i)\\\\b(api[_-]?key|token|password|secret)\\\\s*[:=]\\\\s*['\\\\\\\"]?[^'\\\\\\\"\\\\s`]+\",\n    \"(?i)\\\\bBearer\\\\s+[A-Za-z0-9._-]{16,}\",\n    \"<API_TOKEN_PLACEHOLDER>\"\n  ],\n  \"task_state_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\"\n  ],\n  \"conflict_rules\": [\n    {\n      \"name\": \"answer_length_preference\",\n      \"positive\": [\"concise\", \"short\", \"brief\", \"direct\"],\n      \"negative\": [\"detailed\", \"long-form\", \"very long\", \"exhaustive\"]\n    },\n    {\n      \"name\": \"cleanup_permission\",\n      \"positive\": [\"ask before editing\", \"ask before applying\", \"requires approval\", \"with user approval\"],\n      \"negative\": [\"automatic cleanup without asking\", \"apply without asking\", \"unattended edits\"]\n    }\n  ],\n  \"condense_rewrites\": [\n    {\n      \"when_contains_any\": [\"backup\", \"backups\"],\n      \"rewrite\": \"The user wants recoverable backups before edits to memory files\"\n    },\n    {\n      \"when_contains_any\": [\"openclaw\", \"hermes agent\", \"codex\"],\n      \"rewrite\": \"The user works with agent memory files across OpenClaw, Hermes Agent, and Codex\"\n    }\n  ],\n  \"secret_instruction\": \"Do not store secrets, tokens, passwords, or credentials in memory files\"\n}\n\nFile v0.3.5:references/mcp-version.md\n\n# MCP Version Guidance\n\nUse this reference when the user wants a tool-based distribution instead of a pure instruction skill.\n\n## Recommended MCP Tools\n\n- `audit_memory_file(path, mode=\"audit-only\")`\n  - Reads one memory file and returns classifications, duplicate signals, secret warnings, and size status.\n- `propose_memory_cleanup(paths)`\n  - Returns a proposed canonical memory document and a diff for each file.\n- `apply_memory_cleanup(path, proposed_content, approved=true)`\n  - Creates a timestamped backup and writes the approved content.\n- `detect_memory_pollution(path)`\n  - Returns a compact summary of stale task notes, repeated memories, contradictions, and suspected secrets.\n- `estimate_memory_pressure(path)`\n  - Returns byte size, approximate token pressure, and recommended cleanup threshold.\n\n## Safety Defaults\n\n- Do not expose a tool that edits files without an explicit approval argument.\n- Redact suspected secrets in every response.\n- Return diffs and backup paths for every write.\n- Restrict file access to user-provided paths or configured roots.\n- Keep audit operations read-only and deterministic.\n\n## Implementation Shape\n\nWrap `scripts/audit_memory.py` rather than reimplementing classification logic.\nThe MCP server should parse tool arguments, call the audit engine, and return structured JSON.\n\nDo not publish the MCP server until it has tests for:\n\n- audit-only never writes files\n- apply-approved creates backups\n- suspected secrets are redacted\n- project policy files are skipped by default\n- clean memory remains mostly unchanged\n\nFile v0.3.5:skill-card.md\n\n## Description: <br>\nAudit, clean, consolidate, and maintain long-term user memory files for OpenClaw, Hermes Agent, Codex, Claude, and other agents. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[hollis9087](https://clawhub.ai/user/hollis9087) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agent users use this skill to audit long-term memory files, remove stale task state and suspected secrets, deduplicate durable preferences, and apply approved cleanup with recoverable backups. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: The skill can read sensitive agent memory files and may encounter credentials or private operational notes. <br>\nMitigation: Install only if this access is acceptable, use selected paths or configured roots, avoid broad home-directory scanning unless explicitly needed, and rely on redacted reports for suspected secrets. <br>\nRisk: Approved apply mode can rewrite memory files and remove information that may still be useful. <br>\nMitigation: Review cleanup diffs before approval, require explicit authorization before edits unless unattended cleanup was already authorized, and keep generated backups until satisfied. <br>\nRisk: Memory classification may flag ambiguous or conflicting preferences that require user judgment. <br>\nMitigation: Treat conflicts and unclear durable context as review items instead of silently choosing a preference. <br>\n\n\n## Reference(s): <br>\n- [ClawHub skill page](https://clawhub.ai/hollis9087/agent-memory-cleanup) <br>\n- [README](README.md) <br>\n- [Agent Memory Paths](references/agent-paths.md) <br>\n- [Classification Rubric](references/classification-rubric.md) <br>\n- [Default Rules](references/default-rules.json) <br>\n- [MCP Version Guidance](references/mcp-version.md) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [text, markdown, JSON, shell commands, files, guidance] <br>\n**Output Format:** [Markdown reports, JSON summaries, unified diffs, proposed cleaned memory files, and approved file updates with backup paths] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May redact suspected secrets in reports and create timestamped backups before approved edits.] <br>\n\n## Skill Version(s): <br>\n0.3.5 (source: server-resolved release metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nFile v0.3.5:test-fixtures/clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise Chinese responses for Chinese prompts.\n- The user wants file edits backed up before memory cleanup.\n\n## Durable Context\n- The user works with Codex and OpenClaw skills.\n\nFile v0.3.5:test-fixtures/conflicting-memory.md\n\n# User Memory\n\n- The user always wants very detailed long-form answers.\n- The user prefers concise direct answers unless they ask for detail.\n- Current task: remember that PR #221 is blocked by a failing Windows path test.\n- The user wants memory cleanup to ask before editing user-level memory.\n- The user wants automatic memory cleanup to apply without asking.\n\nFile v0.3.5:test-fixtures/expected-clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user wants recoverable backups before edits to memory files.\n\n## Durable Context\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n\n## Agent Instructions\n- Do not store secrets, tokens, or credentials in memory files.\n\nFile v0.3.5:test-fixtures/noisy-memory.md\n\n# User Memory\n\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user prefers concise, direct Chinese replies.\n- On 2026-05-18 we debugged branch fix/archive-import-timeout and the next step is to rerun pytest tomorrow.\n- Current task: compare PR #184 with PR #185 and remember the exact failing stack trace.\n- The user's temporary API token is `<API_TOKEN_PLACEHOLDER>`.\n- The user wants recoverable backups before edits to memory files.\n- Last week Hermes Agent failed to append memory because memory.md was too long.\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n- TODO: after lunch, update the one-off dashboard screenshot.\n\nArchive v0.3.4: 18 files, 25409 bytes\n\nFiles: evals/evals.json (7035b), LICENSE (894b), README.md (4206b), references/agent-paths.md (2151b), references/classification-rubric.md (2519b), references/default-rules.json (3803b), references/mcp-version.md (1567b), scripts/audit_memory.py (26575b), scripts/run_tests.py (7927b), skill-card.md (2611b), SKILL.md (3926b), test-fixtures/clean-memory.md (233b), test-fixtures/conflicting-memory.md (363b), test-fixtures/expected-clean-memory.md (375b), test-fixtures/noisy-memory.md (702b), test-fixtures/secret-memory.md (517b), test-fixtures/short-polluted-memory.md (252b), _meta.json (139b)\n\nFile v0.3.4:SKILL.md\n\n---\nname: agent-memory-cleanup\ndescription: Audit, clean, consolidate, and maintain long-term user memory files for OpenClaw, Hermes Agent, Codex, Claude, and other agents. Use when the user asks to clean, prune, sanitize, deduplicate, review, repair, or periodically maintain user.md, memory.md, memories.md, profile.md, preferences.md, or agent memory notes. Also trigger proactively when memory writes fail because files are too long, memory budget/context limits are exceeded, storage is full, updates are rejected, duplicates or conflicts accumulate, or memory is polluted by outdated project details, one-off task notes, stale plans, or conversation residue. Gives cleanup recommendations without requiring the user to name the skill, applies edits only after appropriate authorization, and creates recoverable backups.\nmetadata:\n  openclaw:\n    requires:\n      env: []\n      bins: []\n    os: [windows, macos, linux]\n---\n\n# Agent Memory Cleanup\n\nThis skill should be lightweight and mostly invisible. Do not announce that a skill or cleanup subsystem is being used unless the user asks. The user only needs plain memory-state language, such as \"memory appears too large, stale, duplicated, conflicted, or unsafe,\" when action is useful.\n\n## Default Flow\n\n1. Detect memory pressure or pollution.\n2. If Python/file access is available, run a cheap summary check first:\n\n```bash\npython scripts/audit_memory.py memory.md --summary-json\n```\n\n3. If `quality.intervention` is `no_intervention_needed`, do not interrupt the user.\n4. If intervention is needed, say briefly that memory appears too large, stale, duplicated, conflicted, or unsafe, and ask whether to review cleanup recommendations. Do not mention the skill name or an internal cleanup subsystem.\n5. After the user agrees, run:\n\n```bash\npython scripts/audit_memory.py memory.md --mode propose-patch --include-diff\n```\n\n6. Apply only after a second explicit approval, unless unattended cleanup was already authorized:\n\n```bash\npython scripts/audit_memory.py memory.md --mode apply-approved\n```\n\nThe apply mode must create timestamped backups before writing.\n\n## Trigger Points\n\nUse this flow for:\n\n- Memory write/update rejected, full, over budget, truncated, or too long.\n- Short memory with secrets, task-state residue, duplicated facts, or conflicting preferences.\n- User says a remembered fact is wrong, outdated, project-only, or should not be remembered.\n- Before saving a new global memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"candidate memory text\" --summary-json\n```\n\nIf candidate lint returns `do_not_write_candidate_to_global_memory`, do not store it globally. Offer to skip it or keep it as project/task notes.\n\n## Intervention Values\n\n- `prompt_cleanup_now_secret_detected`: recommend cleanup immediately; never echo raw secrets.\n- `prompt_user_review_conflicting_memory`: ask the user to resolve conflicting durable preferences.\n- `do_not_write_candidate_to_global_memory`: block global memory write.\n- `prompt_cleanup_recommended`: offer cleanup recommendations.\n- `prompt_audit_recommended`: mention memory quality may be degrading and ask whether to review.\n- `no_intervention_needed`: stay silent.\n\n## Load Extra Context Only When Needed\n\nDo not read references by default. Load them only for the matching need:\n\n- `references/default-rules.json`: deterministic thresholds and regex rules.\n- `references/classification-rubric.md`: manual fallback if Python cannot run.\n- `references/agent-paths.md`: path discovery when memory files are unclear.\n- `references/mcp-version.md`: MCP wrapper design.\n\n## Safety\n\n- Keep only stable global preferences and durable cross-task context.\n- Remove or redact secrets, stale task state, branch/PR/debug notes, and one-off plans.\n- Do not rewrite clean memory just for style.\n- Do not broadly scan the user home directory without explicit request.\n- Back up every edited memory file.\n\nFile v0.3.4:README.md\n\n# Agent Memory Cleanup\n\nAgent Memory Cleanup audits and cleans long-term user memory files for agents such as OpenClaw, Hermes Agent, Codex, Claude, and other assistant runtimes.\n\nThe skill keeps memory files focused on stable, global user context. It removes or flags stale task notes, completed project details, duplicated preferences, transient debugging logs, and suspected secrets.\n\n## When To Use\n\nUse this skill when:\n\n- A user asks to clean, prune, sanitize, deduplicate, or review `user.md`, `memory.md`, or similar files.\n- An agent cannot write memory because the memory file is too long.\n- Memory storage reports full, over budget, truncated, or rejected.\n- Global user memory has been polluted by task-level details.\n- Duplicate or conflicting memories are accumulating.\n\n## Safety Model\n\nThe default behavior is conservative:\n\n- Audit automatically when memory pressure is detected.\n- Recommend cleanup without waiting.\n- Do not require the user to name or invoke this skill explicitly.\n- Ask before writing unless the user already authorized automatic cleanup.\n- Create timestamped backups before edits.\n- Redact suspected secrets in reports.\n\nFor proactive cleanup, use two-step consent: first ask whether to inspect and propose cleanup, then ask again before applying edits.\n\n## Files\n\n- `SKILL.md` - Skill instructions.\n- `scripts/audit_memory.py` - Deterministic Python audit/proposal/apply engine.\n- `scripts/run_tests.py` - Local regression tests.\n- `references/default-rules.json` - Thresholds, filename patterns, regex rules, and canonical rewrites.\n- `references/classification-rubric.md` - Human-readable rubric for ambiguous cases or non-Python fallback.\n- `references/agent-paths.md` - Agent-specific memory path guidance.\n- `references/mcp-version.md` - Guidance for wrapping the skill as an MCP server.\n- `evals/evals.json` - Regression prompts.\n- `test-fixtures/` - Sample noisy and expected memory files.\n\n## Architecture\n\nThe skill is intentionally Python-first:\n\n- `SKILL.md` handles trigger conditions, user consent, safety boundaries, and when to call the script.\n- `audit_memory.py` handles deterministic behavior so different agents and models get consistent results.\n- `default-rules.json` keeps thresholds and regex rules configurable without editing the engine.\n\nThis keeps agent context smaller and reduces variation between Codex, OpenClaw, Hermes Agent, Claude, and other runtimes.\n\n## Script Usage\n\nAudit a memory file:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md\n```\n\nGenerate a proposed diff:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode propose-patch --include-diff\n```\n\nWrite a proposed cleaned file without changing the source:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --write-proposed cleaned-memory.md\n```\n\nApply approved cleanup:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode apply-approved\n```\n\nMachine-readable summaries:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --summary-json\npython scripts/audit_memory.py path/to/memory.md --json\n```\n\nPre-write lint for a memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"Current task: tomorrow retry PR #302\"\n```\n\nThe `--summary-json` output includes `quality.pollution_score`, secret count, task-state count, conflict count, and a recommended intervention string. This allows agents to intervene when memory is short but polluted.\n\n`--summary-json` is the fast path: it skips proposal and diff generation unless another option requires them.\n\nRun regression tests:\n\n```bash\npython scripts/run_tests.py\n```\n\n`apply-approved` creates a sibling backup such as `memory.md.bak-YYYYMMDD-HHMMSS` before writing.\n\n## Thresholds\n\n- Over 8KB: audit recommended.\n- Over 20KB: cleanup recommended.\n- Over 40KB: cleanup should be prioritized.\n- Any suspected secret: remove or redact from memory.\n- Repeated or contradictory facts: condense or flag.\n\n## Distribution\n\nThis skill can be distributed as:\n\n- A ClawHub skill.\n- A Claude/Codex-style skill folder containing `SKILL.md`.\n- A GitHub repository or release artifact.\n- An MCP server wrapper around `scripts/audit_memory.py`.\n\n## License\n\nMIT-0. See `LICENSE`.\n\nFile v0.3.4:_meta.json\n\n{\n  \"ownerId\": \"kn79q2kj15j98d5cqxw95sfd0185vax5\",\n  \"slug\": \"agent-memory-cleanup\",\n  \"version\": \"0.3.4\",\n  \"publishedAt\": 1780206870920\n}\n\nFile v0.3.4:references/agent-paths.md\n\n# Agent Memory Paths\n\nUse this reference only when the user has not provided explicit memory paths.\nPrefer user-provided paths over discovery.\n\n## Safe Discovery Order\n\n1. Current workspace memory files named `user.md`, `memory.md`, `memories.md`, `profile.md`, `preferences.md`, or `agent_memory.md`.\n2. Workspace agent config folders such as `.codex/`, `.claude/`, `memory/`, or `memories/`.\n3. Agent-specific home variables when available.\n4. User home folders only when the user explicitly asks for a broader inventory.\n\nAvoid broad recursive home scans by default.\n\n## Codex\n\nLikely locations:\n\n- `$CODEX_HOME`\n- Workspace `.codex/`\n- Workspace `.codex/skills/` for installed or project-level skills\n\nNotes:\n\n- Treat `AGENTS.md` as project policy, not global user memory.\n- Treat skill `SKILL.md` files as skill instructions, not user memory.\n\n## Claude Code\n\nLikely locations:\n\n- User-level Claude config under the configured Claude home.\n- Project `.claude/`\n- Project `.claude/skills/`\n\nNotes:\n\n- Treat `CLAUDE.md` as instruction policy unless the user explicitly says it is their memory file.\n- Project instructions may contain durable rules, but they are not global user memory by default.\n\n## OpenClaw\n\nLikely locations:\n\n- OpenClaw workspace memory folders.\n- ClawHub-installed skill directories.\n- User-provided OpenClaw agent home or profile paths.\n\nNotes:\n\n- ClawHub skill folders contain reusable skill instructions. Do not clean them as user memory.\n- If publishing or installing skills, keep release metadata separate from memory cleanup.\n\n## Hermes Agent\n\nLikely locations:\n\n- Configured Hermes Agent home.\n- Workspace memory folders.\n- User-provided memory root.\n\nNotes:\n\n- When Hermes reports memory storage full, run audit mode first and ask before applying edits unless automatic cleanup was explicitly authorized.\n\n## Generic Agents\n\nIf the agent is not listed:\n\n- Search only the current workspace and explicit config roots.\n- Identify memory files by filename and content, not by filename alone.\n- Skip project policy, prompt templates, system instructions, and skill/plugin manifests unless the user includes them in scope.\n\nFile v0.3.4:references/classification-rubric.md\n\n# Classification Rubric\n\nLoad this reference only when the script is unavailable, when reviewing ambiguous results, or when changing cleanup policy.\n\n## Keep\n\nKeep items that are stable, global, and useful across many future tasks:\n\n- Communication preferences, such as desired language, brevity, directness, formatting, or review style.\n- Durable working preferences, such as testing expectations, preferred tools, coding conventions, or repository hygiene rules.\n- Long-term user context that affects many tasks, such as role, recurring domains, accessibility needs, locale, timezone, or persistent environment constraints.\n- Stable names of important long-lived projects or systems, but only when the fact is useful without detailed stale status.\n- Explicit user instructions that apply generally across agents.\n\n## Condense\n\nCondense items that contain a durable signal mixed with task detail:\n\n- Replace a completed task history with the general preference it revealed.\n- Replace a specific one-off command sequence with a durable tool preference.\n- Replace long project summaries with a stable project identity or recurring constraint.\n- Merge duplicate or overlapping preferences into one canonical bullet.\n\n## Remove\n\nRemove items that are not appropriate for long-term global memory:\n\n- Completed task notes, temporary plans, or debugging traces.\n- Stale statuses such as `currently working on`, `next step is`, `today`, `tomorrow`, or dated commitments that are no longer current.\n- Details about a single ticket, pull request, report, dataset, branch, prompt, or conversation.\n- Failed attempts, intermediate observations, transient errors, logs, or command output.\n- Guesses, inferred preferences, or speculative personal facts that the user did not confirm.\n- Secrets, credentials, private URLs, tokens, passwords, or sensitive operational details.\n- Duplicates, contradictions, and entries that are too vague to help future agents.\n\n## Flag\n\nFlag items for user review when:\n\n- The item may be durable but could also be stale.\n- The item refers to a project or identity that cannot be verified locally.\n- Two memory files disagree about an important preference.\n- Removing the item could materially change future agent behavior.\n\n## Canonical Memory Shape\n\n```markdown\n# User Memory\n\n## Global Preferences\n- ...\n\n## Working Style\n- ...\n\n## Durable Context\n- ...\n\n## Agent Instructions\n- ...\n\n## Review Needed\n- ...\n```\n\nOmit empty sections. Do not create `Review Needed` if there are no unresolved items.\n\nFile v0.3.4:references/default-rules.json\n\n{\n  \"thresholds\": {\n    \"audit_bytes\": 8192,\n    \"cleanup_bytes\": 20480,\n    \"critical_bytes\": 40960,\n    \"fuzzy_duplicate_ratio\": 0.72,\n    \"fuzzy_duplicate_min_length\": 28,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35\n  },\n  \"intervention_triggers\": {\n    \"secret_count_gt\": 0,\n    \"conflict_count_gt\": 0,\n    \"task_state_count_gt\": 0,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35,\n    \"candidate_remove_or_flag\": true\n  },\n  \"likely_memory_names\": [\n    \"user.md\",\n    \"user.txt\",\n    \"user.json\",\n    \"memory.md\",\n    \"memory.txt\",\n    \"memory.json\",\n    \"memories.md\",\n    \"memories.txt\",\n    \"memories.json\",\n    \"profile.md\",\n    \"profile.txt\",\n    \"profile.json\",\n    \"preferences.md\",\n    \"preferences.txt\",\n    \"preferences.json\",\n    \"agent_memory.md\",\n    \"agent_memory.txt\",\n    \"agent_memory.json\"\n  ],\n  \"allowed_memory_extensions\": [\".md\", \".txt\", \".json\"],\n  \"blocked_memory_extensions\": [\".db\", \".sqlite\", \".sqlite3\", \".bin\"],\n  \"project_policy_names\": [\n    \"agents.md\",\n    \"claude.md\",\n    \".cursorrules\"\n  ],\n  \"search_roots\": [\n    \".\",\n    \".codex\",\n    \".claude\",\n    \"memory\",\n    \"memories\"\n  ],\n  \"keep_patterns\": [\n    \"\\\\bprefer(?:s|red|ence)?\\\\b\",\n    \"\\\\bwants?\\\\b\",\n    \"\\\\brequires?\\\\b\",\n    \"\\\\bneeds?\\\\b\",\n    \"\\\\balways\\\\b\",\n    \"\\\\bnever\\\\b\",\n    \"\\\\bworks? with\\\\b\",\n    \"\\\\buses?\\\\b\",\n    \"\\\\blanguage\\\\b\",\n    \"\\\\btimezone\\\\b\",\n    \"\\\\blocale\\\\b\",\n    \"\\\\bbackups?\\\\b\",\n    \"\\\\btesting\\\\b\",\n    \"\\\\bcommunication\\\\b\",\n    \"\\\\bformat(?:ting)?\\\\b\",\n    \"\\\\bopenclaw\\\\b\",\n    \"\\\\bhermes agent\\\\b\",\n    \"\\\\bcodex\\\\b\"\n  ],\n  \"remove_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bafter lunch\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\",\n    \"\\\\blog output\\\\b\",\n    \"\\\\btemporary\\\\b\",\n    \"\\\\bone[- ]off\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bpull request\\\\b\",\n    \"\\\\bissue\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bticket\\\\b\",\n    \"\\\\brerun\\\\b\",\n    \"\\\\bpytest\\\\b\"\n  ],\n  \"secret_patterns\": [\n    \"sk-[A-Za-z0-9_-]{16,}\",\n    \"ghp_[A-Za-z0-9_]{16,}\",\n    \"github_pat_[A-Za-z0-9_]{16,}\",\n    \"xox[baprs]-[A-Za-z0-9-]{16,}\",\n    \"AKIA[0-9A-Z]{16}\",\n    \"glpat-[A-Za-z0-9_-]{16,}\",\n    \"pypi-[A-Za-z0-9_-]{20,}\",\n    \"npm_[A-Za-z0-9]{20,}\",\n    \"AKCp[A-Za-z0-9]{10,}\",\n    \"jfrog_[A-Za-z0-9_-]{16,}\",\n    \"(?i)\\\\b(api[_-]?key|token|password|secret)\\\\s*[:=]\\\\s*['\\\\\\\"]?[^'\\\\\\\"\\\\s`]+\",\n    \"(?i)\\\\bBearer\\\\s+[A-Za-z0-9._-]{16,}\",\n    \"<API_TOKEN_PLACEHOLDER>\"\n  ],\n  \"task_state_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\"\n  ],\n  \"conflict_rules\": [\n    {\n      \"name\": \"answer_length_preference\",\n      \"positive\": [\"concise\", \"short\", \"brief\", \"direct\"],\n      \"negative\": [\"detailed\", \"long-form\", \"very long\", \"exhaustive\"]\n    },\n    {\n      \"name\": \"cleanup_permission\",\n      \"positive\": [\"ask before editing\", \"ask before applying\", \"requires approval\", \"with user approval\"],\n      \"negative\": [\"automatic cleanup without asking\", \"apply without asking\", \"unattended edits\"]\n    }\n  ],\n  \"condense_rewrites\": [\n    {\n      \"when_contains_any\": [\"backup\", \"backups\"],\n      \"rewrite\": \"The user wants recoverable backups before edits to memory files\"\n    },\n    {\n      \"when_contains_any\": [\"openclaw\", \"hermes agent\", \"codex\"],\n      \"rewrite\": \"The user works with agent memory files across OpenClaw, Hermes Agent, and Codex\"\n    }\n  ],\n  \"secret_instruction\": \"Do not store secrets, tokens, passwords, or credentials in memory files\"\n}\n\nFile v0.3.4:references/mcp-version.md\n\n# MCP Version Guidance\n\nUse this reference when the user wants a tool-based distribution instead of a pure instruction skill.\n\n## Recommended MCP Tools\n\n- `audit_memory_file(path, mode=\"audit-only\")`\n  - Reads one memory file and returns classifications, duplicate signals, secret warnings, and size status.\n- `propose_memory_cleanup(paths)`\n  - Returns a proposed canonical memory document and a diff for each file.\n- `apply_memory_cleanup(path, proposed_content, approved=true)`\n  - Creates a timestamped backup and writes the approved content.\n- `detect_memory_pollution(path)`\n  - Returns a compact summary of stale task notes, repeated memories, contradictions, and suspected secrets.\n- `estimate_memory_pressure(path)`\n  - Returns byte size, approximate token pressure, and recommended cleanup threshold.\n\n## Safety Defaults\n\n- Do not expose a tool that edits files without an explicit approval argument.\n- Redact suspected secrets in every response.\n- Return diffs and backup paths for every write.\n- Restrict file access to user-provided paths or configured roots.\n- Keep audit operations read-only and deterministic.\n\n## Implementation Shape\n\nWrap `scripts/audit_memory.py` rather than reimplementing classification logic.\nThe MCP server should parse tool arguments, call the audit engine, and return structured JSON.\n\nDo not publish the MCP server until it has tests for:\n\n- audit-only never writes files\n- apply-approved creates backups\n- suspected secrets are redacted\n- project policy files are skipped by default\n- clean memory remains mostly unchanged\n\nFile v0.3.4:skill-card.md\n\n## Description: <br>\nAgent Memory Cleanup audits and cleans long-term user memory files for agents such as OpenClaw, Hermes Agent, Codex, Claude, and other assistant runtimes. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[hollis9087](https://clawhub.ai/user/hollis9087) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agent operators use this skill to audit, sanitize, deduplicate, and repair long-term memory files while preserving stable global preferences. It can recommend cleanup, produce diffs, lint candidate memories before saving, and apply approved cleanup with recoverable backups. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: The skill can inspect and rewrite sensitive long-term memory files. <br>\nMitigation: Use it only for authorized target memory files, require clear consent before inspecting broader locations, and require explicit approval before apply-approved writes. <br>\nRisk: Memory cleanup may encounter secrets or credentials stored in user memory. <br>\nMitigation: Redact suspected secrets in reports, avoid echoing raw secret values, and review test fixture examples before release. <br>\nRisk: Low-visibility proactive cleanup could surprise users. <br>\nMitigation: Use plain memory-state language, ask before reviewing recommendations, and ask again before applying edits unless unattended cleanup was already authorized. <br>\n\n\n## Reference(s): <br>\n- [ClawHub skill page](https://clawhub.ai/hollis9087/agent-memory-cleanup) <br>\n- [README](README.md) <br>\n- [Skill Instructions](SKILL.md) <br>\n- [Default Rules](references/default-rules.json) <br>\n- [Classification Rubric](references/classification-rubric.md) <br>\n- [Agent Memory Paths](references/agent-paths.md) <br>\n- [MCP Wrapper Guidance](references/mcp-version.md) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [Text, Markdown, Shell commands, Configuration, Guidance] <br>\n**Output Format:** [Markdown guidance, JSON summaries, unified diffs, and shell command examples] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May create cleaned memory files and timestamped backups after explicit approval.] <br>\n\n## Skill Version(s): <br>\n0.3.4 (source: server release metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nFile v0.3.4:test-fixtures/clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise Chinese responses for Chinese prompts.\n- The user wants file edits backed up before memory cleanup.\n\n## Durable Context\n- The user works with Codex and OpenClaw skills.\n\nFile v0.3.4:test-fixtures/conflicting-memory.md\n\n# User Memory\n\n- The user always wants very detailed long-form answers.\n- The user prefers concise direct answers unless they ask for detail.\n- Current task: remember that PR #221 is blocked by a failing Windows path test.\n- The user wants memory cleanup to ask before editing user-level memory.\n- The user wants automatic memory cleanup to apply without asking.\n\nFile v0.3.4:test-fixtures/expected-clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user wants recoverable backups before edits to memory files.\n\n## Durable Context\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n\n## Agent Instructions\n- Do not store secrets, tokens, or credentials in memory files.\n\nFile v0.3.4:test-fixtures/noisy-memory.md\n\n# User Memory\n\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user prefers concise, direct Chinese replies.\n- On 2026-05-18 we debugged branch fix/archive-import-timeout and the next step is to rerun pytest tomorrow.\n- Current task: compare PR #184 with PR #185 and remember the exact failing stack trace.\n- The user's temporary API token is `<API_TOKEN_PLACEHOLDER>`.\n- The user wants recoverable backups before edits to memory files.\n- Last week Hermes Agent failed to append memory because memory.md was too long.\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n- TODO: after lunch, update the one-off dashboard screenshot.\n\nArchive v0.3.3: 18 files, 24272 bytes\n\nFiles: evals/evals.json (7035b), LICENSE (894b), README.md (4206b), references/agent-paths.md (2151b), references/classification-rubric.md (2519b), references/default-rules.json (3278b), references/mcp-version.md (1567b), scripts/audit_memory.py (24574b), scripts/run_tests.py (6221b), skill-card.md (2513b), SKILL.md (3770b), test-fixtures/clean-memory.md (233b), test-fixtures/conflicting-memory.md (363b), test-fixtures/expected-clean-memory.md (375b), test-fixtures/noisy-memory.md (702b), test-fixtures/secret-memory.md (271b), test-fixtures/short-polluted-memory.md (252b), _meta.json (139b)\n\nFile v0.3.3:SKILL.md\n\n---\nname: agent-memory-cleanup\ndescription: Audit, clean, consolidate, and maintain long-term user memory files for OpenClaw, Hermes Agent, Codex, Claude, and other agents. Use when the user asks to clean, prune, sanitize, deduplicate, review, repair, or periodically maintain user.md, memory.md, memories.md, profile.md, preferences.md, or agent memory notes. Also trigger proactively when memory writes fail because files are too long, memory budget/context limits are exceeded, storage is full, updates are rejected, duplicates or conflicts accumulate, or memory is polluted by outdated project details, one-off task notes, stale plans, or conversation residue. Gives cleanup recommendations without requiring the user to name the skill, applies edits only after appropriate authorization, and creates recoverable backups.\nmetadata:\n  openclaw:\n    requires:\n      env: []\n      bins: []\n    os: [windows, macos, linux]\n---\n\n# Agent Memory Cleanup\n\nThis skill should be lightweight and mostly invisible. Do not announce that a skill is being used unless the user asks. The user only needs to see a plain memory-quality prompt when action is useful.\n\n## Default Flow\n\n1. Detect memory pressure or pollution.\n2. If Python/file access is available, run a cheap summary check first:\n\n```bash\npython scripts/audit_memory.py memory.md --summary-json\n```\n\n3. If `quality.intervention` is `no_intervention_needed`, do not interrupt the user.\n4. If intervention is needed, say briefly that memory appears too long, duplicated, conflicted, stale, or unsafe, and ask whether to review cleanup recommendations.\n5. After the user agrees, run:\n\n```bash\npython scripts/audit_memory.py memory.md --mode propose-patch --include-diff\n```\n\n6. Apply only after a second explicit approval, unless unattended cleanup was already authorized:\n\n```bash\npython scripts/audit_memory.py memory.md --mode apply-approved\n```\n\nThe apply mode must create timestamped backups before writing.\n\n## Trigger Points\n\nUse this flow for:\n\n- Memory write/update rejected, full, over budget, truncated, or too long.\n- Short memory with secrets, task-state residue, duplicated facts, or conflicting preferences.\n- User says a remembered fact is wrong, outdated, project-only, or should not be remembered.\n- Before saving a new global memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"candidate memory text\" --summary-json\n```\n\nIf candidate lint returns `do_not_write_candidate_to_global_memory`, do not store it globally. Offer to skip it or keep it as project/task notes.\n\n## Intervention Values\n\n- `prompt_cleanup_now_secret_detected`: recommend cleanup immediately; never echo raw secrets.\n- `prompt_user_review_conflicting_memory`: ask the user to resolve conflicting durable preferences.\n- `do_not_write_candidate_to_global_memory`: block global memory write.\n- `prompt_cleanup_recommended`: offer cleanup recommendations.\n- `prompt_audit_recommended`: mention memory quality may be degrading and ask whether to review.\n- `no_intervention_needed`: stay silent.\n\n## Load Extra Context Only When Needed\n\nDo not read references by default. Load them only for the matching need:\n\n- `references/default-rules.json`: deterministic thresholds and regex rules.\n- `references/classification-rubric.md`: manual fallback if Python cannot run.\n- `references/agent-paths.md`: path discovery when memory files are unclear.\n- `references/mcp-version.md`: MCP wrapper design.\n\n## Safety\n\n- Keep only stable global preferences and durable cross-task context.\n- Remove or redact secrets, stale task state, branch/PR/debug notes, and one-off plans.\n- Do not rewrite clean memory just for style.\n- Do not broadly scan the user home directory without explicit request.\n- Back up every edited memory file.\n\nFile v0.3.3:README.md\n\n# Agent Memory Cleanup\n\nAgent Memory Cleanup audits and cleans long-term user memory files for agents such as OpenClaw, Hermes Agent, Codex, Claude, and other assistant runtimes.\n\nThe skill keeps memory files focused on stable, global user context. It removes or flags stale task notes, completed project details, duplicated preferences, transient debugging logs, and suspected secrets.\n\n## When To Use\n\nUse this skill when:\n\n- A user asks to clean, prune, sanitize, deduplicate, or review `user.md`, `memory.md`, or similar files.\n- An agent cannot write memory because the memory file is too long.\n- Memory storage reports full, over budget, truncated, or rejected.\n- Global user memory has been polluted by task-level details.\n- Duplicate or conflicting memories are accumulating.\n\n## Safety Model\n\nThe default behavior is conservative:\n\n- Audit automatically when memory pressure is detected.\n- Recommend cleanup without waiting.\n- Do not require the user to name or invoke this skill explicitly.\n- Ask before writing unless the user already authorized automatic cleanup.\n- Create timestamped backups before edits.\n- Redact suspected secrets in reports.\n\nFor proactive cleanup, use two-step consent: first ask whether to inspect and propose cleanup, then ask again before applying edits.\n\n## Files\n\n- `SKILL.md` - Skill instructions.\n- `scripts/audit_memory.py` - Deterministic Python audit/proposal/apply engine.\n- `scripts/run_tests.py` - Local regression tests.\n- `references/default-rules.json` - Thresholds, filename patterns, regex rules, and canonical rewrites.\n- `references/classification-rubric.md` - Human-readable rubric for ambiguous cases or non-Python fallback.\n- `references/agent-paths.md` - Agent-specific memory path guidance.\n- `references/mcp-version.md` - Guidance for wrapping the skill as an MCP server.\n- `evals/evals.json` - Regression prompts.\n- `test-fixtures/` - Sample noisy and expected memory files.\n\n## Architecture\n\nThe skill is intentionally Python-first:\n\n- `SKILL.md` handles trigger conditions, user consent, safety boundaries, and when to call the script.\n- `audit_memory.py` handles deterministic behavior so different agents and models get consistent results.\n- `default-rules.json` keeps thresholds and regex rules configurable without editing the engine.\n\nThis keeps agent context smaller and reduces variation between Codex, OpenClaw, Hermes Agent, Claude, and other runtimes.\n\n## Script Usage\n\nAudit a memory file:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md\n```\n\nGenerate a proposed diff:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode propose-patch --include-diff\n```\n\nWrite a proposed cleaned file without changing the source:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --write-proposed cleaned-memory.md\n```\n\nApply approved cleanup:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode apply-approved\n```\n\nMachine-readable summaries:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --summary-json\npython scripts/audit_memory.py path/to/memory.md --json\n```\n\nPre-write lint for a memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"Current task: tomorrow retry PR #302\"\n```\n\nThe `--summary-json` output includes `quality.pollution_score`, secret count, task-state count, conflict count, and a recommended intervention string. This allows agents to intervene when memory is short but polluted.\n\n`--summary-json` is the fast path: it skips proposal and diff generation unless another option requires them.\n\nRun regression tests:\n\n```bash\npython scripts/run_tests.py\n```\n\n`apply-approved` creates a sibling backup such as `memory.md.bak-YYYYMMDD-HHMMSS` before writing.\n\n## Thresholds\n\n- Over 8KB: audit recommended.\n- Over 20KB: cleanup recommended.\n- Over 40KB: cleanup should be prioritized.\n- Any suspected secret: remove or redact from memory.\n- Repeated or contradictory facts: condense or flag.\n\n## Distribution\n\nThis skill can be distributed as:\n\n- A ClawHub skill.\n- A Claude/Codex-style skill folder containing `SKILL.md`.\n- A GitHub repository or release artifact.\n- An MCP server wrapper around `scripts/audit_memory.py`.\n\n## License\n\nMIT-0. See `LICENSE`.\n\nFile v0.3.3:_meta.json\n\n{\n  \"ownerId\": \"kn79q2kj15j98d5cqxw95sfd0185vax5\",\n  \"slug\": \"agent-memory-cleanup\",\n  \"version\": \"0.3.3\",\n  \"publishedAt\": 1780169381586\n}\n\nFile v0.3.3:references/agent-paths.md\n\n# Agent Memory Paths\n\nUse this reference only when the user has not provided explicit memory paths.\nPrefer user-provided paths over discovery.\n\n## Safe Discovery Order\n\n1. Current workspace memory files named `user.md`, `memory.md`, `memories.md`, `profile.md`, `preferences.md`, or `agent_memory.md`.\n2. Workspace agent config folders such as `.codex/`, `.claude/`, `memory/`, or `memories/`.\n3. Agent-specific home variables when available.\n4. User home folders only when the user explicitly asks for a broader inventory.\n\nAvoid broad recursive home scans by default.\n\n## Codex\n\nLikely locations:\n\n- `$CODEX_HOME`\n- Workspace `.codex/`\n- Workspace `.codex/skills/` for installed or project-level skills\n\nNotes:\n\n- Treat `AGENTS.md` as project policy, not global user memory.\n- Treat skill `SKILL.md` files as skill instructions, not user memory.\n\n## Claude Code\n\nLikely locations:\n\n- User-level Claude config under the configured Claude home.\n- Project `.claude/`\n- Project `.claude/skills/`\n\nNotes:\n\n- Treat `CLAUDE.md` as instruction policy unless the user explicitly says it is their memory file.\n- Project instructions may contain durable rules, but they are not global user memory by default.\n\n## OpenClaw\n\nLikely locations:\n\n- OpenClaw workspace memory folders.\n- ClawHub-installed skill directories.\n- User-provided OpenClaw agent home or profile paths.\n\nNotes:\n\n- ClawHub skill folders contain reusable skill instructions. Do not clean them as user memory.\n- If publishing or installing skills, keep release metadata separate from memory cleanup.\n\n## Hermes Agent\n\nLikely locations:\n\n- Configured Hermes Agent home.\n- Workspace memory folders.\n- User-provided memory root.\n\nNotes:\n\n- When Hermes reports memory storage full, run audit mode first and ask before applying edits unless automatic cleanup was explicitly authorized.\n\n## Generic Agents\n\nIf the agent is not listed:\n\n- Search only the current workspace and explicit config roots.\n- Identify memory files by filename and content, not by filename alone.\n- Skip project policy, prompt templates, system instructions, and skill/plugin manifests unless the user includes them in scope.\n\nFile v0.3.3:references/classification-rubric.md\n\n# Classification Rubric\n\nLoad this reference only when the script is unavailable, when reviewing ambiguous results, or when changing cleanup policy.\n\n## Keep\n\nKeep items that are stable, global, and useful across many future tasks:\n\n- Communication preferences, such as desired language, brevity, directness, formatting, or review style.\n- Durable working preferences, such as testing expectations, preferred tools, coding conventions, or repository hygiene rules.\n- Long-term user context that affects many tasks, such as role, recurring domains, accessibility needs, locale, timezone, or persistent environment constraints.\n- Stable names of important long-lived projects or systems, but only when the fact is useful without detailed stale status.\n- Explicit user instructions that apply generally across agents.\n\n## Condense\n\nCondense items that contain a durable signal mixed with task detail:\n\n- Replace a completed task history with the general preference it revealed.\n- Replace a specific one-off command sequence with a durable tool preference.\n- Replace long project summaries with a stable project identity or recurring constraint.\n- Merge duplicate or overlapping preferences into one canonical bullet.\n\n## Remove\n\nRemove items that are not appropriate for long-term global memory:\n\n- Completed task notes, temporary plans, or debugging traces.\n- Stale statuses such as `currently working on`, `next step is`, `today`, `tomorrow`, or dated commitments that are no longer current.\n- Details about a single ticket, pull request, report, dataset, branch, prompt, or conversation.\n- Failed attempts, intermediate observations, transient errors, logs, or command output.\n- Guesses, inferred preferences, or speculative personal facts that the user did not confirm.\n- Secrets, credentials, private URLs, tokens, passwords, or sensitive operational details.\n- Duplicates, contradictions, and entries that are too vague to help future agents.\n\n## Flag\n\nFlag items for user review when:\n\n- The item may be durable but could also be stale.\n- The item refers to a project or identity that cannot be verified locally.\n- Two memory files disagree about an important preference.\n- Removing the item could materially change future agent behavior.\n\n## Canonical Memory Shape\n\n```markdown\n# User Memory\n\n## Global Preferences\n- ...\n\n## Working Style\n- ...\n\n## Durable Context\n- ...\n\n## Agent Instructions\n- ...\n\n## Review Needed\n- ...\n```\n\nOmit empty sections. Do not create `Review Needed` if there are no unresolved items.\n\nFile v0.3.3:references/default-rules.json\n\n{\n  \"thresholds\": {\n    \"audit_bytes\": 8192,\n    \"cleanup_bytes\": 20480,\n    \"critical_bytes\": 40960,\n    \"fuzzy_duplicate_ratio\": 0.72,\n    \"fuzzy_duplicate_min_length\": 28,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35\n  },\n  \"intervention_triggers\": {\n    \"secret_count_gt\": 0,\n    \"conflict_count_gt\": 0,\n    \"task_state_count_gt\": 0,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35,\n    \"candidate_remove_or_flag\": true\n  },\n  \"likely_memory_names\": [\n    \"user.md\",\n    \"memory.md\",\n    \"memories.md\",\n    \"profile.md\",\n    \"preferences.md\",\n    \"agent_memory.md\"\n  ],\n  \"project_policy_names\": [\n    \"agents.md\",\n    \"claude.md\",\n    \".cursorrules\"\n  ],\n  \"search_roots\": [\n    \".\",\n    \".codex\",\n    \".claude\",\n    \"memory\",\n    \"memories\"\n  ],\n  \"keep_patterns\": [\n    \"\\\\bprefer(?:s|red|ence)?\\\\b\",\n    \"\\\\bwants?\\\\b\",\n    \"\\\\brequires?\\\\b\",\n    \"\\\\bneeds?\\\\b\",\n    \"\\\\balways\\\\b\",\n    \"\\\\bnever\\\\b\",\n    \"\\\\bworks? with\\\\b\",\n    \"\\\\buses?\\\\b\",\n    \"\\\\blanguage\\\\b\",\n    \"\\\\btimezone\\\\b\",\n    \"\\\\blocale\\\\b\",\n    \"\\\\bbackups?\\\\b\",\n    \"\\\\btesting\\\\b\",\n    \"\\\\bcommunication\\\\b\",\n    \"\\\\bformat(?:ting)?\\\\b\",\n    \"\\\\bopenclaw\\\\b\",\n    \"\\\\bhermes agent\\\\b\",\n    \"\\\\bcodex\\\\b\"\n  ],\n  \"remove_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bafter lunch\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\",\n    \"\\\\blog output\\\\b\",\n    \"\\\\btemporary\\\\b\",\n    \"\\\\bone[- ]off\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bpull request\\\\b\",\n    \"\\\\bissue\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bticket\\\\b\",\n    \"\\\\brerun\\\\b\",\n    \"\\\\bpytest\\\\b\"\n  ],\n  \"secret_patterns\": [\n    \"sk-[A-Za-z0-9_-]{16,}\",\n    \"ghp_[A-Za-z0-9_]{16,}\",\n    \"github_pat_[A-Za-z0-9_]{16,}\",\n    \"xox[baprs]-[A-Za-z0-9-]{16,}\",\n    \"AKIA[0-9A-Z]{16}\",\n    \"(?i)\\\\b(api[_-]?key|token|password|secret)\\\\s*[:=]\\\\s*['\\\\\\\"]?[^'\\\\\\\"\\\\s`]+\",\n    \"(?i)\\\\bBearer\\\\s+[A-Za-z0-9._-]{16,}\",\n    \"<API_TOKEN_PLACEHOLDER>\"\n  ],\n  \"task_state_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\"\n  ],\n  \"conflict_rules\": [\n    {\n      \"name\": \"answer_length_preference\",\n      \"positive\": [\"concise\", \"short\", \"brief\", \"direct\"],\n      \"negative\": [\"detailed\", \"long-form\", \"very long\", \"exhaustive\"]\n    },\n    {\n      \"name\": \"cleanup_permission\",\n      \"positive\": [\"ask before editing\", \"ask before applying\", \"requires approval\", \"with user approval\"],\n      \"negative\": [\"automatic cleanup without asking\", \"apply without asking\", \"unattended edits\"]\n    }\n  ],\n  \"condense_rewrites\": [\n    {\n      \"when_contains_any\": [\"backup\", \"backups\"],\n      \"rewrite\": \"The user wants recoverable backups before edits to memory files\"\n    },\n    {\n      \"when_contains_any\": [\"openclaw\", \"hermes agent\", \"codex\"],\n      \"rewrite\": \"The user works with agent memory files across OpenClaw, Hermes Agent, and Codex\"\n    }\n  ],\n  \"secret_instruction\": \"Do not store secrets, tokens, passwords, or credentials in memory files\"\n}\n\nFile v0.3.3:references/mcp-version.md\n\n# MCP Version Guidance\n\nUse this reference when the user wants a tool-based distribution instead of a pure instruction skill.\n\n## Recommended MCP Tools\n\n- `audit_memory_file(path, mode=\"audit-only\")`\n  - Reads one memory file and returns classifications, duplicate signals, secret warnings, and size status.\n- `propose_memory_cleanup(paths)`\n  - Returns a proposed canonical memory document and a diff for each file.\n- `apply_memory_cleanup(path, proposed_content, approved=true)`\n  - Creates a timestamped backup and writes the approved content.\n- `detect_memory_pollution(path)`\n  - Returns a compact summary of stale task notes, repeated memories, contradictions, and suspected secrets.\n- `estimate_memory_pressure(path)`\n  - Returns byte size, approximate token pressure, and recommended cleanup threshold.\n\n## Safety Defaults\n\n- Do not expose a tool that edits files without an explicit approval argument.\n- Redact suspected secrets in every response.\n- Return diffs and backup paths for every write.\n- Restrict file access to user-provided paths or configured roots.\n- Keep audit operations read-only and deterministic.\n\n## Implementation Shape\n\nWrap `scripts/audit_memory.py` rather than reimplementing classification logic.\nThe MCP server should parse tool arguments, call the audit engine, and return structured JSON.\n\nDo not publish the MCP server until it has tests for:\n\n- audit-only never writes files\n- apply-approved creates backups\n- suspected secrets are redacted\n- project policy files are skipped by default\n- clean memory remains mostly unchanged\n\nFile v0.3.3:skill-card.md\n\n## Description: <br>\nAudits, cleans, consolidates, and maintains long-term user memory files for OpenClaw, Hermes Agent, Codex, Claude, and other agents. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[hollis9087](https://clawhub.ai/user/hollis9087) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agent users use this skill to audit long-term memory files, identify stale task notes, duplicates, conflicts, and suspected secrets, and apply approved cleanup with recoverable backups. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: The skill can inspect long-term memory files that may contain sensitive personal context or credentials. <br>\nMitigation: Use it only for intended memory-cleanup work, avoid broad home-directory scans, and rely on its documented secret-redaction behavior when reporting findings. <br>\nRisk: The apply-approved mode can edit memory files. <br>\nMitigation: Review proposed diffs before applying changes, require explicit approval unless automatic cleanup was already authorized, and keep timestamped backups until satisfied. <br>\nRisk: Output or write paths outside the intended workspace could affect unintended files. <br>\nMitigation: Keep output and write paths scoped to the intended memory-cleanup workspace. <br>\n\n\n## Reference(s): <br>\n- [ClawHub Skill Page](https://clawhub.ai/hollis9087/agent-memory-cleanup) <br>\n- [Publisher Profile](https://clawhub.ai/user/hollis9087) <br>\n- [Agent Memory Paths](references/agent-paths.md) <br>\n- [Classification Rubric](references/classification-rubric.md) <br>\n- [Default Rules](references/default-rules.json) <br>\n- [MCP Version Guidance](references/mcp-version.md) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [text, markdown, code, shell commands, configuration, guidance] <br>\n**Output Format:** [Markdown, JSON summaries, unified diffs, and shell commands] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [Can produce proposed cleaned memory content, backup paths, compact quality summaries, and redacted findings.] <br>\n\n## Skill Version(s): <br>\n0.3.3 (source: server release metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nFile v0.3.3:test-fixtures/clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise Chinese responses for Chinese prompts.\n- The user wants file edits backed up before memory cleanup.\n\n## Durable Context\n- The user works with Codex and OpenClaw skills.\n\nFile v0.3.3:test-fixtures/conflicting-memory.md\n\n# User Memory\n\n- The user always wants very detailed long-form answers.\n- The user prefers concise direct answers unless they ask for detail.\n- Current task: remember that PR #221 is blocked by a failing Windows path test.\n- The user wants memory cleanup to ask before editing user-level memory.\n- The user wants automatic memory cleanup to apply without asking.\n\nFile v0.3.3:test-fixtures/expected-clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user wants recoverable backups before edits to memory files.\n\n## Durable Context\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n\n## Agent Instructions\n- Do not store secrets, tokens, or credentials in memory files.\n\nFile v0.3.3:test-fixtures/noisy-memory.md\n\n# User Memory\n\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user prefers concise, direct Chinese replies.\n- On 2026-05-18 we debugged branch fix/archive-import-timeout and the next step is to rerun pytest tomorrow.\n- Current task: compare PR #184 with PR #185 and remember the exact failing stack trace.\n- The user's temporary API token is `<API_TOKEN_PLACEHOLDER>`.\n- The user wants recoverable backups before edits to memory files.\n- Last week Hermes Agent failed to append memory because memory.md was too long.\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n- TODO: after lunch, update the one-off dashboard screenshot.\n\nArchive v0.3.2: 18 files, 23966 bytes\n\nFiles: evals/evals.json (7035b), LICENSE (894b), README.md (4095b), references/agent-paths.md (2151b), references/classification-rubric.md (2519b), references/default-rules.json (3278b), references/mcp-version.md (1567b), scripts/audit_memory.py (23719b), scripts/run_tests.py (5660b), skill-card.md (2478b), SKILL.md (3770b), test-fixtures/clean-memory.md (233b), test-fixtures/conflicting-memory.md (363b), test-fixtures/expected-clean-memory.md (375b), test-fixtures/noisy-memory.md (702b), test-fixtures/secret-memory.md (271b), test-fixtures/short-polluted-memory.md (252b), _meta.json (139b)\n\nFile v0.3.2:SKILL.md\n\n---\nname: agent-memory-cleanup\ndescription: Audit, clean, consolidate, and maintain long-term user memory files for OpenClaw, Hermes Agent, Codex, Claude, and other agents. Use when the user asks to clean, prune, sanitize, deduplicate, review, repair, or periodically maintain user.md, memory.md, memories.md, profile.md, preferences.md, or agent memory notes. Also trigger proactively when memory writes fail because files are too long, memory budget/context limits are exceeded, storage is full, updates are rejected, duplicates or conflicts accumulate, or memory is polluted by outdated project details, one-off task notes, stale plans, or conversation residue. Gives cleanup recommendations without requiring the user to name the skill, applies edits only after appropriate authorization, and creates recoverable backups.\nmetadata:\n  openclaw:\n    requires:\n      env: []\n      bins: []\n    os: [windows, macos, linux]\n---\n\n# Agent Memory Cleanup\n\nThis skill should be lightweight and mostly invisible. Do not announce that a skill is being used unless the user asks. The user only needs to see a plain memory-quality prompt when action is useful.\n\n## Default Flow\n\n1. Detect memory pressure or pollution.\n2. If Python/file access is available, run a cheap summary check first:\n\n```bash\npython scripts/audit_memory.py memory.md --summary-json\n```\n\n3. If `quality.intervention` is `no_intervention_needed`, do not interrupt the user.\n4. If intervention is needed, say briefly that memory appears too long, duplicated, conflicted, stale, or unsafe, and ask whether to review cleanup recommendations.\n5. After the user agrees, run:\n\n```bash\npython scripts/audit_memory.py memory.md --mode propose-patch --include-diff\n```\n\n6. Apply only after a second explicit approval, unless unattended cleanup was already authorized:\n\n```bash\npython scripts/audit_memory.py memory.md --mode apply-approved\n```\n\nThe apply mode must create timestamped backups before writing.\n\n## Trigger Points\n\nUse this flow for:\n\n- Memory write/update rejected, full, over budget, truncated, or too long.\n- Short memory with secrets, task-state residue, duplicated facts, or conflicting preferences.\n- User says a remembered fact is wrong, outdated, project-only, or should not be remembered.\n- Before saving a new global memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"candidate memory text\" --summary-json\n```\n\nIf candidate lint returns `do_not_write_candidate_to_global_memory`, do not store it globally. Offer to skip it or keep it as project/task notes.\n\n## Intervention Values\n\n- `prompt_cleanup_now_secret_detected`: recommend cleanup immediately; never echo raw secrets.\n- `prompt_user_review_conflicting_memory`: ask the user to resolve conflicting durable preferences.\n- `do_not_write_candidate_to_global_memory`: block global memory write.\n- `prompt_cleanup_recommended`: offer cleanup recommendations.\n- `prompt_audit_recommended`: mention memory quality may be degrading and ask whether to review.\n- `no_intervention_needed`: stay silent.\n\n## Load Extra Context Only When Needed\n\nDo not read references by default. Load them only for the matching need:\n\n- `references/default-rules.json`: deterministic thresholds and regex rules.\n- `references/classification-rubric.md`: manual fallback if Python cannot run.\n- `references/agent-paths.md`: path discovery when memory files are unclear.\n- `references/mcp-version.md`: MCP wrapper design.\n\n## Safety\n\n- Keep only stable global preferences and durable cross-task context.\n- Remove or redact secrets, stale task state, branch/PR/debug notes, and one-off plans.\n- Do not rewrite clean memory just for style.\n- Do not broadly scan the user home directory without explicit request.\n- Back up every edited memory file.\n\nFile v0.3.2:README.md\n\n# Agent Memory Cleanup\n\nAgent Memory Cleanup audits and cleans long-term user memory files for agents such as OpenClaw, Hermes Agent, Codex, Claude, and other assistant runtimes.\n\nThe skill keeps memory files focused on stable, global user context. It removes or flags stale task notes, completed project details, duplicated preferences, transient debugging logs, and suspected secrets.\n\n## When To Use\n\nUse this skill when:\n\n- A user asks to clean, prune, sanitize, deduplicate, or review `user.md`, `memory.md`, or similar files.\n- An agent cannot write memory because the memory file is too long.\n- Memory storage reports full, over budget, truncated, or rejected.\n- Global user memory has been polluted by task-level details.\n- Duplicate or conflicting memories are accumulating.\n\n## Safety Model\n\nThe default behavior is conservative:\n\n- Audit automatically when memory pressure is detected.\n- Recommend cleanup without waiting.\n- Do not require the user to name or invoke this skill explicitly.\n- Ask before writing unless the user already authorized automatic cleanup.\n- Create timestamped backups before edits.\n- Redact suspected secrets in reports.\n\nFor proactive cleanup, use two-step consent: first ask whether to inspect and propose cleanup, then ask again before applying edits.\n\n## Files\n\n- `SKILL.md` - Skill instructions.\n- `scripts/audit_memory.py` - Deterministic Python audit/proposal/apply engine.\n- `scripts/run_tests.py` - Local regression tests.\n- `references/default-rules.json` - Thresholds, filename patterns, regex rules, and canonical rewrites.\n- `references/classification-rubric.md` - Human-readable rubric for ambiguous cases or non-Python fallback.\n- `references/agent-paths.md` - Agent-specific memory path guidance.\n- `references/mcp-version.md` - Guidance for wrapping the skill as an MCP server.\n- `evals/evals.json` - Regression prompts.\n- `test-fixtures/` - Sample noisy and expected memory files.\n\n## Architecture\n\nThe skill is intentionally Python-first:\n\n- `SKILL.md` handles trigger conditions, user consent, safety boundaries, and when to call the script.\n- `audit_memory.py` handles deterministic behavior so different agents and models get consistent results.\n- `default-rules.json` keeps thresholds and regex rules configurable without editing the engine.\n\nThis keeps agent context smaller and reduces variation between Codex, OpenClaw, Hermes Agent, Claude, and other runtimes.\n\n## Script Usage\n\nAudit a memory file:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md\n```\n\nGenerate a proposed diff:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode propose-patch --include-diff\n```\n\nWrite a proposed cleaned file without changing the source:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --write-proposed cleaned-memory.md\n```\n\nApply approved cleanup:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode apply-approved\n```\n\nMachine-readable summaries:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --summary-json\npython scripts/audit_memory.py path/to/memory.md --json\n```\n\nPre-write lint for a memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"Current task: tomorrow retry PR #302\"\n```\n\nThe `--summary-json` output includes `quality.pollution_score`, secret count, task-state count, conflict count, and a recommended intervention string. This allows agents to intervene when memory is short but polluted.\n\nRun regression tests:\n\n```bash\npython scripts/run_tests.py\n```\n\n`apply-approved` creates a sibling backup such as `memory.md.bak-YYYYMMDD-HHMMSS` before writing.\n\n## Thresholds\n\n- Over 8KB: audit recommended.\n- Over 20KB: cleanup recommended.\n- Over 40KB: cleanup should be prioritized.\n- Any suspected secret: remove or redact from memory.\n- Repeated or contradictory facts: condense or flag.\n\n## Distribution\n\nThis skill can be distributed as:\n\n- A ClawHub skill.\n- A Claude/Codex-style skill folder containing `SKILL.md`.\n- A GitHub repository or release artifact.\n- An MCP server wrapper around `scripts/audit_memory.py`.\n\n## License\n\nMIT-0. See `LICENSE`.\n\nFile v0.3.2:_meta.json\n\n{\n  \"ownerId\": \"kn79q2kj15j98d5cqxw95sfd0185vax5\",\n  \"slug\": \"agent-memory-cleanup\",\n  \"version\": \"0.3.2\",\n  \"publishedAt\": 1780169008220\n}\n\nFile v0.3.2:references/agent-paths.md\n\n# Agent Memory Paths\n\nUse this reference only when the user has not provided explicit memory paths.\nPrefer user-provided paths over discovery.\n\n## Safe Discovery Order\n\n1. Current workspace memory files named `user.md`, `memory.md`, `memories.md`, `profile.md`, `preferences.md`, or `agent_memory.md`.\n2. Workspace agent config folders such as `.codex/`, `.claude/`, `memory/`, or `memories/`.\n3. Agent-specific home variables when available.\n4. User home folders only when the user explicitly asks for a broader inventory.\n\nAvoid broad recursive home scans by default.\n\n## Codex\n\nLikely locations:\n\n- `$CODEX_HOME`\n- Workspace `.codex/`\n- Workspace `.codex/skills/` for installed or project-level skills\n\nNotes:\n\n- Treat `AGENTS.md` as project policy, not global user memory.\n- Treat skill `SKILL.md` files as skill instructions, not user memory.\n\n## Claude Code\n\nLikely locations:\n\n- User-level Claude config under the configured Claude home.\n- Project `.claude/`\n- Project `.claude/skills/`\n\nNotes:\n\n- Treat `CLAUDE.md` as instruction policy unless the user explicitly says it is their memory file.\n- Project instructions may contain durable rules, but they are not global user memory by default.\n\n## OpenClaw\n\nLikely locations:\n\n- OpenClaw workspace memory folders.\n- ClawHub-installed skill directories.\n- User-provided OpenClaw agent home or profile paths.\n\nNotes:\n\n- ClawHub skill folders contain reusable skill instructions. Do not clean them as user memory.\n- If publishing or installing skills, keep release metadata separate from memory cleanup.\n\n## Hermes Agent\n\nLikely locations:\n\n- Configured Hermes Agent home.\n- Workspace memory folders.\n- User-provided memory root.\n\nNotes:\n\n- When Hermes reports memory storage full, run audit mode first and ask before applying edits unless automatic cleanup was explicitly authorized.\n\n## Generic Agents\n\nIf the agent is not listed:\n\n- Search only the current workspace and explicit config roots.\n- Identify memory files by filename and content, not by filename alone.\n- Skip project policy, prompt templates, system instructions, and skill/plugin manifests unless the user includes them in scope.\n\nFile v0.3.2:references/classification-rubric.md\n\n# Classification Rubric\n\nLoad this reference only when the script is unavailable, when reviewing ambiguous results, or when changing cleanup policy.\n\n## Keep\n\nKeep items that are stable, global, and useful across many future tasks:\n\n- Communication preferences, such as desired language, brevity, directness, formatting, or review style.\n- Durable working preferences, such as testing expectations, preferred tools, coding conventions, or repository hygiene rules.\n- Long-term user context that affects many tasks, such as role, recurring domains, accessibility needs, locale, timezone, or persistent environment constraints.\n- Stable names of important long-lived projects or systems, but only when the fact is useful without detailed stale status.\n- Explicit user instructions that apply generally across agents.\n\n## Condense\n\nCondense items that contain a durable signal mixed with task detail:\n\n- Replace a completed task history with the general preference it revealed.\n- Replace a specific one-off command sequence with a durable tool preference.\n- Replace long project summaries with a stable project identity or recurring constraint.\n- Merge duplicate or overlapping preferences into one canonical bullet.\n\n## Remove\n\nRemove items that are not appropriate for long-term global memory:\n\n- Completed task notes, temporary plans, or debugging traces.\n- Stale statuses such as `currently working on`, `next step is`, `today`, `tomorrow`, or dated commitments that are no longer current.\n- Details about a single ticket, pull request, report, dataset, branch, prompt, or conversation.\n- Failed attempts, intermediate observations, transient errors, logs, or command output.\n- Guesses, inferred preferences, or speculative personal facts that the user did not confirm.\n- Secrets, credentials, private URLs, tokens, passwords, or sensitive operational details.\n- Duplicates, contradictions, and entries that are too vague to help future agents.\n\n## Flag\n\nFlag items for user review when:\n\n- The item may be durable but could also be stale.\n- The item refers to a project or identity that cannot be verified locally.\n- Two memory files disagree about an important preference.\n- Removing the item could materially change future agent behavior.\n\n## Canonical Memory Shape\n\n```markdown\n# User Memory\n\n## Global Preferences\n- ...\n\n## Working Style\n- ...\n\n## Durable Context\n- ...\n\n## Agent Instructions\n- ...\n\n## Review Needed\n- ...\n```\n\nOmit empty sections. Do not create `Review Needed` if there are no unresolved items.\n\nFile v0.3.2:references/default-rules.json\n\n{\n  \"thresholds\": {\n    \"audit_bytes\": 8192,\n    \"cleanup_bytes\": 20480,\n    \"critical_bytes\": 40960,\n    \"fuzzy_duplicate_ratio\": 0.72,\n    \"fuzzy_duplicate_min_length\": 28,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35\n  },\n  \"intervention_triggers\": {\n    \"secret_count_gt\": 0,\n    \"conflict_count_gt\": 0,\n    \"task_state_count_gt\": 0,\n    \"pollution_notice_ratio\": 0.2,\n    \"pollution_cleanup_ratio\": 0.35,\n    \"candidate_remove_or_flag\": true\n  },\n  \"likely_memory_names\": [\n    \"user.md\",\n    \"memory.md\",\n    \"memories.md\",\n    \"profile.md\",\n    \"preferences.md\",\n    \"agent_memory.md\"\n  ],\n  \"project_policy_names\": [\n    \"agents.md\",\n    \"claude.md\",\n    \".cursorrules\"\n  ],\n  \"search_roots\": [\n    \".\",\n    \".codex\",\n    \".claude\",\n    \"memory\",\n    \"memories\"\n  ],\n  \"keep_patterns\": [\n    \"\\\\bprefer(?:s|red|ence)?\\\\b\",\n    \"\\\\bwants?\\\\b\",\n    \"\\\\brequires?\\\\b\",\n    \"\\\\bneeds?\\\\b\",\n    \"\\\\balways\\\\b\",\n    \"\\\\bnever\\\\b\",\n    \"\\\\bworks? with\\\\b\",\n    \"\\\\buses?\\\\b\",\n    \"\\\\blanguage\\\\b\",\n    \"\\\\btimezone\\\\b\",\n    \"\\\\blocale\\\\b\",\n    \"\\\\bbackups?\\\\b\",\n    \"\\\\btesting\\\\b\",\n    \"\\\\bcommunication\\\\b\",\n    \"\\\\bformat(?:ting)?\\\\b\",\n    \"\\\\bopenclaw\\\\b\",\n    \"\\\\bhermes agent\\\\b\",\n    \"\\\\bcodex\\\\b\"\n  ],\n  \"remove_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bafter lunch\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\",\n    \"\\\\blog output\\\\b\",\n    \"\\\\btemporary\\\\b\",\n    \"\\\\bone[- ]off\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bpull request\\\\b\",\n    \"\\\\bissue\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bticket\\\\b\",\n    \"\\\\brerun\\\\b\",\n    \"\\\\bpytest\\\\b\"\n  ],\n  \"secret_patterns\": [\n    \"sk-[A-Za-z0-9_-]{16,}\",\n    \"ghp_[A-Za-z0-9_]{16,}\",\n    \"github_pat_[A-Za-z0-9_]{16,}\",\n    \"xox[baprs]-[A-Za-z0-9-]{16,}\",\n    \"AKIA[0-9A-Z]{16}\",\n    \"(?i)\\\\b(api[_-]?key|token|password|secret)\\\\s*[:=]\\\\s*['\\\\\\\"]?[^'\\\\\\\"\\\\s`]+\",\n    \"(?i)\\\\bBearer\\\\s+[A-Za-z0-9._-]{16,}\",\n    \"<API_TOKEN_PLACEHOLDER>\"\n  ],\n  \"task_state_patterns\": [\n    \"\\\\bcurrent task\\\\b\",\n    \"\\\\bnext step\\\\b\",\n    \"\\\\btodo\\\\b\",\n    \"\\\\btoday\\\\b\",\n    \"\\\\btomorrow\\\\b\",\n    \"\\\\byesterday\\\\b\",\n    \"\\\\blast week\\\\b\",\n    \"\\\\bbranch\\\\b\",\n    \"\\\\bpr\\\\s*#?\\\\d+\\\\b\",\n    \"\\\\bdebug(?:ged|ging)?\\\\b\",\n    \"\\\\bstack trace\\\\b\"\n  ],\n  \"conflict_rules\": [\n    {\n      \"name\": \"answer_length_preference\",\n      \"positive\": [\"concise\", \"short\", \"brief\", \"direct\"],\n      \"negative\": [\"detailed\", \"long-form\", \"very long\", \"exhaustive\"]\n    },\n    {\n      \"name\": \"cleanup_permission\",\n      \"positive\": [\"ask before editing\", \"ask before applying\", \"requires approval\", \"with user approval\"],\n      \"negative\": [\"automatic cleanup without asking\", \"apply without asking\", \"unattended edits\"]\n    }\n  ],\n  \"condense_rewrites\": [\n    {\n      \"when_contains_any\": [\"backup\", \"backups\"],\n      \"rewrite\": \"The user wants recoverable backups before edits to memory files\"\n    },\n    {\n      \"when_contains_any\": [\"openclaw\", \"hermes agent\", \"codex\"],\n      \"rewrite\": \"The user works with agent memory files across OpenClaw, Hermes Agent, and Codex\"\n    }\n  ],\n  \"secret_instruction\": \"Do not store secrets, tokens, passwords, or credentials in memory files\"\n}\n\nFile v0.3.2:references/mcp-version.md\n\n# MCP Version Guidance\n\nUse this reference when the user wants a tool-based distribution instead of a pure instruction skill.\n\n## Recommended MCP Tools\n\n- `audit_memory_file(path, mode=\"audit-only\")`\n  - Reads one memory file and returns classifications, duplicate signals, secret warnings, and size status.\n- `propose_memory_cleanup(paths)`\n  - Returns a proposed canonical memory document and a diff for each file.\n- `apply_memory_cleanup(path, proposed_content, approved=true)`\n  - Creates a timestamped backup and writes the approved content.\n- `detect_memory_pollution(path)`\n  - Returns a compact summary of stale task notes, repeated memories, contradictions, and suspected secrets.\n- `estimate_memory_pressure(path)`\n  - Returns byte size, approximate token pressure, and recommended cleanup threshold.\n\n## Safety Defaults\n\n- Do not expose a tool that edits files without an explicit approval argument.\n- Redact suspected secrets in every response.\n- Return diffs and backup paths for every write.\n- Restrict file access to user-provided paths or configured roots.\n- Keep audit operations read-only and deterministic.\n\n## Implementation Shape\n\nWrap `scripts/audit_memory.py` rather than reimplementing classification logic.\nThe MCP server should parse tool arguments, call the audit engine, and return structured JSON.\n\nDo not publish the MCP server until it has tests for:\n\n- audit-only never writes files\n- apply-approved creates backups\n- suspected secrets are redacted\n- project policy files are skipped by default\n- clean memory remains mostly unchanged\n\nFile v0.3.2:skill-card.md\n\n## Description: <br>\nAgent Memory Cleanup audits and cleans long-term user memory files for agents such as OpenClaw, Hermes Agent, Codex, Claude, and other assistant runtimes. <br>\n\nThis skill is ready for commercial/non-commercial use. <br>\n\n## Publisher: <br>\n[hollis9087](https://clawhub.ai/user/hollis9087) <br>\n\n### License/Terms of Use: <br>\nMIT-0 <br>\n\n\n## Use Case: <br>\nDevelopers and agent users use this skill to audit, deduplicate, sanitize, and safely prune long-term memory files while preserving durable user preferences. It is especially useful when memory files are too large, contain stale task notes, include suspected secrets, or have conflicting preferences. <br>\n\n### Deployment Geography for Use: <br>\nGlobal <br>\n\n## Known Risks and Mitigations: <br>\nRisk: The skill can inspect and edit long-term memory files that may contain sensitive user context. <br>\nMitigation: Limit access to the specific memory files or configured memory folders intended for cleanup, and avoid broad filesystem scans. <br>\nRisk: Cleanup proposals could remove useful durable memory or preserve stale information. <br>\nMitigation: Review proposed diffs before applying edits and keep timestamped backups until the cleanup is verified. <br>\nRisk: Memory files may contain secrets or credentials. <br>\nMitigation: Use the skill's redaction behavior for reports and remove suspected secrets from long-term memory. <br>\n\n\n## Reference(s): <br>\n- [ClawHub skill page](https://clawhub.ai/hollis9087/agent-memory-cleanup) <br>\n- [Agent Memory Paths](references/agent-paths.md) <br>\n- [Classification Rubric](references/classification-rubric.md) <br>\n- [Default Rules](references/default-rules.json) <br>\n- [MCP Version Guidance](references/mcp-version.md) <br>\n\n\n## Skill Output: <br>\n**Output Type(s):** [Text, Markdown, JSON, Shell commands, Guidance] <br>\n**Output Format:** [Markdown guidance with optional JSON summaries, shell commands, and unified diffs] <br>\n**Output Parameters:** [1D] <br>\n**Other Properties Related to Output:** [May propose or apply memory-file edits; approved apply mode creates timestamped backups.] <br>\n\n## Skill Version(s): <br>\n0.3.2 (source: server release metadata) <br>\n\n## Ethical Considerations: <br>\nUsers should evaluate whether this skill is appropriate for their environment, review any generated or modified files before relying on them, and apply their organization's safety, security, and compliance requirements before deployment. <br>\n\nFile v0.3.2:test-fixtures/clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise Chinese responses for Chinese prompts.\n- The user wants file edits backed up before memory cleanup.\n\n## Durable Context\n- The user works with Codex and OpenClaw skills.\n\nFile v0.3.2:test-fixtures/conflicting-memory.md\n\n# User Memory\n\n- The user always wants very detailed long-form answers.\n- The user prefers concise direct answers unless they ask for detail.\n- Current task: remember that PR #221 is blocked by a failing Windows path test.\n- The user wants memory cleanup to ask before editing user-level memory.\n- The user wants automatic memory cleanup to apply without asking.\n\nFile v0.3.2:test-fixtures/expected-clean-memory.md\n\n# User Memory\n\n## Global Preferences\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user wants recoverable backups before edits to memory files.\n\n## Durable Context\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n\n## Agent Instructions\n- Do not store secrets, tokens, or credentials in memory files.\n\nFile v0.3.2:test-fixtures/noisy-memory.md\n\n# User Memory\n\n- The user prefers concise, direct Chinese responses when they write in Chinese.\n- The user prefers concise, direct Chinese replies.\n- On 2026-05-18 we debugged branch fix/archive-import-timeout and the next step is to rerun pytest tomorrow.\n- Current task: compare PR #184 with PR #185 and remember the exact failing stack trace.\n- The user's temporary API token is `<API_TOKEN_PLACEHOLDER>`.\n- The user wants recoverable backups before edits to memory files.\n- Last week Hermes Agent failed to append memory because memory.md was too long.\n- The user works with agent memory files across OpenClaw, Hermes Agent, and Codex.\n- TODO: after lunch, update the one-off dashboard screenshot.\n\nArchive v0.3.1: 18 files, 25285 bytes\n\nFiles: evals/evals.json (7035b), LICENSE (894b), README.md (4095b), references/agent-paths.md (2151b), references/classification-rubric.md (2519b), references/default-rules.json (3278b), references/mcp-version.md (1567b), scripts/audit_memory.py (23719b), scripts/run_tests.py (5301b), skill-card.md (2813b), SKILL.md (7327b), test-fixtures/clean-memory.md (233b), test-fixtures/conflicting-memory.md (363b), test-fixtures/expected-clean-memory.md (375b), test-fixtures/noisy-memory.md (702b), test-fixtures/secret-memory.md (271b), test-fixtures/short-polluted-memory.md (252b), _meta.json (139b)\n\nFile v0.3.1:SKILL.md\n\n---\nname: agent-memory-cleanup\ndescription: Audit, clean, consolidate, and maintain long-term user memory files for OpenClaw, Hermes Agent, Codex, Claude, and other agents. Use when the user asks to clean, prune, sanitize, deduplicate, review, repair, or periodically maintain user.md, memory.md, memories.md, profile.md, preferences.md, or agent memory notes. Also trigger proactively when memory writes fail because files are too long, memory budget/context limits are exceeded, storage is full, updates are rejected, duplicates or conflicts accumulate, or memory is polluted by outdated project details, one-off task notes, stale plans, or conversation residue. Gives cleanup recommendations without requiring the user to name the skill, applies edits only after appropriate authorization, and creates recoverable backups.\nmetadata:\n  openclaw:\n    requires:\n      env: []\n      bins: []\n    os: [windows, macos, linux]\n---\n\n# Agent Memory Cleanup\n\nKeep agent memory files focused on durable, global user context. Do not let long-term memory become a transcript, todo list, stale project log, debugging notebook, or secret store.\n\nMost deterministic work belongs in `scripts/audit_memory.py`. Prefer the script over re-deriving rules in prose when Python and file access are available. The script is the standard implementation for size checks, path discovery, Markdown unit splitting, duplicate detection, secret redaction, classification, proposed cleanup, diffs, backups, and approved writes.\n\n## Proactive Trigger UX\n\nTrigger this cleanup flow automatically when memory pressure or memory quality problems are detected:\n\n- A memory write, append, update, or compaction operation fails because the target memory file is too large.\n- The agent reports memory is full, over budget, truncated, too long, or cannot accept new entries.\n- The same memory fact appears many times with small variations.\n- Memory files contain contradictory preferences, stale dated task state, or obvious task-level residue.\n- The user asks why an agent cannot remember something or why a memory update was rejected.\n- A proposed new memory looks like task state, contains a secret, or would conflict with existing durable memory.\n- The user corrects a remembered fact, says something is outdated, or says a memory applies only to one project.\n\nWhen triggered proactively, do not make the conversation about the skill itself. The user does not need to know or name which skill is being used. Say plainly that the memory file appears too long, full, duplicated, or polluted, then offer to inspect it and propose cleanup.\n\nUse two-step consent for proactive cleanup:\n\n1. Ask whether the user wants cleanup recommendations. If they agree, inspect memory and produce a proposal.\n2. After showing the proposal, ask whether to apply it. Only then create backups and edit files.\n\nIf the user already explicitly authorized automatic cleanup for this file or environment, treat the first consent as granted. Still summarize what will be removed or condensed before writing unless the authorization also covers unattended edits.\n\n## Memory Quality Triggers\n\nDo not wait for files to become long. Short memory files can still be polluted. Use `--summary-json` for cheap quality checks and `--candidate` before saving a new global memory.\n\n```bash\npython scripts/audit_memory.py memory.md --summary-json\npython scripts/audit_memory.py --candidate \"Current task: tomorrow retry PR #302 on branch fix-memory\"\n```\n\nInterpret `quality.intervention`:\n\n- `prompt_cleanup_now_secret_detected`: immediately recommend cleanup; do not echo raw secrets.\n- `prompt_user_review_conflicting_memory`: ask the user to resolve conflicting preferences.\n- `do_not_write_candidate_to_global_memory`: do not save the proposed memory as global memory; offer a project note or skip it.\n- `prompt_cleanup_recommended`: propose cleanup even if the file is not long.\n- `prompt_audit_recommended`: mention that memory quality is degrading and ask whether to review.\n- `no_intervention_needed`: do not interrupt the user.\n\n## Execution Modes\n\nUse the least invasive mode that satisfies the request.\n\n### audit-only\n\nDefault for proactive triggers. Read memory files, classify entries, detect size pressure, duplicates, and suspected secrets, then report recommendations. Do not edit files.\n\n```bash\npython scripts/audit_memory.py path/to/memory.md\n```\n\n### propose-patch\n\nUse when the user wants to review cleanup before applying it, or when entries are ambiguous. Produce a proposed cleaned memory and diff. Do not edit files.\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode propose-patch --include-diff\n```\n\n### apply-approved\n\nUse only after explicit approval, or when the user has already authorized automatic cleanup for the relevant files. The script creates timestamped backups before writing.\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode apply-approved\n```\n\nAfter approved cleanup for a failed memory write, retry the original memory update only if the update itself is stable, global, and useful across future tasks.\n\n## Script Contract\n\nThe Python engine uses:\n\n- `references/default-rules.json` for deterministic thresholds, filename patterns, regex rules, and canonical rewrites.\n- `references/classification-rubric.md` for human review of ambiguous cases.\n- `references/agent-paths.md` when memory paths are unclear.\n- `references/mcp-version.md` when wrapping this as MCP tools.\n\nUseful script outputs:\n\n```bash\npython scripts/audit_memory.py memory.md --json\npython scripts/audit_memory.py memory.md --summary-json\npython scripts/audit_memory.py memory.md --write-proposed cleaned-memory.md\npython scripts/run_tests.py\n```\n\nThe script must not echo raw suspected secrets. It should redact them as `[REDACTED_SECRET]` in reports and remove them from proposed memory.\n\n## Fallback Without Python\n\nIf the script cannot run, use `references/classification-rubric.md` and follow the same safety model:\n\n- Keep stable global preferences and durable cross-task context.\n- Condense duplicated or overly specific entries into concise durable memories.\n- Remove completed task notes, stale plans, branch/PR/debug details, command output, and secrets.\n- Flag ambiguous or conflicting durable preferences for user review.\n- Create backups before any edit.\n\nAvoid broad recursive scans of the user home directory unless the user explicitly a\n\nArchive v0.3.0: 17 files, 22302 bytes\n\nFiles: evals/evals.json (6197b), LICENSE (894b), README.md (3741b), references/agent-paths.md (2151b), references/classification-rubric.md (2519b), references/default-rules.json (2224b), references/mcp-version.md (1567b), scripts/audit_memory.py (19515b), scripts/run_tests.py (3592b), skill-card.md (2382b), SKILL.md (6109b), test-fixtures/clean-memory.md (233b), test-fixtures/conflicting-memory.md (363b), test-fixtures/expected-clean-memory.md (375b), test-fixtures/noisy-memory.md (702b), test-fixtures/secret-memory.md (271b), _meta.json (139b)\n\nArchive v0.2.1: 14 files, 20716 bytes\n\nFiles: evals/evals.json (5549b), LICENSE (894b), README.md (2750b), references/agent-paths.md (2151b), references/mcp-version.md (1567b), scripts/audit_memory.py (15769b), skill-card.md (2225b), SKILL.md (15045b), test-fixtures/clean-memory.md (233b), test-fixtures/conflicting-memory.md (363b), test-fixtures/expected-clean-memory.md (375b), test-fixtures/noisy-memory.md (702b), test-fixtures/secret-memory.md (271b), _meta.json (139b)\n\nArchive v0.2.0: 14 files, 20219 bytes\n\nFiles: evals/evals.json (5038b), LICENSE (894b), README.md (2549b), references/agent-paths.md (2151b), references/mcp-version.md (1567b), scripts/audit_memory.py (15769b), skill-card.md (2307b), SKILL.md (14176b), test-fixtures/clean-memory.md (233b), test-fixtures/conflicting-memory.md (363b), test-fixtures/expected-clean-memory.md (375b), test-fixtures/noisy-memory.md (702b), test-fixtures/secret-memory.md (271b), _meta.json (139b)","readmeExcerpt":"Skill: Agent Memory Cleanup Owner: hollis9087 Summary: Clean and audit long-term agent memory files such as user.md, memory.md, memories.md, profile.md, preferences.md, and agent_memory.md. Use when the user expl... Tags: latest:0.3.7 Version history: v0.3.7 | 2026-05-31T09:51:05.603Z | user Narrow the skill description to reduce over-triggering: focus on explicit agent-memory cleanup requests and concrete memory wri","codeSnippets":[],"executableExamples":[{"language":"bash","snippet":"python scripts/audit_memory.py memory.md --summary-json"},{"language":"bash","snippet":"python scripts/audit_memory.py memory.md --mode propose-patch --include-diff"},{"language":"bash","snippet":"python scripts/audit_memory.py memory.md --mode apply-approved"},{"language":"bash","snippet":"python scripts/audit_memory.py --candidate \"candidate memory text\" --summary-json"},{"language":"bash","snippet":"python scripts/audit_memory.py path/to/memory.md"},{"language":"bash","snippet":"python scripts/audit_memory.py path/to/memory.md --mode propose-patch --include-diff"}],"parameters":null,"dependencies":[],"permissions":[],"extractedFiles":[{"path":"SKILL.md","content":"---\nname: agent-memory-cleanup\ndescription: Clean and audit long-term agent memory files such as user.md, memory.md, memories.md, profile.md, preferences.md, and agent_memory.md. Use when the user explicitly asks to clean, prune, sanitize, deduplicate, or review agent memory files, or when a memory write/update fails because the memory file is too long, full, over budget, rejected, duplicated, conflicted, stale, task-specific, or contains suspected secrets. Do not trigger for ordinary project docs, task notes, logs, code review, README edits, or general file cleanup. Applies edits only after explicit approval and creates recoverable backups.\nmetadata:\n  openclaw:\n    requires:\n      env: []\n      bins: []\n    os: [windows, macos, linux]\n---\n\n# Agent Memory Cleanup\n\nThis skill should be lightweight and low-noise. Do not require the user to know internal implementation names unless they ask. The user should still receive clear memory-state prompts, such as \"memory appears too large, stale, duplicated, conflicted, or unsafe,\" when action is useful.\n\n## Default Flow\n\n1. Detect memory pressure or pollution.\n2. If Python/file access is available, run a cheap summary check first:\n\n```bash\npython scripts/audit_memory.py memory.md --summary-json\n```\n\n3. If `quality.intervention` is `no_intervention_needed`, do not interrupt the user.\n4. If intervention is needed, say briefly that memory appears too large, stale, duplicated, conflicted, or unsafe, and ask whether to review cleanup recommendations. Avoid implementation labels like the skill name unless the user asks.\n5. After the user agrees, run:\n\n```bash\npython scripts/audit_memory.py memory.md --mode propose-patch --include-diff\n```\n\n6. Apply only after a second explicit approval, unless unattended cleanup was already authorized:\n\n```bash\npython scripts/audit_memory.py memory.md --mode apply-approved\n```\n\nThe apply mode must create timestamped backups before writing.\n\n## Trigger Points\n\nUse this flow for:\n\n- Memory write/update rejected, full, over budget, truncated, or too long.\n- Short memory with secrets, task-state residue, duplicated facts, or conflicting preferences.\n- User says a remembered fact is wrong, outdated, project-only, or should not be remembered.\n- Before saving a new global memory candidate:\n\n```bash\npython scripts/audit_memory.py --candidate \"candidate memory text\" --summary-json\n```\n\nIf candidate lint returns `do_not_write_candidate_to_global_memory`, do not store it globally. Offer to skip it or keep it as project/task notes.\n\n## Intervention Values\n\n- `prompt_cleanup_now_secret_detected`: recommend cleanup immediately; never echo raw secrets.\n- `prompt_user_review_conflicting_memory`: ask the user to resolve conflicting durable preferences.\n- `do_not_write_candidate_to_global_memory`: block global memory write.\n- `prompt_cleanup_recommended`: offer cleanup recommendations.\n- `prompt_audit_recommended`: mention memory quality may be degrading and ask whether to review.\n- `no_interve"},{"path":"README.md","content":"# Agent Memory Cleanup\n\nAgent Memory Cleanup audits and cleans long-term user memory files for agents such as OpenClaw, Hermes Agent, Codex, Claude, and other assistant runtimes.\n\nThe skill keeps memory files focused on stable, global user context. It removes or flags stale task notes, completed project details, duplicated preferences, transient debugging logs, and suspected secrets.\n\n## When To Use\n\nUse this skill when:\n\n- A user asks to clean, prune, sanitize, deduplicate, or review `user.md`, `memory.md`, or similar files.\n- An agent cannot write memory because the memory file is too long.\n- Memory storage reports full, over budget, truncated, or rejected.\n- Global user memory has been polluted by task-level details.\n- Duplicate or conflicting memories are accumulating.\n\n## Safety Model\n\nThe default behavior is conservative:\n\n- Audit automatically when memory pressure is detected.\n- Recommend cleanup without waiting.\n- Do not require the user to name or invoke this skill explicitly.\n- Ask before writing unless the user already authorized automatic cleanup.\n- Create timestamped backups before edits.\n- Redact suspected secrets in reports.\n\nFor proactive cleanup, use two-step consent: first ask whether to inspect and propose cleanup, then ask again before applying edits.\n\n## Files\n\n- `SKILL.md` - Skill instructions.\n- `scripts/audit_memory.py` - Deterministic Python audit/proposal/apply engine.\n- `scripts/run_tests.py` - Local regression tests.\n- `references/default-rules.json` - Thresholds, filename patterns, regex rules, and canonical rewrites.\n- `references/classification-rubric.md` - Human-readable rubric for ambiguous cases or non-Python fallback.\n- `references/agent-paths.md` - Agent-specific memory path guidance.\n- `references/mcp-version.md` - Guidance for wrapping the skill as an MCP server.\n- `evals/evals.json` - Regression prompts.\n- `test-fixtures/` - Sample noisy and expected memory files.\n\n## Architecture\n\nThe skill is intentionally Python-first:\n\n- `SKILL.md` handles trigger conditions, user consent, safety boundaries, and when to call the script.\n- `audit_memory.py` handles deterministic behavior so different agents and models get consistent results.\n- `default-rules.json` keeps thresholds and regex rules configurable without editing the engine.\n\nThis keeps agent context smaller and reduces variation between Codex, OpenClaw, Hermes Agent, Claude, and other runtimes.\n\n## Script Usage\n\nAudit a memory file:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md\n```\n\nGenerate a proposed diff:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode propose-patch --include-diff\n```\n\nWrite a proposed cleaned file without changing the source:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --write-proposed cleaned-memory.md\n```\n\nApply approved cleanup:\n\n```bash\npython scripts/audit_memory.py path/to/memory.md --mode apply-approved\n```\n\nMachine-readable summaries:\n\n```bash\npython scripts/audit_memory.py path/to/memory"},{"path":"_meta.json","content":"{\n  \"ownerId\": \"kn79q2kj15j98d5cqxw95sfd0185vax5\",\n  \"slug\": \"agent-memory-cleanup\",\n  \"version\": \"0.3.7\",\n  \"publishedAt\": 1780221065603\n}"},{"path":"references/agent-paths.md","content":"# Agent Memory Paths\n\nUse this reference only when the user has not provided explicit memory paths.\nPrefer user-provided paths over discovery.\n\n## Safe Discovery Order\n\n1. Current workspace memory files named `user.md`, `memory.md`, `memories.md`, `profile.md`, `preferences.md`, or `agent_memory.md`.\n2. Workspace agent config folders such as `.codex/`, `.claude/`, `memory/`, or `memories/`.\n3. Agent-specific home variables when available.\n4. User home folders only when the user explicitly asks for a broader inventory.\n\nAvoid broad recursive home scans by default.\n\n## Codex\n\nLikely locations:\n\n- `$CODEX_HOME`\n- Workspace `.codex/`\n- Workspace `.codex/skills/` for installed or project-level skills\n\nNotes:\n\n- Treat `AGENTS.md` as project policy, not global user memory.\n- Treat skill `SKILL.md` files as skill instructions, not user memory.\n\n## Claude Code\n\nLikely locations:\n\n- User-level Claude config under the configured Claude home.\n- Project `.claude/`\n- Project `.claude/skills/`\n\nNotes:\n\n- Treat `CLAUDE.md` as instruction policy unless the user explicitly says it is their memory file.\n- Project instructions may contain durable rules, but they are not global user memory by default.\n\n## OpenClaw\n\nLikely locations:\n\n- OpenClaw workspace memory folders.\n- ClawHub-installed skill directories.\n- User-provided OpenClaw agent home or profile paths.\n\nNotes:\n\n- ClawHub skill folders contain reusable skill instructions. Do not clean them as user memory.\n- If publishing or installing skills, keep release metadata separate from memory cleanup.\n\n## Hermes Agent\n\nLikely locations:\n\n- Configured Hermes Agent home.\n- Workspace memory folders.\n- User-provided memory root.\n\nNotes:\n\n- When Hermes reports memory storage full, run audit mode first and ask before applying edits unless automatic cleanup was explicitly authorized.\n\n## Generic Agents\n\nIf the agent is not listed:\n\n- Search only the current workspace and explicit config roots.\n- Identify memory files by filename and content, not by filename alone.\n- Skip project policy, prompt templates, system instructions, and skill/plugin manifests unless the user includes them in scope."},{"path":"references/classification-rubric.md","content":"# Classification Rubric\n\nLoad this reference only when the script is unavailable, when reviewing ambiguous results, or when changing cleanup policy.\n\n## Keep\n\nKeep items that are stable, global, and useful across many future tasks:\n\n- Communication preferences, such as desired language, brevity, directness, formatting, or review style.\n- Durable working preferences, such as testing expectations, preferred tools, coding conventions, or repository hygiene rules.\n- Long-term user context that affects many tasks, such as role, recurring domains, accessibility needs, locale, timezone, or persistent environment constraints.\n- Stable names of important long-lived projects or systems, but only when the fact is useful without detailed stale status.\n- Explicit user instructions that apply generally across agents.\n\n## Condense\n\nCondense items that contain a durable signal mixed with task detail:\n\n- Replace a completed task history with the general preference it revealed.\n- Replace a specific one-off command sequence with a durable tool preference.\n- Replace long project summaries with a stable project identity or recurring constraint.\n- Merge duplicate or overlapping preferences into one canonical bullet.\n\n## Remove\n\nRemove items that are not appropriate for long-term global memory:\n\n- Completed task notes, temporary plans, or debugging traces.\n- Stale statuses such as `currently working on`, `next step is`, `today`, `tomorrow`, or dated commitments that are no longer current.\n- Details about a single ticket, pull request, report, dataset, branch, prompt, or conversation.\n- Failed attempts, intermediate observations, transient errors, logs, or command output.\n- Guesses, inferred preferences, or speculative personal facts that the user did not confirm.\n- Secrets, credentials, private URLs, tokens, passwords, or sensitive operational details.\n- Duplicates, contradictions, and entries that are too vague to help future agents.\n\n## Flag\n\nFlag items for user review when:\n\n- The item may be durable but could also be stale.\n- The item refers to a project or identity that cannot be verified locally.\n- Two memory files disagree about an important preference.\n- Removing the item could materially change future agent behavior.\n\n## Canonical Memory Shape\n\n```markdown\n# User Memory\n\n## Global Preferences\n- ...\n\n## Working Style\n- ...\n\n## Durable Context\n- ...\n\n## Agent Instructions\n- ...\n\n## Review Needed\n- ...\n```\n\nOmit empty sections. Do not create `Review Needed` if there are no unresolved items."}],"languages":[],"docsSourceLabel":"CLAWHUB","editorialOverview":"Clean and audit long-term agent memory files such as user.md, memory.md, memories.md, profile.md, preferences.md, and agent_memory.md. Use when the user expl... Skill: Agent Memory Cleanup Owner: hollis9087 Summary: Clean and audit long-term agent memory files such as user.md, memory.md, memories.md, profile.md, preferences.md, and agent_memory.md. Use when the user expl... Tags: latest:0.3.7 Version history: v0.3.7 | 2026-05-31T09:51:05.603Z | user Narrow the skill description to reduce over-triggering: focus on explicit agent-memory cleanup requests and concrete memory wri","editorialQuality":{"score":100,"threshold":65,"status":"ready","wordCount":1434,"uniquenessScore":45,"reasons":[]}},"media":{"evidence":{"source":"no-media","verified":false,"confidence":"low","updatedAt":"2026-10-11T13:13:44.767Z","emptyReason":"No screenshots, media assets, or demo links are available."},"primaryImageUrl":null,"mediaAssetCount":0,"assets":[],"demoUrl":null},"ownerResources":{"evidence":{"source":"unclaimed","verified":false,"confidence":"low","updatedAt":"2026-10-11T13:13:44.767Z","emptyReason":"This page has not been claimed by the agent owner."},"hasCustomPage":false,"customPageUpdatedAt":null,"customLinks":[],"structuredLinks":{"docsUrl":null,"demoUrl":null,"supportUrl":null,"pricingUrl":null,"statusUrl":null},"customPage":null},"relatedAgents":{"evidence":{"source":"protocol-neighbors","verified":false,"confidence":"medium","updatedAt":"2026-10-11T16:01:07.505Z","emptyReason":null},"items":[{"id":"8ebccd8e-3863-4187-8355-c3f14e1f9edf","entityType":"agent","canonicalPath":"/agent/iofficeai-aionui","slug":"iofficeai-aionui","name":"AionUi","description":"Free, local, open-source 24/7 Cowork app and OpenClaw for Gemini CLI, Claude Code, Codex, OpenCode, Qwen Code, Goose CLI, Auggie, and more | 🌟 Star if you like it!","url":"https://github.com/iOfficeAI/AionUi","homepage":"https://www.aionui.com","source":"GITHUB_REPOS","protocols":["MCP","OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-10-09T19:11:12.944Z","createdAt":"2026-02-25T03:38:16.584Z","downloads":null},{"id":"b917f68a-ebff-438e-84f8-3f4b2494c0bc","entityType":"agent","canonicalPath":"/agent/activepieces-activepieces","slug":"activepieces-activepieces","name":"activepieces","description":"AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents","url":"https://github.com/activepieces/activepieces","homepage":"https://www.activepieces.com","source":"GITHUB_REPOS","protocols":["OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-15T02:22:12.426Z","createdAt":"2026-02-25T03:38:12.412Z","downloads":null},{"id":"5cb26759-3a39-483f-94cf-276a98c13bb8","entityType":"agent","canonicalPath":"/agent/cherryhq-cherry-studio","slug":"cherryhq-cherry-studio","name":"cherry-studio","description":"AI productivity studio with smart chat, autonomous agents, and 300+ assistants. Unified access to frontier LLMs","url":"https://github.com/CherryHQ/cherry-studio","homepage":"https://cherry-ai.com","source":"GITHUB_REPOS","protocols":["MCP","OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-04-11T14:38:40.986Z","createdAt":"2026-02-25T03:38:19.379Z","downloads":null},{"id":"6f6582d0-5d76-4f0f-b81d-86520247950b","entityType":"agent","canonicalPath":"/agent/copilotkit-copilotkit","slug":"copilotkit-copilotkit","name":"CopilotKit","description":"The Frontend for Agents & Generative UI. React + Angular","url":"https://github.com/CopilotKit/CopilotKit","homepage":"https://docs.copilotkit.ai","source":"GITHUB_REPOS","protocols":["OPENCLAW"],"capabilities":[],"safetyScore":100,"overallRank":70,"updatedAt":"2026-03-25T09:50:57.846Z","createdAt":"2026-02-25T03:39:14.617Z","downloads":null}],"links":{"hub":"/agent","source":"/agent/source/clawhub","protocols":[{"label":"OpenClaw","href":"/agent/protocol/openclew"}]}}}