Skip to main content
skill CX Codex

context-hygiene — Claude Code skill for context cleanup

This Claude Code skill archives old session log entries and trims active priorities. Run /context-hygiene to clean the context files.

MIT ★ 26 updated 2026-11-16

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add wrg32786/aigent-os --skill context-hygiene -a claude-code
Open on GitHub

What context-hygiene does

The skill checks vault/memory/SESSION_LOG.md and vault/memory/ACTIVE_PRIORITIES.md, then runs node daemons/nightly-context-hygiene.mjs --root <aigent-root>. It hashes the source files before editing. If a hash changes, the run stops with CONTEXT_HYGIENE_RACE.

For the session log, it moves older complete blocks to an archive and keeps the five newest. In the priorities file, only content explicitly marked stale or superseded can be archived. The archive is written before the live file is trimmed, and the checker runs again afterward. Other memory files are left untouched. Node.js and the two memory files are required.

What it helps with

  • archive older session log blocks
  • keep the five newest dated entries live
  • move stale priorities into an archive
  • detect changes to source files during cleanup

Example prompts for the agent

  • Run /context-hygiene to clean up the session log.
  • Use /context-hygiene to archive older session entries.
  • Run /context-hygiene to trim active priorities.

How to install context-hygiene

1Skills CLI (Vercel)

npx skills add wrg32786/aigent-os --skill context-hygiene -a claude-code

2Manually: put the files in place

~/.claude/skills/context-hygiene/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/context-hygiene/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about context-hygiene

How do I install context-hygiene in Claude Code?

Run npx skills add wrg32786/aigent-os --skill context-hygiene -a claude-code. The skill file is at ~/.claude/skills/context-hygiene/SKILL.md.

What does context-hygiene do?

It checks the session log and active priorities, moves eligible older entries into archive files, then runs the checker again.

What does context-hygiene need to run?

It requires Node.js and the files vault/memory/SESSION_LOG.md and vault/memory/ACTIVE_PRIORITIES.md.

Source text

SKILL.md · MIT
---
name: context-hygiene
agent: none
description: "Archive and trim ACTIVE_PRIORITIES and dated SESSION_LOG entries. Use when cleaning active priorities, trimming session logs, or running context hygiene."
allowed-tools: Read, Write, Bash
user-invocable: true
status: PRODUCTION - bounded archive writer
triggers:
  - context hygiene
  - trim session log
  - archive old session entries
  - clean active priorities
---

# /context-hygiene

This is the sole bounded compaction exception to the Session Log chronicle. It
runs only when invoked, never while the framework is being installed or tested
against a real vault.

## Precondition

1. Read `vault/memory/SESSION_LOG.md` and
   `vault/memory/ACTIVE_PRIORITIES.md`.
2. Hash both exact byte streams with SHA-256.
3. Run:

```text
node daemons/nightly-context-hygiene.mjs --root <aigent-root>
```

Green means no edit is needed. Red permits only the bounded archive below.
Unreadable or unfamiliar content is a failure, not permission to rewrite.

## Session Log archive

The executable target schema uses newest-first dated H2 blocks. A canonical
block starts with `## YYYY-MM-DD - title` and contains one nonempty occurrence
of each field:

- `Objective`
- `Completed`
- `Decisions`
- `Open threads`
- `Next action`

Archival rules:

- Keep the newest five live dated blocks.
- Move older whole blocks to
  `vault/memory/SESSION_LOG_ARCHIVE_<YYYY-MM-DD>.md`.
- Preserve source text and order.
- Preserve frontmatter, title, schema guidance, and archive links.
- Dedupe by exact dated heading plus block hash.
- Refuse a block whose boundary cannot be determined without judgment.

## Active Priorities archive

The mechanically checkable live shape contains:

- exactly one `## Operating Mode: <mode>` heading;
- one to five live bullet priorities under `## Tier 1`, `## Tier 2`, or
  `## Tier 3` headings;
- no placeholder priority;
- one valid `Last reviewed: YYYY-MM-DD` line; and
- no embedded `## Archived` section.

Move only content explicitly marked stale, superseded, or archived to
`vault/memory/ACTIVE_PRIORITIES_ARCHIVE_<YYYY-MM-DD>.md`. If removal requires a
human decision, preserve it and report the gate.

## Compare-and-swap

Immediately before each write, hash the live source again. If either hash
differs from the precondition hash, abort with `CONTEXT_HYGIENE_RACE`. Archive
must be durable before the source is trimmed.

After writing, re-run the checker. Only its literal
`CONTEXT_HYGIENE PASS` receipt may record the checkpoint green. Return archive
paths and before/after hashes in bounded detail. Never touch another memory
file.

© wrg32786 · MIT · wrg32786/aigent-os

Similar skills

SKILL.md skills catalog →

From the same set58

The whole set →
Diagnose Diagnose — a Claude Code skill that traces faults across aigent-OS components and settings. It investigates broken hooks, skill routing failures, and unexpected changes in agent behavior. CX Codex +1 ★ 26repo stars deep-recon The deep-recon Claude Code skill coordinates several agents to investigate a topic and create a structured recon document. It can draw on notes and web sources, with interactive or autonomous rounds. CX Codex +1 ★ 26repo stars decide This Claude Code skill weighs a decision against selected criteria and returns a structured recommendation. Run /decide to compare options or ask for help choosing a course of action. CX Codex +1 ★ 26repo stars critique-plan The critique-plan Claude Code skill challenges strategic plans, architectural decisions, and proposals before approval. It surfaces counterarguments, hidden assumptions, and alternatives. CX Codex +1 ★ 26repo stars context-capsule The context-capsule Claude Code skill saves the current project state in a capsule for later work. Run it to checkpoint before risky changes, mark a completed milestone, or hand work to another session. CX Codex +1 ★ 26repo stars compact-note The compact-note Claude Code skill condenses long notes and logs while keeping the reasoning behind decisions. It runs on requests to shorten a note, log, or memory. CX Codex +1 ★ 26repo stars comms-summarize The comms-summarize Claude Code skill summarizes unread messages from an inbox, channel, or thread. It flags items that need action and separates them from FYI and stale messages. CX Codex +1 ★ 26repo stars cognitive-update The cognitive-update Claude Code skill updates goals, beliefs, self-model fields, and procedures from explicit evidence. It activates for cognitive or runtime state changes. CX Codex +1 ★ 26repo stars

Project sponsors

Companies that keep this analytics open