> ## Documentation Index
> Fetch the complete documentation index at: https://docs.specpilot.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# specpilot compact

> Shorten context.md and requirements.md, with an agent's plan, keeping every original in an archive file.

```bash theme={null}
specpilot compact [options]
```

Run it in the project's folder, or name it with `--dir`. Your agent drives it through [`/specpilot-compact`](https://docs.specpilot.dev/slash-commands#specpilot-compact): the agent judges and writes the plans, and this command moves the text and keeps the originals.

## Options

| Option | What it does | Default |
| - | - | - |
| `-d, --dir <directory>` | The project folder | `.` |
| `--report` | Prints only the report: each file compact touches, its size, estimated tokens and likely saving | Off |
| `--apply` | Applies the plans in `development/compact-plan.md` and `development/compact-requirements.md` | Off |
| `--dry-run` | With `--apply`, shows what would change without writing | Off |
| `--force` | With `--apply`, doesn't ask on a branch other than main or master | Off |
| `--calls <n>` | Model calls per task for the per-task tokens, 1 to 1000. Only with `--report` or `--apply --dry-run` | `50` |

`--report` can't be used with `--apply`.

## What it does

**On its own**, it lists each `development/context.md` entry with its status, line count, size and title, then the `project/requirements.md` items, largest first, with their key, size and line count. The statuses are `finished` (every task it names is in `tasks-archive.md`), `completed`, `open`, `unknown`, `no-id` and `no-lead`. They are hints for the agent, not decisions. Nothing is written.

**With `--report`**, it prints one row per file (`tasks.md`, `prompts.md`, `context.md`, `requirements.md`): its size, estimated tokens (bytes ÷ 4) and the saving. The saving is exact for what [`specpilot archive`](https://docs.specpilot.dev/reference/cli/archive) would move, and likely for the agent's part. The last line is what the agent's run costs once and after how many reads it pays back, or `Nothing for the agent to compact.` Nothing is written.

**With `--apply`**, it reads the two plans and applies both or neither:

* Each `context.md` entry marked archive moves, unchanged, to `development/context-archive.md`, and a one-line marker takes its place.
* Each rewritten requirement replaces the item in place, and the original is kept unchanged in `project/requirements-archive.md`.
* On success it prints `Moved N entries to context-archive.md` and `Rewrote N requirements (X KB shorter); originals in requirements-archive.md`, and deletes the plans.

It refuses, and writes nothing, when an entry names a task that's still open, or a rewrite is longer, out of date or not a single list item ending in the same `[REQ-…]` key. It then prints each reason and `Nothing was written.` Items without a bracketed key are never rewritten.

**With `--apply --dry-run`**, it shows the entries that would move, each requirement's size before and after with the backticked strings and IDs the rewrite drops, and the exact saving per file.

## What it writes

Only with `--apply`: `development/context.md`, `development/context-archive.md`, `project/requirements.md` and `project/requirements-archive.md`. It deletes the two plan files when it's done.

## The branch question

With `--apply` on a branch other than main or master, it asks before writing. Compact after you merge, so the change happens once. `--force` skips the question.

## Exit status

`1` when it refuses, when there's no `.specs/` folder, no `context.md` or no plan, or when an option is wrong. Otherwise `0`.

## Examples

```bash theme={null}
specpilot compact --report
specpilot compact
specpilot compact --apply --dry-run
specpilot compact --apply
```

Checked against SpecPilot 2.22.0.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.