Skip to content

原文(日本語に翻訳)

プラグインオプション(manifest.userConfig)が外部から利用可能になりました。プラグインは有効化時に設定を求めるプロンプトを表示でき、sensitive: true の値は macOS ではキーチェーン、その他のプラットフォームでは保護された認証情報ファイルに保存されます。

原文(英語)

Plugin options (manifest.userConfig) now available externally — plugins can prompt for configuration at enable time, with sensitive: true values stored in keychain (macOS) or protected credentials file (other platforms)

概要

プラグインの manifest.jsonuserConfig を定義することで、プラグインを有効化する際にユーザーに設定値の入力を求められるようになりました。API キーやトークンなどの機密情報は sensitive: true フラグで macOS のキーチェーンや保護された認証情報ファイルに安全に保存されます。

基本的な使い方

プラグインの manifest.jsonuserConfig セクションを追加します:

json
{
  "name": "my-plugin",
  "version": "1.0.0",
  "userConfig": {
    "apiKey": {
      "description": "サービスの API キーを入力してください",
      "sensitive": true,
      "required": true
    },
    "baseUrl": {
      "description": "API のベース URL(オプション)",
      "default": "https://api.example.com",
      "required": false
    }
  }
}

プラグインを有効化すると、ユーザーに設定値の入力が求められます。

実践例

外部 API を使用するプラグイン

GitHub API を使用するプラグインの設定例:

json
// manifest.json
{
  "name": "github-integration",
  "version": "1.0.0",
  "description": "GitHub リポジトリとの統合",
  "userConfig": {
    "githubToken": {
      "description": "GitHub Personal Access Token(repo スコープが必要)",
      "sensitive": true,
      "required": true
    },
    "defaultOrg": {
      "description": "デフォルトの GitHub 組織名",
      "required": false
    }
  }
}

データベース接続設定

json
{
  "name": "db-connector",
  "userConfig": {
    "connectionString": {
      "description": "データベース接続文字列(例: postgresql://user:pass@host/db)",
      "sensitive": true,
      "required": true
    },
    "maxConnections": {
      "description": "最大接続数",
      "default": "10",
      "required": false
    }
  }
}

プラグインスクリプトからの設定値の読み込み

プラグイン内のスクリプトから設定値を参照する方法:

javascript
// plugin-script.js
const config = await claude.getPluginConfig();
const apiKey = config.apiKey; // キーチェーンから安全に取得
const baseUrl = config.baseUrl || 'https://api.example.com';

// API 呼び出し
const response = await fetch(`${baseUrl}/endpoint`, {
  headers: { 'Authorization': `Bearer ${apiKey}` }
});

注意点

  • sensitive: true を指定した値は平文でファイルに保存されることはありません
    • macOS: キーチェーン(Keychain)に保存
    • その他のプラットフォーム: 保護された認証情報ファイルに保存
  • ユーザーが設定を変更したい場合は、プラグインを再有効化するか、設定コマンドを使用します
  • required: true のフィールドが入力されない場合、プラグインの有効化が失敗します
  • default 値が指定されているフィールドは、ユーザーが入力しなくてもデフォルト値が使われます

関連情報