Skip to main content

1Password for VS Code

1Password for VS Code provides you with a set of tools to integrate your development workflow with 1Password, powered by 1Password CLI.

Requirements

Before you can use the VS Code extension, you'll need to:

Installation

You can install the 1Password for VS Code extension through the VS Code Marketplace or GitHub.

The best way to install the 1Password for VS Code extension is through the VS Code Marketplace because it keeps the extension up to date automatically.

Install from the Marketplace

After installation, the extension prompts you to choose a 1Password account and vault.

caution

You must select a 1Password account and vault to use the extension's features.

You can select an account and vault later through the Command Palette :

  1. Open the Command Palette.
  2. Enter 1Password: Choose account to select a 1Password account.
  3. Enter 1Password: Choose vault to select a vault.

Extension settings

1Password for VS Code has a few settings you can configure. To access the 1Password for VS Code settings:

  1. Go to Code > Preferences > Settings.
  2. Scroll to or search for 1Password.

The following table lists the extension settings.

NameSetting IDDefault ValueDetails
Items: Cache Values1password.items.cacheValuestrueUse CLI cache when performing operations. Learn more about caching.
Items: Password Recipe1password.items.passwordRecipe"letters,digits,symbols,32"The recipe to use when generating passwords. Learn more about password recipes.
Items: Use Secret References1password.items.useSecretReferencestrueUse secret reference syntax for storing and retrieving values. Learn more about secret references.
Editor: Suggest Storage1password.editor.suggestStoragetrueSuggest storing a value when it looks like a secret.
Debug: Enabled1password.debug.enabledfalseLog debugger data. Reload required.

Feature

The best defense against secrets leaking from your code is for them not to be in your code to start with. To help with this, we've introduced secret references, and 1Password for VS Code is built with them in mind. Learn more and read further down to see how we're making it easy to use secret references in VS Code.

By default, all operations use secret references when retrieving and storing item fields. If you'd rather not use secret references, you can turn off the "Items: Use Secret References" setting to instead insert or keep the raw field values.

You can use the 1Password VS Code plugin to:

Save in 1Password

You can use the 1Password extension to save items in 1Password from code in your document:

  1. Select an exposed secret in a file.
  2. Open the Command Palette .
  3. Enter 1Password: Save in 1Password.
  4. Provide a name for the item.

The extension prompts you to fill out the item name and a field from each selection. It automatically tries to infer the field label if it looks like an email, URL, or credit card.

After creating the item (and saving it in 1Password), the extension replaces the selection with a secret reference pointing to that item and field.

tip

You can save multiple items at the same time by selecting more than one item in the file before opening the Command Palette . Learn more about multiple selections in VS Code .

Detect secrets

1Password for VS Code automatically watches for bits of code that look like secrets and offers to store them in 1Password. The behavior varies slightly between regular files and .env files:

  • It checks for strings that match known secret patterns across all regular files.
  • It inspects .env files for keywords to make an educated guess if the value is a secret.

When the extension finds a match, it displays a "Save in 1Password" CodeLens above the line that you can click to save the secret in 1Password.

You can control this feature with the "Editor: Suggest Storage" setting.

Get values from 1Password

The 1Password for VS Code extension allows you to use values that already exist in 1Password in your code:

  1. Open the Command Palette .
  2. Enter 1Password: Get from 1Password.
  3. Enter the item name or UUID.
  4. Select the field to use.

The extension inserts a secret reference pointing to that item and field.

tip

Already know the vault, item, and field you want to use? Start typing secret reference or op://. The extension provides a code snippet for you to fill out the individual parts of a secret reference.

Create secrets

You can create secrets for your project from VS Code:

  1. Place your cursor in the document.
  2. Open the Command Palette .
  3. Type 1Password: Generate password in the Command Palette.
  4. Enter a name for your item.

The 1Password VS Code extension creates the item with a randomly generated password and inserts a secret reference in the document pointing to that item and field.

tip

You can use the "Editor: Password Recipe" setting to customize the recipe 1Password for VS Code uses to generate passwords.

Preview secret references

1Password for VS Code analyzes open documents and looks for secret references, underlining each one it finds. It also allows you to preview individual secret references or load the secret reference values in a file.

To inspect the details of a secret reference:

  1. Hover your cursor over the secret reference. The secret reference details appear in a VS Code CodeLens .

The CodeLens window only displays non-sensitive information about the secret, like the creation date. It doesn't show values of sensitive fields (such as passwords and SSH keys).

To preview what a file looks like with its secret references converted to real values:

  1. Select the unlock icon () found in the top-right of a document.

This opens an unsaved copy of your document with the secret references replaced with real values, which you can then save or delete.

tip

You can also show a file's secrets through the Command Palette using the "1Password: Preview with secrets" command.

Open secrets in 1Password

You can open a secret reference in the 1Password application by holding Option , then selecting the secret reference.

Alternatively, you can hover your cursor over the secret reference, then select Follow link in the CodeLens window.

Contributing and feedback

1Password for VS Code is an open source project.

If you discover a problem or want to share feedback, open a GitHub issue.

Everyone is welcome to contribute to the extension. Refer to the contribution guidelines for more information.

Was this page helpful?