clean

clean is a command for Claude Code from goldenwo/claude-state-drift. It costs 37 tokens per session (324 once invoked), scanned A, original, MIT.

A cleanup command for archiving old completed work records from .claude/state.json into a separate archive file. It first performs a dry run, meaning it previews the proposed changes without applying them.

In plain words
What is it for?
Use it to find completed records older than a chosen age, keep the newest records, and archive the rest after approval. It preserves active, blocked, deferred, and open work.
Why use it?
Long-lived project state files can become difficult to read and maintain. The confirmation step prevents accidental removal, while the append-only archive keeps the cleanup reversible.

Command for Claude Code

Written for Claude Code: allowed-tools in frontmatter.

Part of the claude-state-drift plugin — 3 skills, 6 commands, 4 hooks shipped together

Good fit Use it to find completed records older than a chosen age, keep the newest records, and archive the rest after approval. It preserves active, blocked, deferred, and open work.

Compare 6 commands from other repositories ↓
Install with agentmods
npx agentmods add commands/goldenwo/claude-state-drift/clean
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/goldenwo/claude-state-drift

Made for: Claude Code.

Or install claude-state-drift, the plugin that ships this one along with the rest of its 3 skills, 6 commands, 4 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for clean

README.md
[![agentmods](https://agentmods.dev/badge/commands/goldenwo/claude-state-drift/clean.svg)](https://agentmods.dev/commands/goldenwo/claude-state-drift/clean)
Your own site
<a href="https://agentmods.dev/commands/goldenwo/claude-state-drift/clean"><img src="https://agentmods.dev/badge/commands/goldenwo/claude-state-drift/clean.svg" alt="Measured on agentmods" height="20"></a>
Per session 37 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 324 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00037 $0.00324
Opus 5 $0.00018 $0.00162
Sonnet 5 $0.00007 $0.00065
Haiku 4.5 $0.00004 $0.00032

Measured 8d ago against content hash 2895c10d0c70, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

clean scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/clean.md · 15 lines

What it actually says

Archive stale done deliverables out of .claude/state.json to keep it lean, using the propose-then-apply pattern (never a blind write).

  1. Run state-clean (dry-run — no flags) against the current project. It prints which done deliverables are old enough to archive; it keeps the most-recent N plus everything in-progress / deferred / blocked, open questions, and the current focus.
  2. Show the user that list and the counts. If nothing is archivable, say so and stop.
  3. Ask the user to confirm. Offer to tune --keep N (default 10 most-recent done kept) or --older-than DAYS (default 30) if they want a different cut.
  4. Only after explicit approval, run state-clean --apply (with any agreed flags). Archived entries go to an append-only .claude/state-archive.jsonl; git is the backstop, so it is reversible.
  5. Confirm what was archived. (Note: state-clean does not touch last_updated — it is housekeeping, not a state change.)

Never run --apply before the user has seen the dry-run and approved. state-clean is on the Bash tool's PATH while the plugin is enabled.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 15 lines · 37 tokens per session scan A 2895c10d0c70

Subscribe to this mod's changes

clean is a command published in the GitHub repository goldenwo/claude-state-drift (1 stars, last pushed 21d ago), licensed MIT. It adds 37 tokens to every session and 324 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.