# Op Secrets

Securely store and use secrets with 1Password in Claude Code without exposing them in the chat, transcript, or shell history. The tool provides `op-store` for saving secrets, `op-env` for injecting them into commands, and ensures secrets are never visible to Claude.

**Canonical URL:** https://skillshunter.net/skills/discovered-2cf0a943ec09bdc01fa4f569917a7a76d831fc30af3db760

**JSON URL:** https://skillshunter.net/api/public/v1/skills/discovered-2cf0a943ec09bdc01fa4f569917a7a76d831fc30af3db760

**Markdown URL:** https://skillshunter.net/skills/discovered-2cf0a943ec09bdc01fa4f569917a7a76d831fc30af3db760.md

**Instructions download URL:** https://skillshunter.net/skills/discovered-2cf0a943ec09bdc01fa4f569917a7a76d831fc30af3db760/download

**Category:** Software & Development

**Source URL:** https://github.com/lucas-saldanha-werneck/op-secrets/blob/ff42dd004f0177f4d10e551e7399d073b8e650b4/skills/op-secrets/SKILL.md

**Source commit:** ff42dd004f0177f4d10e551e7399d073b8e650b4

**Listing approved at:** 2026-12-01

**Created at:** 2026-11-30T08:07:08.000000Z

**Updated at:** 2026-12-01T12:48:20.000000Z

## Catalog information

The following descriptions are catalog information. Listing approval does not mean the skill has been tested or is safe for every environment.

### Editor's note

Before using `op-store` or `op-env`, ensure the 1Password CLI (`op`) is installed and configured with the 1Password app or a service-account token. Run `op-env --check` first to verify setup and resolve any connection issues.

### When to use it

- Storing API keys, tokens, or passwords securely in 1Password for use with Claude Code
- Injecting secrets into environment variables for tools or scripts that require them
- Launching Claude Code with preloaded secrets using `op-env`
- Verifying 1Password CLI setup and connection status with `op-env --check`

## Skill instructions

---
name: op-secrets
description: >
  Use 1Password with Claude Code without secrets ever entering the chat, the transcript, the
  command line or shell history. Use when the user wants to store an API key, token, password
  or credential; when a tool, MCP server, hook or script needs a secret; when the user mentions
  1Password, `op`, `op://`, secret references, .env files with secrets, "where does the key go",
  or asks how to launch Claude Code with secrets loaded. Provides `op-store` (native hidden
  dialog with an eye/reveal toggle, straight into 1Password), `op-env` (launch any command with
  secrets injected, TTY preserved, one biometric prompt) and `secret-dialog`. Not for other
  password managers.
version: "0.7.3"
metadata:
  author: Lucas Saldanha Werneck <lucas@2olhares.com>
  tags: [1password, secrets, security, op, credentials]
---

# 1Password for Claude Code

## Purpose

Keep secrets out of the chat, the transcript, the command line and shell history: store them in
1Password through a dialog Claude cannot see (`op-store`), and load them as environment variables
for a session or command (`op-env`). Only `op://` references and variable names pass through Claude.

## Instructions

1. Never ask for a secret in the chat. To store one, run `op-store <title>`; a native dialog opens and only the `op://` reference comes back.
2. If a tool needs the secret as an environment variable, append `VAR_NAME=op://...` to `~/.claude/.env.tpl`.
3. Tell the user to start Claude Code with `op-env claude`, so the variables are loaded with one biometric prompt.
4. Use `$VAR_NAME` in commands; never print values, never `op read` inside every Bash call.
5. When anything fails, run `op-env --check` first, then see Troubleshooting below.

## The one rule

**Never ask the user to paste a secret into the chat.** Anything typed in the chat or shown in a
tool result is in the transcript forever. Instead run `op-store <title>`: a native dialog opens
outside Claude's view, the user pastes there, the value goes straight into 1Password, and only the
`op://` reference comes back.

Also never: print a secret value, `op read` inside every Bash call (biometric prompt fatigue),
`source <(op run ... env)` or `eval` (values with shell metacharacters execute as code),
`bash -x` any script that handles a value (the trace prints it).

## The guard hooks back this up

When installed as a plugin, `hooks/guard.py` catches the common mistakes: secrets pasted by the
user (erased before you see them), `op read` / `op item get` / `op run` / `printenv` / `echo $TOKEN`
/ reading `.env*` or credential files (Bash, Read, Grep) / `op item create ...=value`, literal
secrets in Write/Edit, and any final message of yours that asks the user to paste a secret.
If a hook blocks you, do what its message says: run `op-store <title>` and use the `op://`
reference or `$VAR`. Do not look for a way around it, and do not call `secret-dialog` yourself:
its output is the secret.

## Commands (installed by `install.sh` into `~/.local/bin`)

| Command | What it does |
|---|---|
| `op-store <title>` | Opens the native dialog (hidden field + eye). Saves an *API Credential* item, field `credential`, in vault `Claude`. Prints `OK op://Claude/<title>/credential`. Single-line values only. |
| `op-store --login <title> [--url URL]` | Asks username (visible) then password (hidden). Saves a *Login* item. |
| `op-store --update <title>` | Replaces the value of an existing item. |
| `op-store --vault V --field F <title>` | Other vault / field name. |
| `op-env <command>` | Resolves every `op://` line of `~/.claude/.env.tpl` in ONE `op` call, exports them, then `exec`s the command. TTY preserved. Use `op-env claude` to start Claude Code. |
| `op-env --check` | Shows op version, template, account, and how many keys resolve. Run this first when anything fails. |
| `op-env --list` | Key names only, never values. |
| `op-env --meta "<item>" [vault]` | Title, vault, version, created/updated dates and field NAMES of one item (never values). Use it to see whether an edit in the app reached 1Password. |

## Workflows

**User wants to store a secret** (key, token, password):
1. Choose a short item title (e.g. `Apify`, `GitHub PAT`, `UniFi`).
2. Run `op-store <title>` (or `--login` for user+password). Tell the user a dialog opened and to paste there.
3. On `OK op://...`, append `VAR_NAME=op://...` to `~/.claude/.env.tpl` if a tool needs it as an env var.
4. Tell the user to restart Claude Code with `op-env claude` so the new variable is loaded.
   Never verify by printing the value; `op-store` already confirmed the field exists.

**A tool / script / hook needs a secret** and Claude was started with `op-env`:
the variable is already in the environment. Use `$VAR_NAME` in the command. Do not `op read` again.
If the variable is missing, check `op-env --list`, then ask the user to add it with `op-store`
and restart with `op-env claude`.

**MCP server needs a token** (`.mcp.json`): use `${VAR_NAME}` expansion, inherited from `op-env`:
```json
{ "mcpServers": { "x": { "command": "npx", "args": ["-y", "x-mcp"], "env": { "X_TOKEN": "${X_TOKEN}" } } } }
```
HTTP servers with a bearer header: `claude mcp add-json` with a `headersHelper` that runs
`op read` once at connect time (see README).

**One-off value outside a session**: `op read "op://Claude/Item/credential"` — fine in the
user's own terminal, avoid inside Claude's Bash tool (each call is a new shell → new prompt).

## Prerequisites

- The 1Password CLI (`op`) and either the 1Password app with "Integrate with 1Password CLI" on, or a service-account token (`OP_SERVICE_ACCOUNT_TOKEN`).
- `op-store`, `op-env` and `secret-dialog` installed by `install.sh` into `~/.local/bin`; the guard hooks need `python3` and the plugin install.

## Setup check (run before the first use)

```bash
op-env --check
```
- `op not found` → macOS `brew install --cask 1password-cli`; other OS: https://developer.1password.com/docs/cli/get-started/
- `NOT connected` → 1Password app > Settings > Developer > "Integrate with 1Password CLI"
  (Touch ID / Windows Hello / PolKit). Or export `OP_SERVICE_ACCOUNT_TOKEN` (no app needed, scoped to chosen vaults).
- `resolved: N of M` with N < M → a reference in the template is wrong (vault/item/field name).

## Security model (tell the user when relevant)

- With the desktop-app integration, `op` can read **every vault** of the account while the app is
  unlocked, not only `Claude`. The vault is organisation, not isolation. For real isolation use a
  **service account** scoped to one vault (`op service-account create name --vault Claude:read_items,write_items`;
  `write_items` is needed for `op-store`) and turn the app integration off. `op-env` removes
  `OP_SERVICE_ACCOUNT_TOKEN` from the launched session on purpose (`OP_ENV_KEEP_SA=1` keeps it).
- Injected env vars protect the disk and the transcript. Every subprocess, hook and stdio MCP server
  started by Claude Code inherits **all** of them, and a process can still `printenv`. Do not print
  environments; do not run `env`/`printenv`/`set` without filtering.
- `op://` references reveal vault, item and field *names*. Keep them non-sensitive.
- Claude Code's own login token lives in the OS keychain and is readable by same-user processes
  (reported by Silverfort, 2026-07). Unrelated to 1Password; nothing here changes it.

## Limitations

- `op-store` saves single-line values only.
- With the desktop-app integration, `op` can read every vault of the account; only a service account scoped to one vault isolates it.
- Every subprocess started by Claude Code inherits the injected variables. The guard hooks are a text filter, not a sandbox.
- Windows and Linux dialog backends are not yet verified by the author.

## Troubleshooting

- Claude starts in `--print` mode / "No terminal detected": you used `op run -- claude`. Use `op-env claude`.
- `op whoami` says "account is not signed in" but everything works: known with app integration; ignore.
- Repeated biometric prompts: something calls `op` per command. Move the secret to the template and use `op-env`.
- macOS 26: "«iTerm/Terminal» would like to access data from other apps" pops up again and again, even after Allow:
  `op` talks to the desktop app through a socket inside 1Password's group container, and macOS keeps that
  answer only for the current terminal session and program. Fix: System Settings → Privacy & Security →
  Full Disk Access → add the terminal app, restart it. `op-env --check` prints a `macOS:` line while this is missing.
- `op-env` loads 0 keys and `op-env --check` says "More than one item matches": two items share a title.
  Delete the duplicate in 1Password, or reference the item by ID in the template: `VAR=op://Vault/<item id>/field`
  (the IDs are in that same error message).
- MCP server fails after `/mcp` reconnect: reconnect spawns non-interactively, `op` cannot prompt. Prefer `${VAR}` from `op-env`.
- Dialog never appears (macOS): the binary `secret-dialog-macos` is missing → run `install.sh` (needs `swiftc`); falls back to AppleScript (no eye).
- Linux: KDE uses `kdialog --password` (eye built in, KDE Frameworks ≥ 5.84); GNOME uses GTK4 `Gtk.PasswordEntry` via `python3-gi`; else `zenity` (no eye); else `read -s` in a TTY.
- Windows: PowerShell + WinForms dialog. Claude Code runs in Git Bash; the scripts run there.
  Windows and Linux backends are not yet verified by the author.

## Examples

- "Store my Apify key": run `op-store Apify`, tell the user a dialog opened and to paste there; it prints
  `OK op://Claude/Apify/credential`. Then append `APIFY_TOKEN=op://Claude/Apify/credential` to `~/.claude/.env.tpl`
  and tell the user to restart with `op-env claude`.
- "How do I start Claude Code with my secrets loaded?": `op-env claude` (any command works: `op-env ./deploy.sh`).
- "Where do I put my key?": not in the chat; use `op-store <title>`, then the `op://` reference in `.env.tpl`.
- "Secrets are not loading": run `op-env --check`; `resolved: N of M` with N < M means a reference in the template is wrong.

