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

# Manage Environments and secrets

To manage [1Password Environments](https://www.1password.dev/environments.md) and their secrets from the command line, use the [`op environment`](https://www.1password.dev/cli/reference/management-commands/environment) commands. You can create, get, list, edit, and delete Environments and the secrets they contain.

Every command accepts either the Environment's name or its [unique identifier (ID)](https://www.1password.dev/environments/programmatic-access.md#get-an-environments-id). If two Environments share a name, use the ID. We also recommend the ID in scripts, because it doesn't change when an Environment is renamed.

## Requirements

Before you can use 1Password CLI to manage Environments, you'll need to:

* [Sign up for 1Password](https://1password.com/pricing/password-manager)
* [Install 1Password CLI](https://www.1password.dev/cli/get-started.md#step-1-install-1password-cli) version `2.43.0` or later
* Sign in to 1Password CLI with the [1Password desktop app integration](https://www.1password.dev/cli/get-started.md#step-2-turn-on-the-1password-desktop-app-integration), or [authenticate with a service account](https://www.1password.dev/service-accounts/use-with-1password-cli.md#get-started)

> [!NOTE]
>
> Service accounts can only use the Environments you grant them access to, and need write access to an Environment to manage its secrets. A service account can only edit or delete Environments it created.

## Manage Environments

The examples in this section create an Environment named `Staging`, then refer to it by its ID. Replace `6ijsqfxvdxlwjcpsx7yrzs3tka` with your Environment's ID.

### Create an Environment

To create an Environment, use [`op environment create`](https://www.1password.dev/cli/reference/management-commands/environment#environment-create) with a name. 1Password CLI returns the new Environment's name, ID, content version, and when it was created and last updated. Copy the ID to use in the next steps.

```shell theme={null}
op environment create Staging
```

You can create more than one Environment with the same name. To tell them apart in other commands, use the ID.

### Get an Environment

To get an Environment's details, use [`op environment get`](https://www.1password.dev/cli/reference/management-commands/environment#environment-get) with the Environment's name or ID.

```shell theme={null}
op environment get 6ijsqfxvdxlwjcpsx7yrzs3tka
```

To get the result as JSON, add `--format=json`.

### List Environments

To list the Environments you have access to, use [`op environment list`](https://www.1password.dev/cli/reference/management-commands/environment#environment-list).

```shell theme={null}
op environment list
```

### Edit an Environment

To edit an Environment, use [`op environment edit`](https://www.1password.dev/cli/reference/management-commands/environment#environment-edit) with the Environment's name or ID and the `--name` flag. The name is the only Environment property you can change.

```shell theme={null}
op environment edit 6ijsqfxvdxlwjcpsx7yrzs3tka --name "Staging US"
```

### Delete an Environment

> [!WARNING]
>
> Deleted Environments and the secrets they contain can't be restored, and any integrations that use them stop working.

To delete an Environment, use [`op environment delete`](https://www.1password.dev/cli/reference/management-commands/environment#environment-delete) with the Environment's name or ID. Nothing is printed on success.

The following example deletes the Environment you renamed [in the previous step](#edit-an-environment).

```shell theme={null}
op environment delete 6ijsqfxvdxlwjcpsx7yrzs3tka
```

## Manage secrets

The examples in this section refer to an Environment by its ID. Replace `blgexucrwfr2dtsxe2q4uu7dp4` with your Environment's ID. Specify the Environment with the `--environment` flag, and the secret by name. A secret's name must start with a letter or underscore and contain only letters, digits, and underscores.

> [!CAUTION]
>
> Command arguments can be visible to other processes on your machine. To set a sensitive value, pipe it to the command as JSON instead of using the `--value` flag.

### Create a secret

To add a secret to an Environment, use [`op environment secret create`](https://www.1password.dev/cli/reference/management-commands/environment#environment-secret-create) with the secret's name and the `--environment` flag. New secrets are hidden by default. To create a secret whose value is shown by default, add `--concealed=false`. See [Secret visibility](https://www.1password.dev/environments/programmatic-access.md#secret-visibility).

To create a secret named `DB_HOST` and show its value by default:

```shell theme={null}
op environment secret create DB_HOST --value db.internal.example.com --concealed=false --environment blgexucrwfr2dtsxe2q4uu7dp4
```

To create a hidden secret from piped JSON:

```shell theme={null}
echo '{"value": "<value>"}' | op environment secret create API_KEY - --environment blgexucrwfr2dtsxe2q4uu7dp4
```

### Get a secret

To get one secret, use [`op environment secret get`](https://www.1password.dev/cli/reference/management-commands/environment#environment-secret-get) with the secret's name and the `--environment` flag. 1Password CLI returns the secret's name, value, and whether it's hidden. The value of a hidden secret is withheld unless you add `--reveal`.

```shell theme={null}
op environment secret get API_KEY --environment blgexucrwfr2dtsxe2q4uu7dp4 --reveal
```

### List secrets

To list the secrets in an Environment, use [`op environment secret list`](https://www.1password.dev/cli/reference/management-commands/environment#environment-secret-list) with the Environment's name or ID. Add `--reveal` to include the values of hidden secrets, and `--format=dotenv` to get output you can save as a `.env` file.

```shell theme={null}
op environment secret list blgexucrwfr2dtsxe2q4uu7dp4 --reveal --format=dotenv
```

### Edit a secret

To edit a secret, use [`op environment secret edit`](https://www.1password.dev/cli/reference/management-commands/environment#environment-secret-edit) with the secret's name, the `--environment` flag, and at least one of `--name`, `--value`, or `--concealed`. Anything you don't specify is left unchanged.

To rename a secret:

```shell theme={null}
op environment secret edit API_KEY --name SERVICE_API_KEY --environment blgexucrwfr2dtsxe2q4uu7dp4
```

To change a secret's value from piped JSON:

```shell theme={null}
echo '{"value": "<newValue>"}' | op environment secret edit SERVICE_API_KEY - --environment blgexucrwfr2dtsxe2q4uu7dp4
```

### Delete a secret

> [!WARNING]
>
> Deleted secrets can't be restored, and any integrations that use them stop working.

To delete a secret, use [`op environment secret delete`](https://www.1password.dev/cli/reference/management-commands/environment#environment-secret-delete) with the secret's name and the `--environment` flag. Nothing is printed on success.

```shell theme={null}
op environment secret delete SERVICE_API_KEY --environment blgexucrwfr2dtsxe2q4uu7dp4
```

## Learn more

* [`op environment` reference documentation](https://www.1password.dev/cli/reference/management-commands/environment)
* [Rotate a secret in an Environment](https://www.1password.dev/cli/rotate-environment-secret.md)
* [Programmatically access 1Password Environments](https://www.1password.dev/environments/programmatic-access.md)
* [Manage Environments and secrets using 1Password SDKs](https://www.1password.dev/sdks/environments.md)
* [1Password Environments](https://www.1password.dev/environments.md)


## Related topics

- [Rotate a secret in an Environment](https://www.1password.dev/cli/rotate-environment-secret.md)
- [Programmatically access 1Password Environments](https://www.1password.dev/environments/programmatic-access.md)
- [Tutorial: Rotate a secret in a 1Password Environment on a schedule](https://www.1password.dev/sdks/tutorials/rotate-environment-secret.md)
