---
title: "opod cache"
description: "List a node's weight cache, prune what no plan references without touching files opod did not fetch, and keep a disk KV-cache tier under a size bound."
url: "https://opod.io/docs/core-cli/cache/"
markdown_url: "https://opod.io/docs/core-cli/cache.md"
section: "Core CLI"
last_updated: "2026-10-30"
---

# opod cache

> List a node's weight cache, prune what no plan references without touching files opod did not fetch, and keep a disk KV-cache tier under a size bound.

## In short

`opod cache` lists and reclaims the space model weights take on a node. It only ever deletes files opod itself fetched (they carry a marker), and it is a dry run unless you pass `--apply`. `kv-prune` keeps a disk KV-cache tier under a size cap. It runs on the node with no leader.

```bash
opod cache prune --dir /data/models            # what would go
opod cache prune --dir /data/models --apply    # remove it
```

```text
would remove Llama-3.2-3B-Instruct-Q4_K_M.gguf           1.9 GB (last used 31h0m0s ago)
would remove 1 item(s), 1.9 GB; kept 2 referenced or recent; left 1 file(s) this cache did not write (my-own-model.gguf)
```

## Usage

```text
opod cache ls [--dir DIR] [--json]
opod cache prune [--dir DIR] [--keep a,b] [--min-age 24h] [--target-free GB] [--sweep 24h] [--apply] [--json]
opod cache kv-prune --dir DIR --max-gb N [--keep a,b] [--every 10s] [--apply] [--json]
```

Models are pulled once per node into the models directory and shared by every worker on it. Nothing deletes from that directory on its own, so a node fills up. `opod cache` reclaims the space safely. It runs on the node, without a leader, a config file or a store. A manager runs `prune` as a job and passes the files its plans still reference.

Two facts make a delete safe:

- **A marker.** [`opod fetch`](https://opod.io/docs/core-cli/fetch/) and every worker pull write `FILE.opod` beside each file they fetch. A prune only ever considers files with a marker. Everything else on the volume is the owner's and is never touched, whatever it looks like.
- **The download lock.** A prune takes the same per-file lock a download takes, so a prune and a pull never race. Whoever gets the lock goes first.

## opod cache ls

What is cached, which entries opod fetched, their size and when each was last used.

| Flag        | Default            | Effect                   |
| ----------- | ------------------ | ------------------------ |
| `--dir DIR` | `$OPOD_MODELS_DIR` | The models directory.    |
| `--json`    | off                | A JSON array of entries. |

```bash
opod cache ls --dir /data/models
```

```text
Llama-3.2-3B-Instruct-Q4_K_M.gguf           1.9 GB  opod      last used 3h12m0s ago
Qwen-Qwen2.5-7B-Instruct@a09a354/ (snapshot, 14 files)    14.2 GB  opod      last used 26h4m0s ago
my-own-model.gguf                           4.1 GB  not ours  last used never recorded
```

One line per entry: the name, the size in GiB, `opod` or `not ours`, and the last use. A file pinned to a revision is named `<repo-slug>@<rev>/FILE` and listed by itself. A safetensors snapshot is **one** entry with the directory's total size, because an engine loads the whole directory. opod's own bookkeeping files (`*.opod`, `*.lock`, `*.partial-*`, `*.trash-*`) are not listed. A directory that is not a `<repo-slug>@<rev>` revision directory is not looked into.

### JSON fields

| Field                     | Meaning                                                                                                                                       |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `path`                    | Absolute path.                                                                                                                                |
| `file`                    | Name relative to `--dir`: `a.gguf`, `<repo-slug>@<rev>/a.gguf`, or `<repo-slug>@<rev>` for a snapshot.                                        |
| `repo`                    | The Hugging Face repo, from the marker.                                                                                                       |
| `size`                    | Bytes; for a snapshot, the sum of its files.                                                                                                  |
| `ours`                    | `true` when opod fetched it. Only these can be pruned. A snapshot is ours only when its manifest reads and **every** file in it has a marker. |
| `fetchedAt`, `lastUsedAt` | From the marker. A worker or a fetch that finds the file records a use.                                                                       |
| `revision`                | Set for anything under a revision directory.                                                                                                  |
| `snapshot`, `files`       | A snapshot directory, and how many files it holds.                                                                                            |

## opod cache prune

Remove cached entries that are opod's, that no one references, and that have not been used for a while. **A dry run unless you pass `--apply`.**

| Flag               | Default            | Effect                                                                                                                                                                           |
| ------------------ | ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--dir DIR`        | `$OPOD_MODELS_DIR` | The models directory.                                                                                                                                                            |
| `--keep a,b`       | —                  | Entries that must survive, comma-separated (below).                                                                                                                              |
| `--min-age D`      | `24h`              | Leave entries used more recently than this, so a rollback finds its weights warm.                                                                                                |
| `--target-free GB` | `0`                | Stop once the volume has this many GB free. `0` removes every prunable entry.                                                                                                    |
| `--sweep D`        | `24h`              | With `--apply`, also clear the leftovers of crashed pulls (temp files and locks nothing writes any more) older than this. `0` turns it off. Without `--apply` there is no sweep. |
| `--apply`          | off                | Actually delete.                                                                                                                                                                 |
| `--json`           | off                | One JSON result object.                                                                                                                                                          |

### What `--keep` matches

- A **bare file name** (`a.gguf`) keeps that file wherever it is cached: at the top and under every revision.
- A **path under `--dir`** (`org-model@rev/a.gguf`) keeps exactly that entry.
- A **snapshot** is kept by its directory name (`Qwen-Qwen2.5-7B-Instruct@a09a354`, bare or as a path) or by the path of any file inside it. Never by a bare file name, since every snapshot holds a `config.json`.

The manager computes this list: every file a plan, a job, an in-flight prefetch or a staged model version on this node references. `prune` trusts it.

### Rules

1. Only entries with opod's marker are considered. A file opod did not fetch is never deleted, whatever the disk pressure; the summary names it.
2. Entries used within `--min-age` and entries on the keep list are kept.
3. The least recently used entries go first.
4. With `--target-free`, the prune stops as soon as the volume has that much free.
5. Each removal takes the file's download lock. A file a pull holds is left for the next run. A lock whose holder died is taken over.
6. A safetensors snapshot goes **whole**, under every one of its files' locks, or stays whole. The manifest is removed first, so an engine that starts mid-prune pulls for itself instead of loading a directory that is losing files. One file in it that opod did not write leaves the whole directory alone.
7. A removal renames the file to `.trash-…` and then unlinks it, so a reader that opened it a moment earlier keeps reading.

```bash
opod cache prune --dir /data/models                                     # what would go
opod cache prune --dir /data/models --keep Qwen-Qwen2.5-7B-Instruct@a09a354 --apply
opod cache prune --dir /data/models --target-free 100 --min-age 72h --apply
```

```text
would remove Llama-3.2-3B-Instruct-Q4_K_M.gguf           1.9 GB (last used 31h0m0s ago)
would remove 1 item(s), 1.9 GB; kept 2 referenced or recent; left 1 file(s) this cache did not write (my-own-model.gguf)
dry run: pass --apply to delete
```

With `--apply`, `would remove` reads `removed`, the last line is gone, and a sweep that cleared anything says `swept N leftover(s) of crashed pulls` on stderr.

### JSON result

| Field                     | Meaning                                                     |
| ------------------------- | ----------------------------------------------------------- |
| `removed`                 | The entries removed, or that would be (same shape as `ls`). |
| `freedBytes`              | Bytes freed, or that would be.                              |
| `kept`                    | Entries kept because referenced or recent.                  |
| `skipped`                 | Files that are not opod's, by name.                         |
| `dryRun`                  | `true` without `--apply`.                                   |
| `totalBytes`, `freeBytes` | The volume holding the cache, measured where the prune ran. |
| `volumeErr`               | Why the volume could not be measured, when it could not.    |
| `swept`                   | Leftovers cleared by `--sweep`.                             |

> **A full node**
>
> On a node whose disk is full, the kubelet admits only pods of priority `system-cluster-critical` and above, so a prune job of normal priority cannot start on the node that needs it most. Give the prune job a priority class that is admitted under disk pressure.

## opod cache kv-prune

Bound a disk KV-cache tier: the directory an engine writes KV blocks to (the `kv_tier_fs` engine flag). The engine never deletes from it, so something must. A manager runs this beside the engine, for as long as the engine writes the directory.

| Flag         | Default    | Effect                                                                                                                                               |
| ------------ | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--dir DIR`  | —          | The tier directory. Required.                                                                                                                        |
| `--max-gb N` | —          | Cap on the tier's files, in GiB; decimals are allowed. Required. `0` removes everything but the `--keep` entries.                                    |
| `--keep a,b` | —          | Top-level entries of `--dir` that are never touched.                                                                                                 |
| `--every D`  | `0` (once) | Repeat at this idle interval until stopped (`SIGINT` or `SIGTERM`). While the tier grows or is being trimmed, the next pass follows within 1 second. |
| `--apply`    | off        | Actually delete.                                                                                                                                     |
| `--json`     | off        | One JSON object per pass.                                                                                                                            |

```bash
opod cache kv-prune --dir /data/kvtier/ep --max-gb 100                          # one dry pass
opod cache kv-prune --dir /data/kvtier/ep --max-gb 100 --every 10s --apply      # keep it bounded
```

```text
/data/kvtier/ep: 103.40 GiB in the tier; removed 812 file(s), 13.42 GiB (walk 41 ms, remove 220 ms)
```

How a pass works:

1. It walks `--dir` and counts only the tier's own files: `*.bin` (blocks), `*.tmp` (blocks being written) and `config.json`.
2. When the total is above `--max-gb`, it removes the oldest files first until the total is at **90 %** of `--max-gb`, so the next burst does not trip the cap at once.
   - From core v0.4.7, with `--every`, a pass also counts the growth since the previous pass as already written (at most half of `--max-gb`). It trims when the total plus that growth is above `--max-gb`, down to 90 % less the growth, so a tier that a burst keeps filling is trimmed ahead of it. The growth is measured from one pass to the next, so in core v0.4.7 a burst that starts while the pruner is idle (one pass every `--every`) is not trimmed ahead: on NFS, two writers took a tier capped at 0.85 GiB to 1.07 GiB before the first trim, 10 s after the burst began.
   - From core v0.4.8, while idle the loop also reads the volume's free space every second (one `statfs` call, not a walk) and runs a pass at once when it has dropped by a twentieth of `--max-gb`. The same two-writer burst then peaked at 0.95–1.08 × the cap in four runs. Another writer on the same volume only brings a pass forward.
   - From core v0.4.7, a pass lists up to 32 directories at once. On a network filesystem (NFS) each listing is a round trip, and vLLM puts almost every block in its own directory: a one-at-a-time pass took 3.7 s for 3,362 blocks on NFS, long enough for two writers to take a 1 GiB tier to 2.28 GiB.
3. Entries named in `--keep` are never touched.

With `--every`, a pass that removes nothing prints nothing (except with `--json`), and a failed pass prints `error: …` and the next pass tries again. A single pass that fails exits `1`.

JSON per pass: `dir`, `dryRun`, `usedBytes` (before the pass), `removed` (files), `freedBytes`, `totalBytes` and `freeBytes` (the volume), `volumeErr`, `walkMs`, `removeMs`. A pass much longer than `--every` is how a burst outruns the cap.

## Exit codes

| Code | Meaning                                                                                                                                                                        |
| ---- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `0`  | Done (or a dry run).                                                                                                                                                           |
| `1`  | An error: `error: …` on stderr.                                                                                                                                                |
| `2`  | No `--dir` and no `$OPOD_MODELS_DIR` (`error: --dir or OPOD_MODELS_DIR required`), or, for `kv-prune`, no `--dir` or no `--max-gb` (`error: --dir and --max-gb are required`). |

From core v0.4.6:

- Every message starts with `opod:`, and `kv-prune` names the flag it lacks (`needs --dir, the tier directory` or `needs --max-gb, the tier's cap in GiB`). An extra argument is a usage error.
- Sizes are labelled **GiB**, which is what they always were (bytes ÷ 2³⁰).
- `ls` on an empty cache says `(no weights cached in <dir>)`.
- `prune`'s dry run says it does not sweep crashed pulls; with `--apply` the sweep's count is on stdout with the summary, and a failed sweep is a warning.
- `kv-prune` on a directory that does not exist warns (`… does not exist — nothing to prune`) and still exits `0` with its result — a sweep may find a tier already gone. With `--every` it prints a start line, waits for the directory the engine creates (warning every 10 minutes while it is missing, so a mistyped `--dir` shows), and prints an idle pass at most once a minute.
- `--json` stays one object per line: a control plane reads the last line that starts with `{`.
