Skip to content

kylebrodeur/1password-ssh-setup / packages/pi-1password/skills/1password-env

1password-env

Unverified

1Password environment management for AI agents and development. Load secrets as environment variables from 1Password, supporting .env and .env.1pass formats. Use when configuring API keys, tokens, or secrets for AI models, CI/CD, or local development.

1Password Environment Skill

Setup

Prerequisites

  1. 1Password CLI (op)

    # macOS
    brew install 1password-cli
    
    # Linux/WSL
    # Download from: https://1password.com/downloads/command-line/
    
  2. 1Password Service Account (required for non-interactive use)

  3. Reload shell

    source ~/.zshrc
    
  4. Verify authentication

    op account list
    

Install to Pi (if using Pi coding agent)

# Copy extension to Pi
mkdir -p ~/.pi/agent/extensions
cp extensions/1password.ts ~/.pi/agent/extensions/

# Reload Pi
reload

Environment File Formats

.env (Standard format)

# Non-sensitive variables
KEY=value
API_KEY=your-api-key

# Or with 1Password references
OPENAI_API_KEY=op://Private/API-Keys/openai

.env.1pass (1Password references)

# Format: VAR="op://vault/item/field"
OPENAI_API_KEY="op://Private/API-Keys/openai"
DATABASE_URL="op://Work/Database/prod"

Supported Formats for AI Agents

# Google AI
GOOGLE_GENERATIVE_AI_API_KEY=op://Private/API-Keys/google-ai

# Anthropic
ANTHROPIC_API_KEY=op://Private/API-Keys/anthropic

# OpenAI
OPENAI_API_KEY=op://Private/API-Keys/openai

# GitHub
GITHUB_TOKEN=op://Personal/GitHub/token

Pi .env Support

Supported Locations

  1. ~/.pi/.env - Pi-level config (loaded first)
  2. ~/.config/op-ssh/.env.1pass - User-level
  3. ./.env.1pass - Project-level (overrides user)

Pi Commands

/op-status

Check 1Password authentication and loaded environment variables.

/op-env

Load project environment from ./.env.1pass.

  • Arguments: optional file name (default: .env.1pass)
  • Autocomplete: .env.1pass, .env.local.1pass, etc.

/op-env-user

Load user-level environment from ~/.config/op-ssh/.env.1pass.

/op-get op://...

Get a specific secret and copy to OP_LAST_SECRET env var.

/op-create-env [filename]

Create a new project-level environment file with template.

Default: .env.1pass (if no filename provided)

Example:

/op-create-env              # Creates ./.env.1pass
/op-create-env .env.local   # Creates ./.env.local.1pass
/op-create-env .env.test    # Creates ./.env.test.1pass

Template includes common API keys:

  • GITHUB_TOKEN
  • OPENAI_API_KEY
  • ANTHROPIC_API_KEY

/op-add-item VAR_NAME op://... [--global]

Add or update a 1Password secret reference in project or global env.

Project (default):

/op-add-item OPENAI_API_KEY op://Private/API-Keys/openai
/op-add-item DATABASE_URL op://Work/Database/prod

Global:

/op-add-item OPENAI_API_KEY op://Private/API-Keys/openai --global

Features:

  • Auto-updates existing items automatically (no need to manually edit file first)
  • Autocomplete shows vaults and items from op item list
  • Smart matching by vault name or item name

/op-add-global-item VAR_NAME op://...

Similar to /op-add-item but specifically for global user env.

Examples:

/op-add-global-item OPENAI_API_KEY op://Private/API-Keys/openai
/op-add-global-item ANTHROPIC_API_KEY op://Private/API-Keys/anthropic

/op-list

List all loaded environment variables with their sources.

/op-config

Open the config directory and show user env file.

Setup Flow for New Project

# Step 1: Create project environment (defaults to .env.1pass)
/op-create-env

# Step 2: Add API keys easily (autocomplete helps find items)
/op-add-item OPENAI_API_KEY op://Private/API-Keys/openai
/op-add-item ANTHROPIC_API_KEY op://Private/API-Keys/anthropic

# Step 3: Load the environment
/op-env

# Step 4: Verify loaded variables
/op-status
/op-list

Global vs Project Environment

LocationPurposeCommand
~/.config/op-ssh/.env.1passGlobal (all projects)/op-env-user, /op-add-global-item
./.env.1passProject-specific/op-env, /op-add-item

Cascade Order:

  1. ~/.pi/.env (Pi-level)
  2. ~/.config/op-ssh/.env.1pass (global)
  3. ./.env.1pass (project, overrides global)

Environment Format

Both formats work in .env.1pass files:

# With export
OPENAI_API_KEY="op://Private/API-Keys/openai"

# Without export
OPENAI_API_KEY="op://Private/API-Keys/openai"

Both formats work in project env files:

# With export
DATABASE_URL="op://Work/Database/prod"

# Without export
DATABASE_URL="op://Work/Database/prod"

Troubleshooting

"Not signed in to 1Password"

Set OP_SERVICE_ACCOUNT_TOKEN in ~/.zshrc and reload.

Secrets not resolving

Check reference format: op://vault/item/field

Pi not loading extension

Restart Pi or run /reload in Pi command.

Item already exists

The commands automatically update existing items - just run them again with the new reference.

Autocomplete not showing items

Make sure op item list works and returns valid JSON. Run op login if needed.

Original Article

Based on: "Combining Keychain and 1Password CLI for ssh-agent management" by Bas Nijholt.

rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 467kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 467kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 467kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 193kUpdated Claude CodeCodexVerifiedInstall