Skip to main content
To manage 1Password Environments and their secrets from the command line, use the op 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). 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:
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 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.
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 with the Environment’s name or ID.
To get the result as JSON, add --format=json.

List Environments

To list the Environments you have access to, use op environment list.

Edit an Environment

To edit an Environment, use op environment edit with the Environment’s name or ID and the --name flag. The name is the only Environment property you can change.

Delete an Environment

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 with the Environment’s name or ID. Nothing is printed on success. The following example deletes the Environment you renamed in the previous step.

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.
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 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. To create a secret named DB_HOST and show its value by default:
To create a hidden secret from piped JSON:

Get a secret

To get one secret, use op 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.

List secrets

To list the secrets in an Environment, use op 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.

Edit a secret

To edit a secret, use op 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:
To change a secret’s value from piped JSON:

Delete a secret

Deleted secrets can’t be restored, and any integrations that use them stop working.
To delete a secret, use op environment secret delete with the secret’s name and the --environment flag. Nothing is printed on success.

Learn more