Requirements
Before you can use the VS Code extension, you’ll need to:- Install 1Password for Mac, Windows, or Linux.
- Install the latest version of 1Password CLI.
- Integrate 1Password CLI with the 1Password app.
Installation
You can install the 1Password for VS Code extension through the VS Code Marketplace or GitHub.- VS Code Marketplace
- 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
- Open the Command Palette.
- Enter
1Password: Choose accountto select a 1Password account. - Enter
1Password: Choose vaultto select a vault.
Extension settings
1Password for VS Code has a few settings you can configure. To access the 1Password for VS Code settings:- Go to Code > Preferences > Settings.
- Scroll to or search for 1Password.
| Name | Setting ID | Default Value | Details |
|---|---|---|---|
| Items: Cache Values | 1password.items.cacheValues | true | Use CLI cache when performing operations. Learn more about caching. |
| Items: Password Recipe | 1password.items.passwordRecipe | "letters,digits,symbols,32" | The recipe to use when generating passwords. Learn more about password recipes. |
| Items: Use Secret References | 1password.items.useSecretReferences | true | Use secret reference syntax for storing and retrieving values. Learn more about secret references. |
| Editor: Suggest Storage | 1password.editor.suggestStorage | true | Suggest storing a value when it looks like a secret. |
| Debug: Enabled | 1password.debug.enabled | false | Log 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
- Detect secrets
- Get values from 1Password
- Create secrets
- Preview secret references
- Open secrets in 1Password
Save in 1Password
You can use the 1Password extension to save items in 1Password from code in your document:- Select an exposed secret in a file.
- Open the Command Palette .
- Enter
1Password: Save in 1Password. - Provide a name for the item.
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
.envfiles for keywords to make an educated guess if the value is a secret.
Get values from 1Password
The 1Password for VS Code extension allows you to use values that already exist in 1Password in your code:- Open the Command Palette .
- Enter
1Password: Get from 1Password. - Enter the item name or UUID.
- Select the field to use.
Create secrets
You can create secrets for your project from VS Code:- Place your cursor in the document.
- Open the Command Palette .
- Type
1Password: Generate passwordin the Command Palette. - Enter a name for your item.
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:- 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).
- 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.