cf clean
Interactively clean files generated by Coding Friend inside docs/ subdirectories, with per-directory confirmation.
Usage
cf clean
No flags or arguments. The command is fully interactive — it loops over the directories that contain content one at a time: pick a directory, pick an age cutoff for it, confirm, and repeat until you choose Done (exit).
Directories
The following directories are candidates for cleaning. Only directories that exist and have at least one file will appear in the selection list.
| Directory | Default path | What Coding Friend generates there |
|---|---|---|
context | docs/context/ | Context handoff files for agent tasks (cf-plan, cf-implementer) |
memory | docs/memory/ | Markdown memory files created by /cf-remember and /cf-scan |
research | docs/research/ | Research documents created by /cf-research |
reviews | docs/reviews/ | Code review outputs from /cf-review-out and /cf-review-in |
plans | docs/plans/ | Implementation plans created by /cf-plan |
sessions | docs/sessions/ | Session files saved by cf session save |
learn | ~/.coding-friend/learn/ | Learning notes created by /cf-learn (respects learn.outputDir) |
All paths respect your docsDir config setting. The memory directory also respects config.docsDir, and the learn directory respects config.learn.outputDir if set.
Behavior
- Banner — prints a header so you know which command is running.
- Directory selection (loop) — shows only directories that exist and have content, one pick at a time. Each option displays the directory name and a file count, e.g.
context — 3 files, plus a Done (exit) option to finish. File counts are refreshed after every round. - Date range prompt — pick an age cutoff for the selected directory:
- More than 1 day / 3 days / 1 week / 1 month / 1 year
- Before a specific date (
YYYY-MM-DD) - Clean all (no date filter)
- Confirmation — the command prints the directory path and the chosen range, then asks you to confirm deletion of matching contents. The default answer is No (safe by default).
- Clearing — only entries that match the date range are deleted. The top-level folder itself is preserved. The loop then returns to step 2 so you can clean another directory with a different cutoff.
- Summary — after you exit the loop, prints the total number of files removed and a per-directory breakdown.
If no directories have content, the command prints Nothing to clean. and exits.
How dates are determined
For each entry inside a selected directory:
- If the filename starts with a
YYYY-MM-DD-prefix (the convention used bycf-plan,cf-fix,cf-remember, etc.), that date is used. - Otherwise the filesystem
mtimeis used as the fallback.
This means recently regenerated history docs still keep their original date and won't be falsely preserved by a "more than 1 week" filter just because they were rewritten yesterday.
Notes
-
Memory directory warning — when you select
memory, the confirmation message includes a reminder that the directory may contain SQLite databases (used by Tier 1 memory). Stop the memory daemon before cleaning to avoid corruption:cf memory stop-daemon cf clean -
Irreversible — deletion is permanent. The per-directory
confirmprompt (default: No) is the only safeguard. Use with care. -
Folders are kept — only the contents of each directory are removed. The directories themselves remain so Coding Friend can write to them again later.