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

# magnet link

> Link a local directory to a Magnet workspace.

The `magnet link` command (alias: `magnet init`) connects the current directory to one of your Magnet workspaces. Subsequent CLI commands run from this directory (or any subdirectory) operate in the context of the linked workspace.

## Usage

```bash theme={null}
magnet link
```

If you belong to multiple workspaces, the CLI shows a picker. The selection is saved to `.magnet/project.json`.

## Options

| Option                   | Description                                         |
| ------------------------ | --------------------------------------------------- |
| `--workspace <idOrSlug>` | Workspace id or slug. Skips the interactive picker. |
| `--org <idOrSlug>`       | Alias for `--workspace`.                            |
| `--yes`                  | Skip confirmation prompts (for CI and scripts).     |

## Examples

Link non-interactively (for CI):

```bash theme={null}
magnet link --workspace my-team --yes
```

## The `.magnet` folder

> **Why do I have a folder named ".magnet" in my project?**
> The `.magnet` folder is created when you link a directory to a Magnet workspace.

> **What does the "project.json" file contain?**
> The ID of the linked Magnet workspace (`orgId`), plus its slug and name (`orgSlug`, `orgName`).

> **Should I commit the ".magnet" folder?**
> No, you should not share the `.magnet` folder with anyone. Upon creation, it is automatically added to your `.gitignore` file.

Like `.git`, the link is discovered by walking up from the current directory, so commands work from anywhere inside the linked project.
