---
title: Fork a luna
description: Copy one luna, as it is now or as it was at an earlier moment, to a new key or into another environment with luna fork.
related:
  - /develop/restore-to-an-earlier-moment
  - /develop/manage-environments
  - /develop/export-and-import
---

Some problems only show up with one customer's real data, and you cannot debug on their luna while they use it. A fork copies that luna into a new one that you can change freely, while the original carries on untouched.

## Fork to a new key

[`luna fork`](/cli/fork) takes the luna type, the key of the luna to copy, and the key of the new luna. Keys are JSON.

```bash
luna fork List --key '{"id":"groceries"}' --to-key '{"id":"groceries-copy"}'
```

The new luna starts with the original's data and files, and from then on the two go their own ways. Changes to one never reach the other.

The new key must not belong to a luna that exists. A fork onto a key that is taken is refused.

Forking reads the original and writes the copy. The token or login you use needs `data:read` where the luna is and `data:write` where the copy goes.

## Fork as of an earlier moment

Pass `--at` to copy the luna as it was at a moment in the past. It takes the same forms as `luna restore --to`, such as `"2h ago"` or `2026-11-30T09:00:00Z`.

```bash
luna fork List --key '{"id":"groceries"}' --to-key '{"id":"groceries-before"}' --at "2h ago"
```

This reads an old state without changing the luna itself, unlike `luna restore`. Luna keeps 30 days of history to fork from, as [Restore to an earlier moment](/develop/restore-to-an-earlier-moment) explains.

## Fork into another environment

Pass `--to-env` to put the copy in another environment of the same project. The copy keeps the same key unless you pass `--to-key` too.

```bash
luna fork List --key '{"id":"groceries"}' --to-env dev
```

The environment you copy into must run code that defines the same luna type. Deploy to it first if it has none.

Pass `--to-env` and `--to-key` together to give the copy a new key in the other environment. A fork with neither is refused, since the copy would land on the original.

:::note
A fork into your own environment is how you debug against production data. Treat the copy with the same care, since it holds the same customer's data.
:::

## What comes with the copy

A fork copies what the luna holds, and none of what ties it to the outside world.

| Part | In the copy |
| --- | --- |
| Tables and files | Copied as they were at that moment |
| Schedules | None, unless you pass `--schedules`. Then they carry on, without catching up on runs they missed |
| Messages waiting or queued | None |
| Connections and stream subscriptions | None |
| Durable runs under way | Cancelled |
| Sandboxes | Copied as they were last saved |

A sandbox keeps no history, so a fork as of an earlier moment still gets its sandboxes as last saved. If they cannot be copied, the luna is still forked and the command says why. [Run a sandbox](/files-and-code/run-a-sandbox) explains what a sandbox saves.

## Next steps

- [Restore to an earlier moment](/develop/restore-to-an-earlier-moment) rewinds the luna itself instead of copying it.
- [Export and import](/develop/export-and-import) copies many lunas at once, or takes them out of Luna.
- [Browse a luna's data](/develop/browse-a-lunas-data) reads and edits the copy's rows.
