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

# Environment configuration as code

> Adopt an existing environment, preview YAML or JSON changes, and manage settings from Git.

Manage an [environment](https://docs.replicas.dev/features/environments.md) from YAML or JSON. Preview before applying. Declared settings become read-only in the app; unrelated settings stay editable. Terraform is not required.

## Apply a local file

Start with an environment you can write to. The file does not create environments; use the app or `replicas environment create` first.

Save `infra/development.yaml`:

```yaml theme={null}
environment:
  variables:
    APP_MODE: "development"
  systemPrompt: "Run relevant checks before opening a pull request."
  startHook: "echo 'Development workspace ready'"
```

From that checkout:

```bash theme={null}
replicas environment config preview "Development" --file ./infra/development.yaml
replicas environment config apply "Development" --file ./infra/development.yaml
replicas environment config get "Development"
```

Preview changes nothing. Apply shows the preview and asks for confirmation; `--yes` skips the prompt. Preview again afterward to check for no setting changes.

JSON uses the same wrapper:

```json theme={null}
{
  "environment": {
    "variables": { "APP_MODE": "development" },
    "startHook": "echo 'Development workspace ready'"
  }
}
```

## Link Git and use an infra pointer

Git reads a root `replicas.json`, `replicas.yaml`, or `replicas.yml`, in that order. Only the first existing filename is used. Keep one root entrypoint.

Put the `environment` block there, or point to a separate file:

```json theme={null}
{
  "infra": "./infra/development.yaml"
}
```

The target contains the same `environment` wrapper. Its path is relative to the entrypoint. Do not combine `infra` and `environment` in one entrypoint or chain pointers. Existing top-level repository hooks can remain beside `infra`.

Commit both files to the repository's default branch. The repository must be connected to the organization and attached to the environment.

```bash theme={null}
replicas environment config preview "Development" --repository acme/web
replicas environment config link "Development" --repository acme/web
```

Link previews, connects, and applies the file. The UI shows its resolved path and applied commit. To move a locally managed environment to Git, commit its configuration, run `replicas environment config disconnect "Development"` to release its file source, then preview and link the repository. Disconnecting keeps the current settings.

After merging a change to the default branch, check the source in the UI and review its changes, or run:

```bash theme={null}
replicas environment config preview "Development"
replicas environment config sync "Development"
```

By default, a push alone does not apply settings. Sync previews the linked source and asks before applying. Non-default branches are not the Git source. Disconnect Git management before applying an unrelated local file.

To apply changes automatically, turn on **Apply Git changes automatically** in the environment's General settings, or run:

```bash theme={null}
replicas environment config auto-apply "Development" on
```

Merges and direct pushes to the default branch queue an update, including changes to an `infra` target. Invalid configuration or missing secrets preserve the last applied settings and show an error. Turn automatic apply off to return to manual review:

```bash theme={null}
replicas environment config auto-apply "Development" off
```

Disconnecting also stops automatic updates. Local-file sources always require a CLI apply.

## Ownership and removal

| Situation | Result |
| - | - |
| A setting is declared | The file owns it; direct UI/API edits to that setting are blocked. |
| A setting was never declared | It remains managed normally in the app. |
| A previously managed variable, MCP, file, or skill is removed | Apply removes that managed item. Unmanaged items remain. |
| A managed scalar or inherited setting is omitted later | Preview shows removal of the override; normal inheritance/default behavior resumes. |
| A required secret or plugin name is removed | Only the requirement is removed, not its stored secret or connected account. |
| Configuration is disconnected | Applied settings are preserved and ownership locks released. |

```bash theme={null}
replicas environment config disconnect "Development"
```

Always preview removals. Parent and child hooks are additive: the child's `startHook` does not replace the parent's script. `inheritRepositories: true` inherits the parent's repository list and cannot be combined with `repositories`.

This is environment inheritance, not file inheritance. An `infra` pointer selects one file; it does not merge files.

## Two hook locations

| Location | Meaning |
| - | - |
| Top-level `startHook` / `warmHook` | [Repository hooks](https://docs.replicas.dev/features/workspaces/repository-configuration.md), read at setup time. Start hooks use a `commands` object. |
| `environment.startHook` / `environment.warmHook` | Environment scripts saved by configuration apply. Both use script strings. |

Both can run. Applying an environment block does not suppress top-level repository hooks.

`environment.setupSourceMode` selects execution sources:

| Value | Hooks that run |
| - | - |
| `app_and_repo` | Parent environment, child environment, then repository hooks. |
| `repo_only` | Repository hooks only; environment hooks are skipped and their app editors locked. |
| `app_only` | Environment hooks including parents; repository hooks are skipped. |

“App” includes environment hooks managed through configuration. Do not select `repo_only` to run `environment.startHook`: it disables environment hooks. The selected environment's mode controls its whole chain. See [setup sources](https://docs.replicas.dev/features/environments.md#setup-sources).

## Secrets and MCP references

Store sensitive values in [Environment Variables](https://docs.replicas.dev/features/environments.md#variables), then reference names:

```yaml theme={null}
environment:
  requiredSecrets:
    - SERVICE_TOKEN
  mcps:
    internal-service:
      transport: http
      config:
        url: https://mcp.example.com
        headers:
          Authorization:
            env: SERVICE_TOKEN
            prefix: "Bearer "
```

Missing required secrets block apply. A name cannot be in both `variables` and `requiredSecrets`. Secrets can be inherited; removing a requirement does not delete the value.

Do not commit secret values in variables, file contents, scripts, or literal MCP headers/environment values. `requiredPlugins` checks existing connections; it does not connect accounts or perform OAuth sign-in.

## Supported fields

All fields below are optional inside `environment`. Unknown fields are rejected.

| Field | Format / behavior |
| - | - |
| `systemPrompt` | Environment instruction string, appended after inherited instructions. |
| `warmHook`, `startHook` | Script strings; additive across parent and child. |
| `setupSourceMode` | `app_and_repo`, `repo_only`, `app_only`, or `null` to reset to the default `app_and_repo`. |
| `variables` | Ordinary variable names mapped to string values. |
| `requiredSecrets` | List of separately stored secret names. |
| `repositories` | List of connected `owner/repo` names or repository IDs. |
| `inheritRepositories` | Boolean; `true` inherits the parent's repository list. |
| `workspaceSize` | Supported workspace size, such as `auto`. |
| `memory` | `{ read: boolean, write: boolean }`; either key optional, `null` resets the override. |
| `gpu`, `mobileTesting` | Boolean override, or `null` to inherit/reset. |
| `defaultSkills` | `replicas_agent.enabled` and an `abilities` map for built-in agent preferences. Mandatory abilities cannot be disabled; `null` resets the override. |
| `files` | `~/...` paths mapped to `{ content, name? }`; max 65,536 characters of content per file. |
| `skills` | Skill slugs mapped to `{ source, name? }`. |
| `mcps` | Server names mapped to `{ transport, config }`; transports `stdio`, `http`, `sse`. |
| `requiredPlugins` | List of supported plugin IDs that must already be connected. |

For `stdio` MCPs, config contains `command`, optional `args`, and `env`. For HTTP/SSE, it contains `url`, optional `auth`, and `headers`. Environment/header values can be strings or `{ env: "NAME", prefix: "optional prefix" }` references.

Environment creation, names, parent selection, and automation definitions are outside this block. Use the app or [API](https://docs.replicas.dev/features/api.md) for lifecycle actions and [Automations](https://docs.replicas.dev/features/automations.md) for triggers.

## Verify a new workspace

Wait for pending builds to finish, then start a new workspace. Verify variables, files, tools, and hook output there. Running workspaces do not receive every change in place; the environment's [status](https://docs.replicas.dev/features/environments.md#status) tells you what new workspaces get.

If preview is blocked, fix the listed secrets, plugin connections, repository access, or invalid settings and retry. A saved Git change is not proof it was applied: inspect `replicas environment config get` and the UI's configuration source.

## Migrate an existing environment

> [!TIP]
>
> Ask the Replicas agent to do this for you: “Move my existing Development environment into YAML configuration, preserving its current settings and inheritance. Show me the preview before applying.”

Export its own settings first, preserving [inheritance](https://docs.replicas.dev/features/environments.md#forks) instead of copying parent values into the child.

Get its UUID from `replicas environment list --json`. Set `ENVIRONMENT_ID` to that ID and `REPLICAS_API_KEY` to an organization or personal [API key](https://docs.replicas.dev/features/api.md#authenticate) with write access to the environment. Save the export locally:

```bash theme={null}
curl --fail --silent --show-error \
  -H "Authorization: Bearer $REPLICAS_API_KEY" \
  "https://api.replicas.dev/v1/environments/$ENVIRONMENT_ID/config-source/export" \
  > environment-export.json
```

The response contains `environment` and `warnings`. Read every warning before adoption. With `jq` installed:

```bash theme={null}
jq '{environment: .environment}' environment-export.json > development.json
replicas environment config preview "$ENVIRONMENT_ID" --file ./development.json
replicas environment config apply "$ENVIRONMENT_ID" --file ./development.json
```

Review the exported file before committing. Sensitive variables become required-secret names, and inherited settings stay inherited. Hidden file contents, locked ordinary variables, and newly exported MCPs with hidden literal values can stay unmanaged with warnings. Previously declared file/MCP literals are preserved, so an export of an already managed environment can retain those contents.

Initial preview can list unchanged settings as **adopted**: the file is taking ownership. Check for unintended value changes, apply, then repeat preview and inspect the UI. Keep intermediate exports out of Git if they contain values you do not intend to publish.


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