Vsecrets
Bun

variable

secrets

const secrets: { delete(options: { name: string; service: string }): Promise<boolean>; get(options: { name: string; service: string }): Promise<null | string>; set(options: { allowUnrestrictedAccess: boolean; name: string; service: string; value: string }): Promise<void> }

Securely store and retrieve sensitive credentials using the operating system's native credential storage.

Uses platform-specific secure storage:

  • macOS: Keychain Services
  • Linux: libsecret (GNOME Keyring, KWallet, etc.)
  • Windows: Windows Credential Manager
import { secrets } from "bun";

// Store a credential
await secrets.set({
  service: "my-cli-tool",
  name: "github-token",
  value: "ghp_xxxxxxxxxxxxxxxxxxxx"
});

// Retrieve a credential
const token = await secrets.get({
  service: "my-cli-tool",
  name: "github-token"
});

if (token) {
  console.log("Token found:", token);
} else {
  console.log("Token not found");
}

// Delete a credential
const deleted = await secrets.delete({
  service: "my-cli-tool",
  name: "github-token"
});
console.log("Deleted:", deleted); // true if deleted, false if not found