Optimize learning memory. Prunes stale entries, consolidates duplicates, rebalances tags. Interactive — confirms before deleting. Use: /trw-memory-optimize
Codex-specific skill: this version is authored for Codex. Follow Codex-native skill and subagent flows, and ignore Claude-only references if any remain.
Optimize the TRW self-learning layer by pruning low-value entries, consolidating duplicates, and rebalancing tags. Interactive — always confirms before making destructive changes.
Audit first: Run the same analysis as /trw-memory-audit:
trw_recall('*', compact=true) for all learnings.trw/learnings/index.yamlBuild optimization plan:
repeated with count suffix, entries referencing removed featuresPresent plan: Show the user:
Execute (only after user confirmation):
obsolete (do not delete the file — TRW tracks obsolete entries)trw_learn, then mark originals as obsoleteSync: Run delivery sync so AGENTS.md reflects the optimized learning set.
Report: Before/after summary:
The optimal learning count scales with project complexity — do NOT use a fixed target.
Formula: Target = (distinct domain count) × 3-5 entries per domain, with a floor of 20.
How to calculate:
Consolidation depth limit: Never merge more than 10-15 entries into a single compendium. If a topic has 60+ entries, create 5-8 sub-topic compendiums (e.g., "hallucination-grounding", "hallucination-detection", "hallucination-mitigation") rather than one mega-entry.
Domain coverage rule: Every distinct domain MUST retain at least 1 detailed entry after optimization. If consolidation would leave a domain with 0 entries, it's too aggressive.
obsolete status insteadAfter standard pruning and consolidation, run an assertion verification wave:
trw_recall(query="*", max_results=0) and filter for entries with assertion_statusUPDATE_LEARNING: Learning text needs revision (provide new text)UPDATE_ASSERTION: Assertion pattern is wrong (provide corrected pattern)RETIRE_LEARNING: Knowledge is obsolete (provide reason)CODE_VIOLATION: Code is wrong, learning is right (flag for human review)trw_learn_update() to apply changes (with user confirmation for retirements)/trw-memory-audit first for a read-only preview