### Example CLI Commands Source: https://github.com/bitwarden/cli/blob/master/_autodocs/02-program-class.md Illustrates various ways to use the Bitwarden CLI commands, including login, lock, unlock, list, get, create, edit, delete, generate, config, send, and receive. ```bash bw login ``` ```bash bw lock ``` ```bash bw unlock myPassword321 ``` ```bash bw list --help ``` ```bash bw list items --search google ``` ```bash bw get item 99ee88d2-6046-4ea7-92c2-acac464b1412 ``` ```bash bw get password google.com ``` ```bash echo '{"name":"My Folder"}' | bw encode ``` ```bash bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K ``` ```bash bw edit folder c7c7b60b-9c61-40f2-8ccd-36c49595ed72 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg== ``` ```bash bw delete item 99ee88d2-6046-4ea7-92c2-acac464b1412 ``` ```bash bw generate -lusn --length 18 ``` ```bash bw config server https://bitwarden.example.com ``` ```bash bw send -f ./file.ext ``` ```bash bw send "text to send" ``` ```bash echo "text to send" | bw send ``` ```bash bw receive https://vault.bitwarden.com/#/send/... ``` -------------------------------- ### SyncCommand Usage Examples Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Examples demonstrating how to use the sync command, with and without the force flag. ```bash bw sync ``` ```bash bw sync --force ``` -------------------------------- ### Run the Bitwarden CLI Application Source: https://github.com/bitwarden/cli/blob/master/_autodocs/01-main-class.md Initializes the application and starts command processing. This method handles service setup, command registration, argument parsing, and displays help if no arguments are provided. It may throw errors during service initialization or command parsing. ```typescript async run(): Promise ``` ```typescript const main = new Main(); await main.run(); ``` -------------------------------- ### Install Bitwarden CLI with NPM Source: https://github.com/bitwarden/cli/blob/master/README.md Install the Bitwarden CLI globally using NPM. This is the preferred method if you have Node.js installed. ```bash npm install -g @bitwarden/cli ``` -------------------------------- ### JavaScript/Node.js Client Examples Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Examples of how to interact with the Bitwarden CLI server using JavaScript's fetch API. Ensure you have a valid session key. ```javascript const baseUrl = "http://localhost:3000"; const sessionKey = "your-session-key"; async function listItems() { const response = await fetch(`${baseUrl}/vault/items`, { headers: { "Authorization": `Bearer ${sessionKey}` } }); return await response.json(); } async function getPassword(itemId) { const response = await fetch( `${baseUrl}/vault/items/${itemId}/password`, { headers: { "Authorization": `Bearer ${sessionKey}` } } ); return await response.text(); } async function createItem(item) { const response = await fetch(`${baseUrl}/vault/items`, { method: "POST", headers: { "Authorization": `Bearer ${sessionKey}`, "Content-Type": "application/json" }, body: JSON.stringify(item) }); return await response.json(); } ``` -------------------------------- ### Install Bitwarden CLI with Snap Source: https://github.com/bitwarden/cli/blob/master/README.md Install the Bitwarden CLI on Linux using the Snap package manager. ```bash sudo snap install bw ``` -------------------------------- ### LoginCommand Example Usage Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md This example demonstrates how to instantiate and use the LoginCommand to authenticate a user. It shows passing necessary services and user credentials. ```typescript const command = new LoginCommand(...services); const response = await command.run( "user@example.com", "masterpassword", { sso: true } ); ``` -------------------------------- ### Get Vault Status CLI Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Example using curl to fetch the vault and session status, including the session key in the Authorization header. ```bash curl -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/status" ``` -------------------------------- ### Get General Help for Bitwarden CLI Source: https://github.com/bitwarden/cli/blob/master/README.md Display all available commands and options for the Bitwarden CLI. ```bash bw --help ``` -------------------------------- ### Sync Vault CLI Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Example of forcing a vault synchronization using curl, providing the session key and setting the `force` query parameter to true. ```bash curl -X POST -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/sync?force=true" ``` -------------------------------- ### CreateCommand Example: Create with Stdin Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Example showing how to create a vault object (e.g., a folder) by leaving the `requestJson` parameter empty, which instructs the command to read data from stdin. ```typescript // Create with stdin const resp = await command.run("folder", "", {}); ``` -------------------------------- ### Get Folder by Name Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Retrieves a specific folder by its name. This is useful for getting folder details or its ID. ```bash bw get folder "My Folder" ``` -------------------------------- ### run() Source: https://github.com/bitwarden/cli/blob/master/_autodocs/01-main-class.md Initializes the application and starts command processing. It sets up services, registers command handlers, parses arguments, and displays help if no arguments are provided. ```APIDOC ## run() ### Description Initializes the application and starts command processing. It sets up services, registers command handlers, parses arguments, and displays help if no arguments are provided. ### Method async run(): Promise ### Behavior 1. Calls `init()` to set up services and state 2. Registers all command handlers via `program.register()`, `vaultProgram.register()`, and `sendProgram.register()` 3. Parses command-line arguments with commander.js 4. Displays help if no arguments were provided ### Throws Any error from service initialization or command parsing ### Example ```typescript const main = new Main(); await main.run(); ``` ``` -------------------------------- ### Get Password by Search Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Retrieves the password for a login item by searching for its associated domain or name. ```bash bw get password google.com ``` -------------------------------- ### CreateCommand Example: Create Folder Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Example of creating a new folder using the CreateCommand. It involves stringifying a folder object, encoding it to base64, and then calling the `run` method with the 'folder' type. ```typescript const command = new CreateCommand(...services); // Create folder const json = JSON.stringify({ name: "My Folder" }); const encoded = Buffer.from(json).toString("base64"); const resp = await command.run("folder", encoded, {}); ``` -------------------------------- ### Install Bitwarden CLI with Chocolatey Source: https://github.com/bitwarden/cli/blob/master/README.md Install the Bitwarden CLI on Windows using the Chocolatey package manager. ```powershell choco install bitwarden-cli ``` -------------------------------- ### Get and Save Attachment Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Retrieves a file attachment from a specific item and saves it to a specified file path. Requires the item ID and output path. ```bash bw get attachment logo.png --itemid 99ee88d2-6046-4ea7-92c2-acac464b1412 --output logo.png ``` -------------------------------- ### Install Bitwarden CLI with Homebrew Source: https://github.com/bitwarden/cli/blob/master/README.md Install the Bitwarden CLI on macOS using the Homebrew package manager. ```bash brew install bitwarden-cli ``` -------------------------------- ### cURL Examples for Bitwarden CLI Server Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Various cURL commands to interact with the Bitwarden CLI server for common operations like listing items, getting passwords, creating folders, generating passwords, and checking status. ```bash # List items curl -H "Authorization: Bearer key" http://localhost:3000/vault/items # Get password curl -H "Authorization: Bearer key" http://localhost:3000/vault/items/id/password # Create folder curl -X POST -H "Authorization: Bearer key" \ -H "Content-Type: application/json" \ -d '{"name":"Work"}' \ http://localhost:3000/vault/folders # Generate password curl -H "Authorization: Bearer key" \ "http://localhost:3000/vault/generate?length=32" # Get status curl -H "Authorization: Bearer key" http://localhost:3000/vault/status ``` -------------------------------- ### List Items Command Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Demonstrates how to list all vault items. Use the --search option to filter by name or text. ```bash bw list items ``` -------------------------------- ### Curl Example: Get Item Password Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Shows how to use curl to fetch the password property of a specific vault item. ```bash curl -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/items/item-id/password" # Returns: "secretpassword" ``` -------------------------------- ### GenerateCommand Examples Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Demonstrates various ways to use the GenerateCommand.run method to generate passwords and passphrases with different configurations. ```typescript const command = new GenerateCommand(...services); // Basic password const resp = await command.run({}); // Outputs: "aB3$xYz9..." // Long password with all types const resp = await command.run({ length: 32 }); // Passphrase const resp = await command.run({ passphrase: true }); // Outputs: "correct-horse-battery-staple" // Custom passphrase const resp = await command.run({ passphrase: true, words: 5, separator: "_", capitalize: true }); // Outputs: "Correct_Horse_Battery_Staple_123" ``` -------------------------------- ### Generate Password CLI Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Example of generating a password using curl, specifying the desired length and including the session key in the Authorization header. ```bash curl -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/generate?length=20" ``` -------------------------------- ### Build and Run Bitwarden CLI Locally Source: https://github.com/bitwarden/cli/blob/master/README.md Steps to set up the development environment, install dependencies, and build the Bitwarden CLI project. Includes initializing git submodules and watching for build changes. ```bash npm install npm run sub:init # initialize the git submodule for jslib npm run build:watch ``` -------------------------------- ### Authentication Query Parameter Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Shows how to pass the session key as a query parameter for authenticated requests. ```http GET /vault/items?session={session-key} ``` -------------------------------- ### Server Command Source: https://github.com/bitwarden/cli/blob/master/_autodocs/README.md Command to start an HTTP server. ```APIDOC ## Server Command ### Description Starts an HTTP server with over 80 endpoints. ### Command - **serve**: Start the HTTP server. ``` -------------------------------- ### GetCommand Examples Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Demonstrates various use cases for the GetCommand's run method, including fetching full items, specific properties, TOTP codes, and downloading attachments. ```typescript const command = new GetCommand(...services); // Get full item const resp = await command.run("item", "item-uuid", {}); // Get specific property const resp = await command.run("password", "gmail", {}); // Get TOTP code const resp = await command.run("totp", "aws", {}); // Download attachment const resp = await command.run( "attachment", "item-uuid", { itemid: "item-uuid", output: "./file.pdf" } ); ``` -------------------------------- ### List Folders Command Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Lists all folders in the vault. This command helps in organizing and navigating vault items. ```bash bw list folders ``` -------------------------------- ### List Items by URL Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Demonstrates filtering login items by their associated URL. This is helpful for managing credentials for specific websites. ```bash bw list items --url amazon.com ``` -------------------------------- ### Curl Example: Create Item Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Example using curl to send a POST request to create a new vault item with specified details. ```bash curl -X POST -H "Authorization: Bearer session-key" \ -H "Content-Type: application/json" \ -d '{"name":"Gmail","type":1,"login":{"username":"user@example.com"}}' \ "http://localhost:3000/vault/items" ``` -------------------------------- ### StatusCommand Response Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md An example of the JSON response structure returned by the StatusCommand, detailing server URL, last sync time, user information, and authentication status. ```json { "serverUrl": "https://vault.bitwarden.com", "lastSync": "2026-06-22T15:30:00Z", "userEmail": "user@example.com", "userId": "12345678-1234-1234-1234-123456789012", "status": "unlocked" } ``` -------------------------------- ### Authentication Header Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Demonstrates how to include the session key in the Authorization header for authenticated requests. ```http Authorization: Bearer {session-key} ``` -------------------------------- ### Lock Vault CLI Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Example using curl to lock the vault, including the session key in the Authorization header. ```bash curl -X POST -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/lock" ``` -------------------------------- ### Curl Example: List Items by Search Term Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md A practical example using curl to list vault items filtered by a search term. ```bash curl -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/items?search=google" ``` -------------------------------- ### List Organizations Command Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Lists all organizations the user is a member of. This is useful for managing access and permissions. ```bash bw list organizations ``` -------------------------------- ### List Items by Search Query Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Shows how to filter vault items using a search query. This is useful for finding specific items quickly. ```bash bw list items --search google ``` -------------------------------- ### Import Vault Data Examples Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Demonstrates how to use the ImportCommand's run method to import data from different formats and into organizations. Also shows how to list available formats. ```typescript const command = new ImportCommand(...services); // Import from LastPass const resp = await command.run("lastpass", "./lp_export.csv", {}); // Import to organization const resp = await command.run("bitwarden", "./export.json", { organizationid: "org-uuid" }); // List formats const resp = await command.run(null, null, { formats: true }); ``` -------------------------------- ### Initialize Bitwarden CLI Services Source: https://github.com/bitwarden/cli/blob/master/_autodocs/01-main-class.md Performs internal service initialization, called by the run() method. This includes initializing storage, state, crypto, loading server URLs, setting up locale and i18n, initializing the two-factor service, and updating the installed version. Errors may occur during storage or service initialization. ```typescript private async init(): Promise ``` -------------------------------- ### CreateCommand Example: Create Item Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Example of creating a new cipher item using the CreateCommand. It demonstrates stringifying an item object with login details, encoding it to base64, and calling the `run` method with the 'item' type. ```typescript // Create item const itemJson = JSON.stringify({ name: "Gmail", type: 1, login: { username: "user@example.com", password: "pass" } }); const encoded = Buffer.from(itemJson).toString("base64"); const resp = await command.run("item", encoded, {}); ``` -------------------------------- ### Start Bitwarden HTTP API Server Source: https://github.com/bitwarden/cli/blob/master/_autodocs/02-program-class.md Starts an HTTP API server for programmatic access to the Bitwarden vault. Requires the 'serve' flag to be enabled in feature flags. Exposes REST endpoints for vault operations. ```bash bw serve [--port ] ``` -------------------------------- ### Curl Example: Restore Item Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Example using curl to send a POST request to restore a deleted vault item. ```bash curl -X POST -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/items/item-id/restore" ``` -------------------------------- ### Get Send Template Source: https://github.com/bitwarden/cli/blob/master/_autodocs/04-send-program.md Retrieves a template for creating a Send. Specify the type as 'text' or 'file' to get the corresponding default structure. ```bash bw send template text ``` -------------------------------- ### List Vault Items with Filters Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Example of how to list vault items using various query parameters for filtering. ```http GET /vault/items?search={term}&url={url}&folderId={id}&collectionId={id}&organizationId={id}&deleted={true|false} ``` -------------------------------- ### ListCommand Usage Examples Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Demonstrates how to instantiate and use the ListCommand to retrieve different types of vault objects, including filtering by search terms or IDs. ```typescript const command = new ListCommand(...services); // List all items const resp = await command.run("items", {}); // List with search const resp = await command.run("items", { search: "google" }); // Filter by folder const resp = await command.run("items", { folderid: "folder-uuid" }); ``` -------------------------------- ### Get Help for a Specific Bitwarden CLI Command Source: https://github.com/bitwarden/cli/blob/master/README.md Display detailed help and usage information for a specific command, such as 'list' or 'create'. ```bash bw list --help ``` ```bash bw create --help ``` -------------------------------- ### Unlock Vault CLI Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Example using curl to unlock the vault, providing the session key, setting the Content-Type header, and sending the master password in the JSON request body. ```bash curl -X POST -H "Authorization: Bearer session-key" \ -H "Content-Type: application/json" \ -d '{"password":"masterpassword"}' \ "http://localhost:3000/vault/unlock" ``` -------------------------------- ### Initialize LowdbStorageService with File Locking Source: https://github.com/bitwarden/cli/blob/master/_autodocs/05-utilities.md Create an instance of LowdbStorageService for persistent key-value storage. This example enables file locking to prevent concurrent writes. ```typescript const storage = new LowdbStorageService(logService, null, "./data", false, true); await storage.init(); ``` -------------------------------- ### serve Source: https://github.com/bitwarden/cli/blob/master/_autodocs/02-program-class.md Starts an HTTP API server for programmatic access to vault operations. This requires the `serve` flag to be enabled in feature flags. ```APIDOC ## serve ### Description Starts an HTTP API server for programmatic access to vault operations. ### Signature ``` bw serve [--port ] ``` ### Note Requires the `serve` flag to be enabled in feature flags. ### Behavior - Starts a Koa-based HTTP server. - Exposes REST endpoints for vault operations. - Allows clients to interact with the vault via HTTP instead of the CLI. ``` -------------------------------- ### Run Local HTTP Server Source: https://github.com/bitwarden/cli/blob/master/_autodocs/00-index.md Start a local HTTP server to access your vault data. Requires an authorization token for requests. ```bash bw serve ``` -------------------------------- ### Serve Command API Reference Source: https://github.com/bitwarden/cli/blob/master/_autodocs/00-index.md Reference for the Serve command, which sets up an HTTP API server for programmatic vault access via REST endpoints. Covers server setup, authentication, and various vault management endpoints. ```APIDOC ## Serve Command API Reference ### Description HTTP API server enabling programmatic vault access via REST endpoints. ### Covers - HTTP server setup (Koa framework) - REST endpoints for vault operations - Authentication via session keys - Vault management endpoints - Folder and collection endpoints - Organization endpoints - Utility endpoints (generate, status, sync) - Send endpoints - Error handling and status codes - Security considerations ### Key Classes ServeCommand ### Endpoints - GET/POST/PUT/DELETE /vault/items - GET/POST /vault/items/{id}/attachments - GET /vault/folders, /vault/collections - GET /vault/organizations - POST /vault/sync, /vault/unlock, /vault/lock - GET /vault/generate, /vault/status - And more... ``` -------------------------------- ### Processing JSON Output with jq Source: https://github.com/bitwarden/cli/blob/master/_autodocs/09-configuration.md Demonstrates how to process raw JSON output from Bitwarden CLI commands using `jq`. Examples include filtering, counting, and extracting specific fields like passwords. ```bash # Pretty-printed JSON export BW_PRETTY=true bw list items > vault-export.json # Parse with jq bw list items --raw | jq '.[] | select(.name == "Gmail")' # Count items bw list items --raw | jq 'length' # Get all passwords bw list items --raw | jq -r '.[] | select(.type == 1) | .name + ": " + .login.password' ``` -------------------------------- ### EncodeCommand Usage Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Demonstrates how to use the `bw encode` command to base64 encode JSON data, both standalone and for piping into other commands like `bw create folder`. ```bash # Usage echo '{"name":"My Folder"}' | bw encode # Outputs: eyJuYW1lIjoiTXkgRm9sZGVyIn0K # For use with create command echo '{"name":"My Folder"}' | bw encode | bw create folder ``` -------------------------------- ### Check Bitwarden CLI Version Source: https://github.com/bitwarden/cli/blob/master/_autodocs/09-configuration.md Use the `--version` flag to display the currently installed version of the Bitwarden CLI. This is useful for troubleshooting or ensuring you are running the latest version. ```bash bw --version # Outputs: 1.22.1 ``` -------------------------------- ### ExportCommand Usage Examples Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Demonstrates how to use the ExportCommand to export vault data in different formats and configurations. Ensure necessary services are provided during instantiation. ```typescript const command = new ExportCommand(...services); // Export as CSV const resp = await command.run({ format: "csv" }); ``` ```typescript const resp = await command.run({ format: "encrypted_json", password: "exportpass123", output: "./backup.json" }); ``` ```typescript const resp = await command.run({ format: "json", organizationid: "org-uuid", output: "./org-backup.json" }); ``` -------------------------------- ### Get Item by ID Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Retrieves a specific vault item using its unique ID (UUID/GUID). ```bash bw get item 99ee88d2-6046-4ea7-92c2-acac464b1412 ``` -------------------------------- ### Curl Example: Get Specific Item Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Demonstrates fetching a particular vault item using its ID via curl. ```bash curl -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/items/12345678-1234-1234-1234-123456789012" ``` -------------------------------- ### List Collections by Organization ID Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Lists collections belonging to a specific organization. Requires the organization's ID. ```bash bw list collections --organizationid 12345678-1234-1234-1234-123456789012 ``` -------------------------------- ### Access Vault via HTTP Server Source: https://github.com/bitwarden/cli/blob/master/_autodocs/00-index.md Example of how to make a request to the local Bitwarden HTTP server to retrieve vault items using a session key. ```bash curl -H "Authorization: Bearer session-key" http://localhost:3000/vault/items ``` -------------------------------- ### Get TOTP by Search Example Source: https://github.com/bitwarden/cli/blob/master/_autodocs/03-vault-program.md Retrieves the Time-based One-Time Password (TOTP) code for a login item by searching for its associated domain or name. ```bash bw get totp amazon ``` -------------------------------- ### Curl Example: Edit Item Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Demonstrates updating an existing vault item using a PUT request with curl and a JSON payload. ```bash curl -X PUT -H "Authorization: Bearer session-key" \ -H "Content-Type: application/json" \ -d '{"name":"Updated Name"}' \ "http://localhost:3000/vault/items/item-id" ``` -------------------------------- ### Get Folder API Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Retrieves a single folder by its unique ID using a GET request. ```bash curl -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/folders/folder-id" ``` -------------------------------- ### Send Program API Reference Source: https://github.com/bitwarden/cli/blob/master/_autodocs/00-index.md Reference for the Send Program class, managing Bitwarden Send (temporary file/text sharing). Supports creating, listing, getting, editing, deleting Sends, removing passwords, and receiving Sends. ```APIDOC ## Send Program API Reference ### Description Command handler for Bitwarden Send (temporary file/text sharing). ### Covers - Create text and file Sends - List, get, edit, and delete Sends - Remove password protection - Access Sends from URLs (receive command) - Send templates and creation - Encryption and access control ### Key Classes SendProgram ### Commands send, send list, send get, send create, send edit, send delete, send remove-password, receive ``` -------------------------------- ### Get Item Property Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Gets a specific property (e.g., password, username, totp) from a vault item. ```APIDOC ## GET /vault/items/{id}/{property} ### Description Gets a specific property from an item (password, username, totp, etc). ### Method GET ### Endpoint /vault/items/{id}/{property} ### Parameters #### Path Parameters - **id** (string) - Required - Item UUID - **property** (string) - Required - Property name ### Valid Properties - `username` — Username/email - `password` — Password - `uri` — URI/URL - `totp` — TOTP code - `notes` — Notes text ### Response #### Success Response (200) StringResponse with property value ### Request Example ```bash curl -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/items/item-id/password" # Returns: "secretpassword" ``` ``` -------------------------------- ### Send Get Command Source: https://github.com/bitwarden/cli/blob/master/_autodocs/04-send-program.md The `send get` command retrieves detailed information about a specific Send using its unique identifier. ```APIDOC ## send get Retrieves details of a specific Send. ### Description Fetches and displays the full details of a particular Send, identified by its unique ID. ### Method bw send get ### Parameters #### Path Parameters - **send-id** (string) - Required - UUID of Send to retrieve ### Returns - Send object ### Example ```bash bw send get a1234567-b890-c123-d456-e78901234567 ``` ``` -------------------------------- ### Main Class Constructor Source: https://github.com/bitwarden/cli/blob/master/_autodocs/01-main-class.md Initializes the Main class, setting up the data directory path and all CLI services. The constructor does not accept any parameters. ```typescript constructor() ``` -------------------------------- ### Instantiate and Register Program Source: https://github.com/bitwarden/cli/blob/master/_autodocs/02-program-class.md Instantiate the Program class with the main application container and then register all global options and core commands. ```typescript const program = new Program(main); await program.register(); ``` -------------------------------- ### Login with Password from Environment Variable Source: https://github.com/bitwarden/cli/blob/master/_autodocs/09-configuration.md Sets default configurations and logs in using a password stored in an environment variable. Ensure BW_PASSWORD is set before execution. ```bash # Set defaults export BW_NOINTERACTION=true export BITWARDENCLI_APPDATA_DIR=~/.bw-cli # Login with password from environment export BW_PASSWORD="mypassword" bw login user@example.com --passwordenv BW_PASSWORD ``` -------------------------------- ### Get Vault Status API Request Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md This GET request retrieves the current status of the Bitwarden vault and session. It requires a session key for authentication. ```http GET /vault/status ``` -------------------------------- ### Typical settings.json Structure Source: https://github.com/bitwarden/cli/blob/master/_autodocs/09-configuration.md Shows the structure of a typical settings.json file for the Bitwarden CLI. This file includes global server configurations, such as the base URL and API endpoints, and user-specific settings like locale. ```json { "global": { "serverUrl": "https://vault.bitwarden.com", "serverUrls": { "base": "https://vault.bitwarden.com", "api": "https://api.bitwarden.com", "identity": "https://identity.bitwarden.com", "icons": "https://icons.bitwarden.net" } }, "user@example.com": { "locale": "en" } } ``` -------------------------------- ### Main Class Usage Pattern Source: https://github.com/bitwarden/cli/blob/master/_autodocs/01-main-class.md Demonstrates the typical usage of the Main class in the application entry point. This single line handles service initialization, command registration, user input parsing, and command execution. ```typescript import { Main } from "./bw"; const main = new Main(); await main.run(); ``` -------------------------------- ### Get Collection Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Retrieves a single collection by its ID. ```APIDOC ## GET /vault/collections/{id} ### Description Retrieves a single collection. ### Method GET ### Endpoint /vault/collections/{id} ### Parameters #### Path Parameters - **id** (string) - Required - Collection UUID ### Response #### Success Response (200) - CollectionResponse ``` -------------------------------- ### Get Organization Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Retrieves the details of a specific organization by its ID. ```APIDOC ## GET /vault/organizations/{id} ### Description Retrieves organization details. ### Method GET ### Endpoint /vault/organizations/{id} ### Parameters #### Path Parameters - **id** (string) - Required - Organization UUID ### Response #### Success Response (200) - OrganizationResponse ``` -------------------------------- ### Get Item Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Retrieves a single vault item by its unique identifier. ```APIDOC ## GET /vault/items/{id} ### Description Retrieves a single vault item. ### Method GET ### Endpoint /vault/items/{id} ### Parameters #### Path Parameters - **id** (string) - Required - Item UUID #### Query Parameters - **session** (string) - Optional - Session key (if not in header) ### Response #### Success Response (200) CipherResponse object ### Request Example ```bash curl -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/items/12345678-1234-1234-1234-123456789012" ``` ``` -------------------------------- ### EncodeCommand Constructor Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md Initializes the EncodeCommand. No specific setup is required for this constructor. ```typescript constructor() {} ``` -------------------------------- ### Get Folder Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Retrieves the details of a single folder using its unique identifier. ```APIDOC ## GET /vault/folders/{id} ### Description Retrieves a single folder. ### Method GET ### Endpoint /vault/folders/{id} ### Parameters #### Path Parameters - **id** (string) - Required - Folder UUID ### Response #### Success Response - FolderResponse ### Request Example ```bash curl -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/folders/folder-id" ``` ``` -------------------------------- ### Get Send Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Retrieves a specific Send by its ID. Requires the Send's UUID. ```APIDOC ## GET /vault/sends/{id} ### Description Retrieves a Send. ### Method GET ### Endpoint /vault/sends/{id} ### Parameters #### Path Parameters - **id** (string) - Required - Send UUID ### Response #### Success Response (200) - SendResponse ``` -------------------------------- ### LoginCommand run Method Signature Source: https://github.com/bitwarden/cli/blob/master/_autodocs/07-command-classes.md The run method for LoginCommand handles user authentication and initiates the initial vault sync. It accepts user credentials and command options. ```typescript async run(email: string, password: string, options: OptionValues): Promise ``` -------------------------------- ### Get Single Vault Item Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Endpoint for retrieving a specific vault item by its unique identifier. ```http GET /vault/items/{id} ``` -------------------------------- ### Run Unit Tests Source: https://github.com/bitwarden/cli/blob/master/_autodocs/11-architecture-and-patterns.md Commands to execute unit tests for the Bitwarden CLI. ```bash npm run test # Run once ``` ```bash npm run test:watch # Watch mode ``` -------------------------------- ### Get Send Endpoint Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Use this endpoint to retrieve details of a specific Send using its unique ID. ```HTTP GET /vault/sends/{id} ``` -------------------------------- ### Get Item Property Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Endpoint to retrieve a specific property (e.g., password, username) of a vault item. ```http GET /vault/items/{id}/{property} ``` -------------------------------- ### Configure Bitwarden CLI Source: https://github.com/bitwarden/cli/blob/master/_autodocs/02-program-class.md Manages CLI configuration, including setting the server URL and other key-value configurations. Stores configuration in the state service, persisting across sessions. ```bash bw config server [url] ``` ```bash bw config [key] [value] ``` ```bash bw config server https://bitwarden.example.com ``` ```bash bw config server https://vault.bitwarden.com # Reset to default ``` -------------------------------- ### register() Method Source: https://github.com/bitwarden/cli/blob/master/_autodocs/02-program-class.md Registers all global options and core commands with the commander.js program. ```APIDOC ## Method: register() Registers all global options and core commands with the commander.js program. ### Signature ```typescript async register(): Promise ``` ### Global Options Registered: - `--pretty`: Format JSON output with two-space indentation - `--raw`: Return raw output without descriptive messages - `--response`: Return a JSON formatted version of response output - `--cleanexit`: Exit with code 0 on success, non-zero only on errors - `--quiet`: Suppress all stdout output - `--nointeraction`: Disable interactive prompts - `--session `: Pass session key instead of reading from BW_SESSION env var - `-v, --version`: Display CLI version ### Commands Registered: 1. **login** — Log into a user account 2. **logout** — Log out of the current account 3. **lock** — Lock vault and destroy session keys 4. **unlock** — Unlock vault and return new session key 5. **sync** — Synchronize vault with server 6. **status** — Display vault and session status 7. **generate** — Generate a password or passphrase 8. **encode** — Base64 encode stdin input 9. **config** — Manage CLI configuration 10. **completion** — Output shell completion script 11. **serve** — Start an HTTP API server ### Option Effects: - `--pretty` sets `process.env.BW_PRETTY = "true"` - `--raw` sets `process.env.BW_RAW = "true"` - `--quiet` sets `process.env.BW_QUIET = "true"` - `--response` sets `process.env.BW_RESPONSE = "true"` - `--cleanexit` sets `process.env.BW_CLEANEXIT = "true"` - `--nointeraction` sets `process.env.BW_NOINTERACTION = "true"` - `--session ` sets `process.env.BW_SESSION = key` ### Help Display Examples: ``` bw login bw lock bw unlock myPassword321 bw list --help bw list items --search google bw get item 99ee88d2-6046-4ea7-92c2-acac464b1412 bw get password google.com echo '{"name":"My Folder"}' | bw encode bw create folder eyJuYW1lIjoiTXkgRm9sZGVyIn0K bw edit folder c7c7b60b-9c61-40f2-8ccd-36c49595ed72 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg== bw delete item 99ee88d2-6046-4ea7-92c2-acac464b1412 bw generate -lusn --length 18 bw config server https://bitwarden.example.com bw send -f ./file.ext bw send "text to send" echo "text to send" | bw send bw receive https://vault.bitwarden.com/#/send/... ``` ### Throws: Any error from command handler execution ``` -------------------------------- ### Curl Example: Delete Item Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Shows how to use curl to send a DELETE request to remove a vault item. ```bash curl -X DELETE -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/items/item-id" ``` -------------------------------- ### Show Current Configuration Directory Source: https://github.com/bitwarden/cli/blob/master/_autodocs/09-configuration.md Lists the contents of the default Bitwarden CLI configuration directory. Configuration is stored in a platform-specific location, checked in order: bw-data/, BITWARDENCLI_APPDATA_DIR, or the platform default. ```bash # Show current config directory # Configuration stored in platform-specific location # Check in order: bw-data/, BITWARDENCLI_APPDATA_DIR, platform default # List configuration ls -la ~/.config/Bitwarden\ CLI/ ``` -------------------------------- ### Main Class API Reference Source: https://github.com/bitwarden/cli/blob/master/_autodocs/00-index.md Reference for the Main class, the entry point and dependency injection container for the CLI application. Covers service initialization, lifecycle, dependency ordering, logout, initialization, and custom user agent configuration. ```APIDOC ## Main Class API Reference ### Description Entry point and dependency injection container for the entire CLI application. ### Key Classes Main ``` -------------------------------- ### Download Attachment API Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Downloads a file attachment using a GET request, requiring the attachment ID and item ID. ```bash curl -H "Authorization: Bearer session-key" \ "http://localhost:3000/vault/attachments/attachment-id?itemId=item-id" \ -o downloaded-file.pdf ``` -------------------------------- ### Vault Management Commands Source: https://github.com/bitwarden/cli/blob/master/_autodocs/README.md Commands for interacting with the Bitwarden vault, such as listing, getting, creating, editing, deleting, and restoring items. ```APIDOC ## Vault Management Commands ### Description Commands for managing vault items. ### Commands - **list**: List items in the vault. - **get**: Retrieve a specific item from the vault. - **create**: Create a new item in the vault. - **edit**: Modify an existing item in the vault. - **delete**: Delete an item from the vault. - **restore**: Restore a deleted item to the vault. ``` -------------------------------- ### LowdbStorageService Constructor Source: https://github.com/bitwarden/cli/blob/master/_autodocs/05-utilities.md Initializes the LowdbStorageService for persistent key-value storage using lowdb with file locking. It supports default values, a storage directory, caching, and file locking. ```APIDOC ## Constructor LowdbStorageService ### Description Initializes the LowdbStorageService for persistent key-value storage using lowdb with file locking. It supports default values, a storage directory, caching, and file locking. ### Parameters #### Path Parameters - **logService** (LogService) - Required - Logger for storage operations - **defaults** (any) - Optional - Default data structure - **dir** (string) - Optional - Storage directory - **allowCache** (boolean) - Optional - Whether to cache in memory - **requireLock** (boolean) - Optional - Whether to use file locking ### Request Example ```typescript const storage = new LowdbStorageService(logService, null, "./data", false, true); await storage.init(); ``` ### Response #### Success Response (200) - **LowdbStorageService instance** - Description of the initialized storage service instance ``` -------------------------------- ### Typical data.json Structure Source: https://github.com/bitwarden/cli/blob/master/_autodocs/09-configuration.md Illustrates the structure of a typical data.json file used by the Bitwarden CLI. This file contains global settings, authenticated accounts, and detailed user profile, folder, cipher, and collection data. ```json { "global": { "theme": null, "neverDomains": [] }, "authenticatedAccounts": ["user@example.com"], "user@example.com": { "profile": { "id": "user-uuid", "email": "user@example.com", "emailVerified": true, "name": "User Name", "status": "active" }, "folders": [...], "ciphers": [...], "collections": [...] } } ``` -------------------------------- ### Get Collection by ID Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Retrieves details for a specific collection using its UUID. Requires the collection's ID as a path parameter. ```http GET /vault/collections/{id} ``` -------------------------------- ### Create a Text Send with Bitwarden CLI Source: https://github.com/bitwarden/cli/blob/master/_autodocs/04-send-program.md Use this command to create a new text-based Send. The content is provided directly as an argument. ```bash # 1. Create a text send bw send "Here are the Q3 results" ``` -------------------------------- ### Docker Configuration for Bitwarden CLI Source: https://github.com/bitwarden/cli/blob/master/_autodocs/09-configuration.md Runs the Bitwarden CLI in a Docker container, setting necessary environment variables and mounting a volume for persistent data. The serve command is used. ```bash # In Docker container docker run -e BITWARDENCLI_APPDATA_DIR=/data \ -e BW_NOINTERACTION=true \ -e FLAGS='{"serve":true}' \ -v /data:/data \ bitwarden/cli serve ``` -------------------------------- ### Initialize I18nService Source: https://github.com/bitwarden/cli/blob/master/_autodocs/05-utilities.md Instantiate and initialize the I18nService for message translation. Ensure the locales directory is correctly specified and the language is initialized. ```typescript const i18n = new I18nService("en", "./locales"); await i18n.init("en"); ``` -------------------------------- ### Get Organization by ID Source: https://github.com/bitwarden/cli/blob/master/_autodocs/08-serve-command.md Retrieves detailed information for a specific organization using its UUID. Requires the organization's ID as a path parameter. ```http GET /vault/organizations/{id} ``` -------------------------------- ### Bitwarden CLI File Structure Source: https://github.com/bitwarden/cli/blob/master/_autodocs/00-index.md Overview of the directory and file organization within the Bitwarden CLI project. ```tree src/ ├── bw.ts # Main entry point ├── program.ts # Core command handler ├── vault.program.ts # Vault command handler ├── send.program.ts # Send command handler ├── utils.ts # Utility functions ├── flags.ts # Feature flags type ├── commands/ # Command implementations │ ├── login.command.ts │ ├── list.command.ts │ ├── get.command.ts │ ├── create.command.ts │ ├── edit.command.ts │ ├── delete.command.ts │ ├── restore.command.ts │ ├── generate.command.ts │ ├── export.command.ts │ ├── import.command.ts │ ├── encode.command.ts │ ├── status.command.ts │ ├── sync.command.ts │ ├── config.command.ts │ ├── lock.command.ts │ ├── unlock.command.ts │ ├── completion.command.ts │ ├── serve.command.ts │ └── send/ # Send commands │ ├── create.command.ts │ ├── edit.command.ts │ ├── delete.command.ts │ ├── get.command.ts │ ├── list.command.ts │ ├── receive.command.ts │ └── removePassword.command.ts ├── services/ # Custom services │ ├── i18n.service.ts │ ├── lowdbStorage.service.ts │ └── nodeEnvSecureStorage.service.ts └── models/ # Data models ├── request/ │ └── organizationCollectionRequest.ts ├── response/ │ ├── attachmentResponse.ts │ ├── cipherResponse.ts │ ├── collectionResponse.ts │ ├── folderResponse.ts │ ├── loginResponse.ts │ ├── organizationCollectionResponse.ts │ ├── organizationResponse.ts │ ├── organizationUserResponse.ts │ ├── passwordHistoryResponse.ts │ ├── sendAccessResponse.ts │ ├── sendFileResponse.ts │ ├── sendResponse.ts │ ├── sendTextResponse.ts │ └── templateResponse.ts └── selectionReadOnly.ts ``` -------------------------------- ### Get Send Metadata Source: https://github.com/bitwarden/cli/blob/master/_autodocs/04-send-program.md Retrieve the metadata object for a Send instead of its content. This is useful for inspecting Send properties without accessing the actual data. ```bash bw receive https://vault.bitwarden.com/#/send/a1234567/b8901234 --obj ``` -------------------------------- ### Utilities and Helper Classes Source: https://github.com/bitwarden/cli/blob/master/_autodocs/00-index.md Documentation for utility functions and services used in common CLI operations, including file I/O, localization, persistent storage, and encrypted credential storage. ```APIDOC ## Utilities and Helper Classes ### Description Utility functions and services for common CLI operations. ### Covers - CliUtils class (file I/O, stdin/stdout, search, password handling) - I18nService (localization) - LowdbStorageService (persistent storage with locking) - NodeEnvSecureStorageService (encrypted credential storage) - File operations and encoding ### Key Classes - CliUtils - I18nService - LowdbStorageService - NodeEnvSecureStorageService ``` -------------------------------- ### Execute Bitwarden CLI Command After Local Build Source: https://github.com/bitwarden/cli/blob/master/README.md Run a Bitwarden CLI command, such as 'login', after building the project locally. Assumes the build output is in the './build' directory. ```bash node ./build/bw.js login ```