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

# Cleaning and caches

> The three layers of cached state, and what each cleaning command removes.

There are three layers of cached state. Knowing which is which tells you what
each cleaning command does.

| Layer | Where it lives | What is in it | Who owns it |
| - | - | - | - |
| Environment | ProofPod, shared | Lean toolchain, Mathlib and its dependencies, fully built | ProofPod. Never deleted by anything you run. |
| Workspace build outputs | ProofPod, per workspace | Your project's `.lake/build`, plus dependencies that are not prebuilt | You |
| Local build outputs | Your machine | `.lake/` in your working tree, used by your editor | You |

## `pp lake clean`

Runs on **both** sides.

1. On your machine it runs `lake clean` with the arguments you gave. If Lake is
   not installed locally and you passed no package names, it removes
   `.lake/build` directly.
2. In the cloud it cleans your workspace.

If the project has no cloud workspace yet, or you are not signed in, only the
local half runs, and no sandbox is started.

### What a bare `lake clean` cleans in the cloud

Locally, `lake clean` with no arguments deletes the build directory of *every*
package in the workspace, Mathlib included, which is why it is usually followed
by a long `lake exe cache get`.

In the cloud that would be pure loss: prebuilt Mathlib would be deleted from the
sandbox and the next build would start compiling Mathlib from source. So a bare
`pp lake clean` is narrowed to the packages whose build outputs actually live in
your workspace:

* your project's own package, and
* any dependency that is not part of the prebuilt environment.

Prebuilt packages are left in place. With `--verbose` you can see the
narrowing:

```console theme={null}
$ pp --verbose lake clean
proofpod: cleaning demo; prebuilt packages are left in place
```

### Naming packages

If you name packages, the command runs exactly as written on both sides:

```console theme={null}
$ pp lake clean mathlib
```

In the cloud, the prebuilt Mathlib is a shared read-only image under a
per-sandbox scratch layer, so this can only remove Mathlib from the *current*
sandbox. ProofPod notices that a command altered a prebuilt package, retires
that sandbox, and your next command starts from the pristine prebuilt copy. You
cannot put yourself in the position of rebuilding Mathlib.

To clean one side only:

```console theme={null}
$ pp --local lake clean
$ pp --cloud lake clean
```

The exit code is non-zero if either side failed.

## `pp lake cache clean`

Also runs on both sides. It clears Lake's artifact cache locally and the
workspace's copy of it in the cloud.

## `pp workspace reset`

Deletes the whole cloud workspace: the synced copy of your sources, your build
outputs, and every dependency Lake cloned into it.

```console theme={null}
$ pp workspace reset
This deletes the cloud workspace formalization-3fa9c21b7e: the synced copy of your sources and all build caches in it.
Your local files are not touched. The next command re-syncs and rebuilds from scratch (Mathlib stays prebuilt).
Continue? [y/N]
```

Use it when you want a guaranteed-fresh build, or to remove a workspace you no
longer need. `pp workspace reset KEY` targets another workspace from
`pp workspace list`. Local files are never touched.

## Which one do I want?

| I want to… | Run |
| - | - |
| Rebuild my project from scratch, everywhere | `pp lake clean` |
| Rebuild in the cloud only, keep my editor's local build | `pp --cloud lake clean` |
| Free local disk space | `pp --local lake clean` |
| Start over completely in the cloud, including non-Mathlib dependencies | `pp workspace reset` |
| Get rid of a workspace for a project I deleted | `pp workspace reset KEY` |

## What cleaning never does

* It never deletes a prebuilt environment, and never leaves you compiling
  Mathlib from source.
* It never touches your source files.
* It never deletes a workspace other than the one you named.


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