# The CLI from agents

URL: https://skywake.dev/docs/agents/cli

Give each agent a fork and a folder, then merge what worked.

When your agents run shell commands, give each one its own fork of the disk and a folder to work in. When an agent's work is good, merge its fork back. Add `--json` to every command whose output a program reads.

```bash tab="CLI"
echo "retries = 3" | skywake write app/config.toml

skywake fork app agent-1 --json
skywake download app@agent-1 ./agent-1 --json

echo "retries = 5" > agent-1/config.toml
echo "# Notes" > agent-1/NOTES.md

skywake upload ./agent-1 app@agent-1 -m "Raise retries" --json
skywake diff app@agent-1 --json
skywake merge app@agent-1 --json
skywake destroy app@agent-1 --yes --json
```

## One fork per agent [#one-fork-per-agent]

When each agent has its own fork, no agent ever waits for another. [`skywake fork app agent-1`](/reference/cli/fork) makes the fork instantly, however big the disk is. Then the agent works in one of three ways:

- **A folder.** [`download`](/reference/cli/download) the branch, let the agent work in the folder, then [`upload`](/reference/cli/upload) it as one commit. This works anywhere, macOS included, with nothing but an API key.
- **File commands.** `skywake read app@agent-1/src/app.ts`, `write`, `delete`, `grep`, `find` and `query` work on the branch directly, with no folder.
- **A mount.** On Linux, [`skywake mount`](../filesystem/mount.mdx) serves the branch as a live folder that saves itself.

Agents that don't run shell commands can use the [MCP server](./mcp.mdx), or the [bash shell](./bash.mdx) from TypeScript.

## Download and upload [#download-and-upload]

- `download app@agent-1 ./dir` writes every file of the branch into the folder. `--at` downloads an older commit.
- `upload ./dir app@agent-1 -m MESSAGE` saves the folder's files as one commit. Files that didn't change make no change. Files you removed from the folder are not deleted on the branch: delete them with `skywake delete app@agent-1/PATH`.
- `.git` is left out of an upload.

A `write` key is enough for all of this. Narrow it to one disk with `skywake keys create --role write --only app`.

## Output for scripts [#output-for-scripts]

`--json` prints JSON instead of text, on every command:

| Command              | JSON                                                |
| -------------------- | --------------------------------------------------- |
| `fork`               | `{ "forked": "app@agent-1", "from": "app" }`        |
| `download`, `upload` | `{ "commit": "…" }`                                 |
| `write`, `delete`    | `{ "commit": "…", "changed": true }`                |
| `diff`               | `[{ "path": "config.toml", "change": "modified" }]` |
| `merge`              | `{ "commit": "…", "conflicts": [] }`                |
| `destroy`            | `{ "destroyed": "app@agent-1" }`                    |

A failed command exits non-zero and prints the error, with a hint on how to fix it. That includes a [merge with conflicts](../filesystem/diff-and-merge.mdx#merge), which prints `conflict: PATH` for each path and saves nothing. `merge --dry-run` reports the conflicts without merging.

`destroy` asks before it deletes anything. An agent has no terminal to answer, so pass `--yes`.

## Settings [#settings]

| Setting     | Flag        | Env var           |
| ----------- | ----------- | ----------------- |
| key         | `--key`     | `SKYWAKE_API_KEY` |
| API         | `--url`     | `SKYWAKE_URL`     |
| environment | `--env`     | `SKYWAKE_ENV`     |
| profile     | `--profile` | `SKYWAKE_PROFILE` |
| store       | `--local`   | `SKYWAKE_STORE`   |

Give an agent its own key in `SKYWAKE_API_KEY` rather than running `skywake login` on its machine. `--local[=DIR]` works on a bucket or folder with no server; see [branches](../filesystem/branches.mdx#with-no-server).

## Next [#next]

<Cards>
  <Card href="../filesystem/branches.mdx" />
  <Card href="../filesystem/diff-and-merge.mdx" />
  <Card href="/reference/cli" />
</Cards>