Add the disk-hygiene plugin for session-owned cleanup - #48
Conversation
Move the shared cleanup hooks out of the Cortex plugins, where they were proposed as a pull request, into an independent plugin for Claude Code and Codex. The removal logic is unchanged; the review findings are fixed: - Push detection reads only the command of a shell tool, so file content, grep patterns, commit messages, heredoc bodies and --dry-run no longer purge a live session. - The ledger lock waits up to 10 seconds instead of failing at once, an unchanged ledger is not rewritten, and ordinary tool calls take no lock. - DISK_HYGIENE_CLEANUP=off disables every hook and mutating command. - The context-guard checkpoint follows the transcript policy. - A corrupt or foreign end-of-session intake file is skipped and reported instead of blocking every hook. - A symlinked config directory is resolved instead of silently disabling cleanup, and the Cortex completion receipt for Codex rollouts is optional. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mkvy5MtGG89cNLuQSU8xLe Signed-off-by: cdeust <cdeust@icloud.com>
The CI job installs ruff 0.16.8, which flags 38 issues in the new plugin that an older local ruff did not: unsorted imports, unused noqa comments, nested with statements, subprocess.run without an explicit check argument, one file handle without a context manager and a shebang without the executable bit. Fix them without changing behavior. The purgers fixture moves to tests/conftest.py instead of being re-imported by alias. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mkvy5MtGG89cNLuQSU8xLe Signed-off-by: cdeust <cdeust@icloud.com>
|
|
||
| def holder(lock_path, seconds): | ||
| """Hold the ledger lock from another thread's file descriptor.""" | ||
| handle = open(lock_path, "a+") # noqa: SIM115 - held until the release thread ends |
|
|
||
| def test_active_file_prevents_removal(self): | ||
| with ( | ||
| open(Path(self.path, "open.tmp"), "w"), |
An end-of-session intake with a valid shape but a session id that is not a UUID was written by SessionEnd, then made the host import raise on every later hook, so no host cleanup ran for any session. The host consumer now reports and skips such a file while the worktree consumer, which only needs an owner key, still reads it. A test covers both consumers. Also state in the README what really happens to an intake recorded under other roots, and document the migration of the ledger location and of the CORTEX_CLAUDE_DIR variable in the README and the CHANGELOG. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mkvy5MtGG89cNLuQSU8xLe Signed-off-by: cdeust <cdeust@icloud.com>
|
ZETETIC-REVIEW: REQUEST_CHANGES Independent read-only review of 3d6ca63 and 42977e3 against the original files of cdeust/Cortex#645 (head 9a8b606b). No wrongful deletion path was found: Findings:
Not verified by the reviewer: no test was run, and the real Codex |
|
ZETETIC-REVIEW: APPROVE Follow-up to the REQUEST_CHANGES verdict above, on head 4562db8. Findings 1 to 3 are fixed and finding 4 is accepted as documented.
|
Summary
plugins/disk-hygiene, a shared cleanup hook for Claude Code and Codex, moved out of fix(hooks): share cleanup across Claude and Codex, retain transcripts Cortex#645 because cleanup of session files does not belong to a memory server.DISK_HYGIENE_CLEANUP=offdisables every hook; the context-guard checkpoint follows the transcript policy; a corrupt or foreign end-of-session intake file is skipped and reported; a symlinked config directory is resolved; the Cortex completion receipt for Codex rollouts is optional.Test plan
🤖 Generated with Claude Code
https://claude.ai/code/session_01Mkvy5MtGG89cNLuQSU8xLe