
local-env-file-management
Tools to populate local .env files from 1password secrets.
- GitHub stars
- 7
Install
/plugin install local-env-file-management@claude-1passwordRun it inside Claude Code after adding the marketplace with /plugin marketplace add densom/claude-1password.
Contents
Discovered from sourceCommands 3
You are tasked with adding a new environment variable to the .env.1password template file and optionally creating or updating the corresponding secret in 1Password.
Instructions:
-
Parse arguments:
- First argument (required): The variable name (e.g.,
API_KEY) - Second argument (optional): Either:
- A 1Password reference like
op://Private/myapp/api_key - A value to be stored in 1Password
- If not provided, ask the user for input
- A 1Password reference like
- First argument (required): The variable name (e.g.,
-
Check for .env.1password: Look for the template file in the current working directory.
- If it doesn't exist, ask if the user wants to create it (and offer to run
/claude-1password:env-initif a.envexists)
- If it doesn't exist, ask if the user wants to create it (and offer to run
-
Check if variable already exists:
- If the variable name already exists in
.env.1password, ask if they want to update it - Show the current value/reference before updating
- If the variable name already exists in
-
Determine the 1Password reference:
Option A: If the second argument looks like a 1Password reference (
op://...):- Use it as-is
- Verify it's valid by trying
op read "reference"(optional, warn if it fails)
Option B: If the second argument is a value (not starting with
op://):- Ask the user for the 1Password item details:
- Vault name (default: "Private")
- Item name (suggest based on project or existing pattern)
- Field name (default: variable name in lowercase)
- Offer to create the item/field in 1Password using the CLI:
Or if the item exists, update it:op item create --category=password --title="item-name" \ --vault="vault-name" field-name="value"op item edit "item-name" --vault="vault-name" field-name="value" - Construct the reference:
op://vault/item/field
Option C: If no second argument provided:
- Ask the user whether they want to:
- Provide an existing 1Password reference
- Provide a value to store in 1Password
- Leave it as a placeholder for manual editing later
-
Update .env.1password:
- Add the new variable in the format:
VAR_NAME=op://vault/item/field - Optionally add a comment above it if the user wants to document it
- Maintain alphabetical order or append to the end (ask user preference)
- Add the new variable in the format:
-
Optionally update .env:
- Ask if they want to immediately sync to
.envby running/claude-1password:env-sync - Or just update
.env.1passwordfor now
- Ask if they want to immediately sync to
-
Output summary: Show the user:
- The variable that was added:
VAR_NAME=op://... - Whether it was also created/updated in 1Password
- Next steps (e.g., "Run
/claude-1password:env-syncto update your.envfile")
- The variable that was added:
Examples:
Example 1: Add with existing 1Password reference
/claude-1password:env-add NEW_API_KEY op://Private/myapp/new_api_key
Result in .env.1password:
NEW_API_KEY=op://Private/myapp/new_api_key
Example 2: Add with a new value
/claude-1password:env-add STRIPE_KEY sk_test_abc123
You would then:
- Ask for vault/item/field details (or use smart defaults)
- Create/update in 1Password
- Add to
.env.1passwordwith the generated reference
Example 3: Add placeholder for manual editing
/claude-1password:env-add DATABASE_PASSWORD
You would prompt for what to do, and potentially add:
DATABASE_PASSWORD=op://Private/myapp/database_password
Error Handling:
- If 1Password CLI is not installed or not authenticated, warn the user but still allow adding to
.env.1passwordas a placeholder - If variable name is invalid (contains spaces, special chars except
_), suggest a corrected name - If 1Password operation fails, show the error but still update the template file
You are tasked with creating a .env.1password template file from an existing .env file.
Instructions:
-
Read the .env file: If the user provided a path argument, use that path. Otherwise, look for
.envin the current working directory. -
Parse the file: Extract all environment variable key-value pairs. Ignore:
- Empty lines
- Lines starting with
#(comments) - Malformed lines without
=
-
Generate template: For each variable, create a line in the format:
VAR_NAME=op://vault-name/item-name/field-nameYou should:
- Keep the variable name exactly as it appears
- For the 1Password reference, suggest a sensible structure:
vault-name: Default to "Private" or ask the useritem-name: Use a descriptive name based on the project or variable contextfield-name: Use the variable name in lowercase or the actual field name in 1Password
Example transformation:
DATABASE_URL=postgresql://localhost:5432/mydb API_KEY=abc123secretBecomes:
DATABASE_URL=op://Private/project-secrets/database_url API_KEY=op://Private/project-secrets/api_key -
Add security header: Prepend or update the security comment to the top of the generated
.env.1passwordfile:# This file was auto-generated from .env.1password # DO NOT commit this file to version control # Generated on: [current date/time](Note the blank line after the header)
If the
.env.1passwordtemplate file already exists, check for the security header and add it if it does not exist. -
Preserve comments: Keep any comment lines from the original file to maintain documentation.
-
Write the template: Save the result as
.env.1passwordin the same directory as the source.envfile. -
Output summary: Show the user:
- How many variables were converted
- The path to the new
.env.1passwordfile - A reminder to update the 1Password references to match their actual vault structure
- Instructions: "Edit
.env.1passwordto update theop://references to match your 1Password vault, item, and field names. Then run/claude-1password:env-syncto generate your.envfile."
Error Handling:
- If the
.envfile doesn't exist, inform the user and ask if they want to create a new empty template - If
.env.1passwordalready exists, ask if they want to overwrite it
You are tasked with generating a .env file by resolving 1Password secret references from a .env.1password template file.
Prerequisites Check:
-
Verify 1Password CLI is installed: Run
op --versionto check if the 1Password CLI is available.- If not installed, inform the user to install it from https://developer.1password.com/docs/cli/get-started/
-
Verify 1Password CLI is authenticated: Run
op account listto check if the user is signed in.- If not authenticated, inform the user to run
op signinfirst
- If not authenticated, inform the user to run
Instructions:
-
Locate the template file: If the user provided a path argument, use that path. Otherwise, look for
.env.1passwordin the current working directory.- If
.env.1passworddoesn't exist, inform the user and suggest running/claude-1password:env-initfirst
- If
-
Check if .env already exists:
- If
.envalready exists, ask the user if they want to overwrite it - Consider backing up the existing
.envas.env.backupbefore overwriting
- If
-
Use op inject command: Use the 1Password CLI
op injectcommand to resolve all secret references in the template file and generate the.envfile.The basic command syntax is:
op inject -i .env.1password -o .envThe
op injectcommand will:- Automatically find all
op://vault/item/fieldreferences in the template - Resolve them by fetching the secrets from 1Password
- Replace the references with the actual secret values
- Preserve all comments, empty lines, and non-secret values exactly as they appear
- Handle multiple references on a single line
- Provide clear error messages if any references are invalid or inaccessible
- Automatically find all
If the user opted to overwrite the existing file, make sure to use the --force flag in the op command.
- Output summary: Show the user:
- Success message: "Successfully generated .env from .env.1password"
- The path to the generated
.envfile - Number of secret references that were resolved (count
op://occurrences in the template) - A reminder to add
.envto.gitignoreif not already present - Security reminder: "Remember to delete this file when no longer needed"
Example:
Template (.env.1password):
# Database configuration
DATABASE_URL=op://Private/myapp/database_url
API_KEY=op://Private/myapp/api_key
# Non-secret values can be stored directly
NODE_ENV=development
Command executed:
op inject -i .env.1password -o .env
Generated (.env):
# Database configuration
DATABASE_URL=postgresql://user:pass@localhost:5432/db
API_KEY=sk_live_abc123xyz789
# Non-secret values can be stored directly
NODE_ENV=development
Additional Options:
- Force overwrite: If you want to skip the overwrite confirmation, you can add the
--forceflag:op inject -i .env.1password -o .env --force - In-memory only: To output to stdout without writing a file (useful for verification):
op inject -i .env.1password - Different paths: You can specify any template and output paths:
op inject -i path/to/template -o path/to/.env
Error Handling:
- If
.env.1passworddoesn't exist, inform the user and suggest running/claude-1password:env-initfirst - If
.envalready exists, ask if they want to overwrite it - If
op injectfails, show the specific error message from the CLI and suggest solutions:- "not signed in": User needs to run
op signin - "item not found" or "vault not found": Check that the
op://references in.env.1passwordmatch actual items in 1Password - "field not found": Verify the field name exists in the 1Password item
- For any errors, show which reference(s) caused the problem to help the user debug
- "not signed in": User needs to run
- If the command succeeds but the output seems incorrect, suggest the user manually verify their 1Password references
Sponsors
Details
- Marketplace
- densom/claude-1password
- Source
- plugins/1password
- Author
- Dennis Somerville
- Category
- Development
- License
- MIT
- Keywords
- 1password, env, dotenv, secrets, local-development