| name | 1password-cli |
| description | 1Password CLI integration for managing secrets, API keys, and authentication. Use when working with 1Password in Linux/WSL/Windows environments. Supports Service Account authentication, Desktop App integration, and Session Token Caching. |
1Password CLI Skill
Setup
Choose one of the following authentication methods:
Option A: Desktop App Integration (Recommended for Local)
If you have a 1Password Desktop app installed:
- Open Settings $\rightarrow$ Developer $\rightarrow$ Integrate with 1Password CLI.
- No shell config required.
Option B: Session Token Caching (Best for WSL/Linux)
If the Desktop bridge doesn't work, use the session manager to avoid repeated password prompts:
- Run the interactive setup wizard
npx 1password-cli-setup and enable "Session Token Caching".
- Or manually add to shell config:
source ~/.config/op-ssh/op-session-manager.sh
Option C: Service Account (Best for CI/CD and Headless)
- Go to https://op.serviceaccounts.1password.com
- Create a Service Account and copy the token.
- Add to your shell config (
~/.zshrc or ~/.bashrc):
export OP_SERVICE_ACCOUNT_TOKEN="your-service-account-token-here"
Reload your shell and verify setup:
source ~/.zshrc
op account list
Features
CLI Tool: op-reference
Manage 1Password secret references:
op-reference check
op-reference list
op-reference get "op://..."
op-reference copy "op://..."
op-reference add NAME REF
op-reference env FILE
Environment Files
Use .env.1pass files with secret references:
OPENAI_API_KEY="op://Private/API-Keys/openai"
DATABASE_URL="op://Work/Database/prod"
Secret Reference Syntax
Format: op://vault/item/field
op://Private/API-Keys/openai
op://Work/Database/production
Usage with AI Agents
Automatic Loading
The Pi extension automatically loads:
- User-level:
~/.config/op-ssh/.env.1pass
- Project-level:
./.env.1pass (overrides user)
Pi Commands
/op-status - Check authentication and loaded variables
/op-env - Load project environment
/op-env-user - Load user environment
/op-get op://... - Get a specific secret
/op-list - Show loaded variables
Custom Tool: op_get_secret
Retrieve secrets by reference without exposing them in context:
{
"reference": "op://Private/API-Keys/openai"
}
Environment Levels
Configuration follows cascading precedence:
- User Level (
~/.config/op-ssh/.env.1pass) - Global secrets
- Project Level (
./.env.1pass) - Project-specific, overrides user
LLM Context and Best Practices
When building AI tools or interacting with LLMs regarding 1Password, always refer to the official LLM-optimized documentation:
- Full Index:
https://developer.1password.com/llms.txt
- CLI Docs:
https://developer.1password.com/llms-cli.txt
- SDK Docs:
https://developer.1password.com/llms-sdks.txt
- Secrets Automation:
https://developer.1password.com/llms-secrets-automation.txt
To fetch specific pages as Markdown for retrieval-augmented generation (RAG), append .md to any documentation URL (e.g., https://developer.1password.com/docs/cli/get-started.md).
Agent Hooks
1Password provides agent hooks that run inside supported IDEs and AI agents (Cursor, Claude Code, GitHub Copilot, Windsurf) to validate and verify 1Password setup before shell execution or tool use.
The available hook is 1password-validate-mounted-env-files which validates mounted .env files from 1Password Environments.
Installing Hooks
You can install the agent hooks from the 1Password/agent-hooks repository:
git clone https://github.com/1Password/agent-hooks
cd agent-hooks
./install.sh --agent cursor --target-dir /path/to/your/project
./install.sh --agent windsurf --target-dir /path/to/your/project
./install.sh --agent claude-code --target-dir /path/to/your/project
The script will bundle the hooks and optionally create the required config file (e.g. .cursor/hooks.json or .windsurf/hooks.json).
Files and Directories
~/.config/op-ssh/
├── .env.1pass # User-level environment
├── references.conf # Named references
└── op-ai-helper.sh # Helper functions
~/projects/project/
└── .env.1pass # Project-level environment (overrides user)
Troubleshooting
Service Account Required
Error: Not signed in to 1Password
Solution: Set OP_SERVICE_ACCOUNT_TOKEN in ~/.zshrc
Secret Not Found
Error: Secret not found: op://...
Solution: Verify the reference in 1Password: op://vault/item/field
1Password CLI Not Found
Error: 1Password CLI (op) not found
Solution: Install from https://1password.com/downloads/command-line/
Advanced: oprun for Secret Injection
For applications, use oprun (the shell helper) to inject secrets:
oprun --env-file app.env -- node app.js
OPENAI_API_KEY="op://Private/API-Keys/openai"
oprun -- node app.js
Original Article
Based on: "Combining Keychain and 1Password CLI for ssh-agent management" by Bas Nijholt.