1password について
1Password CLIで開発作業のシークレットを取得・管理するためのスキルです。シークレット参照、アイテムのフィールド設定、値をコマンド履歴に残さない方法を説明します。
主な機能
- 01op readによるシークレット取得
- 02認証情報アイテムの作成と編集
- 03フィールド種別の明示
- 04TOTPとSSHキー項目の処理
- 05コマンドや環境変数でのシークレット利用
活用シーン
- 01CLIコマンドにAPIキーを渡す
- 02OAuth認証情報アイテムを作成する
- 03データベース接続情報を保存する
- 04機密でない項目を隠さずに編集する
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ steveclarke/ dotfiles --skill 1passwordインストール後、Claude Code で/1passwordを入力して読み込まれたか確認します。
詳細
1Password CLI
1Password CLI(op)を使用して、秘密情報をプレーンテキストで公開せずに取得・管理できます。
秘密情報の取得
ユーザーに1Password の秘密情報参照(1Password でフィールドを右クリック →「秘密情報参照をコピー」)を尋ねます:
# Read a secret value
op read "op://Vault/Item/field"
# Use in a command (secret never shown in shell history)
some-cli --token "$(op read 'op://Vault/Item/api-key')"
# Use as environment variable
export API_KEY="$(op read 'op://Vault/Item/api-key')"
よく使われるパターン
# CLI auth
toggl auth "$(op read 'op://Employee/Toggl/api key')"
gh auth login --with-token < <(op read 'op://Personal/GitHub/token')
# Docker login
docker login -u $(op read op://Vault/Docker/username) -p $(op read op://Vault/Docker/password)
参照形式
op://vault-name/item-name/field-name
op://vault-name/item-name/section-name/field-name
特殊なフィールド:
op read "op://Vault/Item/one-time password?attribute=otp" # TOTP
op read "op://Vault/Item/private key?ssh-format=openssh" # SSH key
アイテムの作成
フィールドタイプの構文
"Field Name[text]=value" # Plain text (visible)
"Field Name[concealed]=value" # Password/secret (hidden)
"Field Name[url]=https://..." # Clickable URL
"Field Name[delete]" # Remove a field
デフォルト(サフィックスなし)は非表示です。フィールドタイプは必ず明示してください。
原則
- 実際の秘密情報のみを非表示にする — パスワード、API キー、トークンです。URL、ユーザー名、クライアント ID、ホスト名、ポート、その他の機密性のない識別子には、
[text]または[url]を使用してください。会議で声に出して読める情報は秘密情報ではありません。 - 明確で説明的なフィールド名を使う — 元の用語に合わせます
- コンテキストを含める — アカウント情報、メモ、詳細を追加します
- テンプレートの不要な項目を整理する — テンプレートのデフォルトフィールドを削除するか、値を設定します
OAuth API 認証情報
op item create --category="API Credential" --title="Service Name - App Name" --vault="VaultName" \
"Client ID[text]=ABC123" \
"Client Secret[concealed]=secret-value-here" \
"Account[text][email protected]" \
"Redirect URL[text]=http://localhost:8080" \
"Authorization URL[text]=https://service.com/oauth2/authorize" \
"Token Request URL[text]=https://api.service.com/oauth2/token" \
"Developer Portal[url]=https://developer.service.com" \
"notesPlain=Context about this credential and any gotchas."
シンプルな API キー
op item create --category="API Credential" --title="Service Name API" --vault="VaultName" \
"API Key[concealed]=sk-xxxxxxxxxxxx" \
"Account[text][email protected]" \
"Documentation[url]=https://docs.service.com/api" \
"notesPlain=Used for X purpose. Rate limit: 1000/day."
データベース認証情報
op item create --category="Database" --title="Production DB - ServiceName" --vault="VaultName" \
"type[text]=postgresql" \
"server[text]=db.example.com" \
"port[text]=5432" \
"database[text]=myapp_production" \
"username[text]=app_user" \
"password[concealed]=secret-password" \
"notesPlain=Read replica. Primary is on port 5433."
既存のアイテムの編集
op item edit で既存のアイテムにフィールドを追加する場合も、同じタイプのルールが適用されます — フィールドタイプは必ず明示してください:
# WRONG — defaults to concealed, hides the URL and username
op item edit "My Item" "Section.URL=https://example.com" "Section.username=admin"
# RIGHT — only the password is concealed
op item edit "My Item" "Section.URL[url]=https://example.com" "Section.username[text]=admin" "Section.password[concealed]=secret"
テンプレートフィールドの処理
カテゴリーによっては、valid from や expires などのデフォルトフィールドに、エポック 0 が設定されていることがあります。
# Delete if not applicable
op item edit "Item Name" --vault="VaultName" "valid from[delete]" "expires[delete]"
# Set if applicable
op item edit "Item Name" --vault="VaultName" "valid from=2026-01-27" "expires=2027-01-27"
フィールド名
| 悪い例 | 良い例 |
|---|---|
credential | Client ID |
token_uri | Token Request URL |
secret | Client Secret または API Key |
サービスのドキュメントに記載されている用語に合わせます。
前提条件
- 1Password アプリがインストールされ、CLI 統合が有効になっていること
- デスクトップアプリ統合がサインインを処理します。実際の
op read/op itemコマンドを実行し、アプリのプロンプトに従ってください - 保管庫を確認します:
op vault list - SSH 経由で別の Mac に接続している場合、
opはその Mac の 1Password アプリを使用します:ssh <mac> 'op ...'を実行してください。Touch ID のプロンプトはその Mac の画面に表示されます。ユーザーがエージェントとは別の Mac にいる場合にこれを使うと、再度サインインせずに、その場で承認できます - ドキュメント:https://developer.1password.com/docs/cli
コメント
Markdown 対応