# lpm hosts (/docs/infra/hosts)



```bash
lpm hosts clean
```

Removes LPM CLI-managed hosts-file blocks left by local-domain development runs. `lpm dev` normally adds and removes its own project-scoped block for hosts outside `localhost` / `*.localhost`; `lpm hosts clean` is the explicit cleanup escape hatch for interrupted sessions or old orphaned blocks.

## Examples [#examples]

```bash
lpm hosts clean        # prompt before removing LPM CLI-managed blocks
lpm hosts clean --yes  # remove without prompting
lpm hosts clean --json # machine-readable result
```

The command only removes complete blocks that LPM CLI created:

```text
# >>> lpm:project-... >>>
127.0.0.1 app.test
# <<< lpm:project-... <<<
```

It preserves unmanaged hosts-file lines, writes the first backup to `~/.lpm/hosts.bak`, and rejects malformed unterminated LPM CLI blocks instead of guessing what to delete. In non-interactive shells, pass `--yes`; otherwise cleanup aborts before mutation.

If the system hosts file needs elevated permission, LPM CLI re-runs its hosts-file helper through `sudo` on Unix or asks for Administrator elevation through UAC on Windows after consent. If elevation is cancelled or unavailable, the command fails before guessing at a fallback.

## Flags [#flags]

| Flag     | Effect                                                                      |
| -------- | --------------------------------------------------------------------------- |
| `--yes`  | Confirm cleanup without an interactive prompt                               |
| `--json` | Emit `{ success, cleaned, removedBlocks, hostsFile, backupPath }` on stdout |

## See also [#see-also]

* [`lpm dev`](/docs/dev/dev) - registers local-domain routes and session hosts entries
* [`lpm proxy`](/docs/infra/proxy) - local-domain proxy daemon
