CLI plugin JavaScript usage example
Example showing how to read CLI matches in JavaScript: import { getMatches } from '@tauri-apps/plugin-cli'; const matches = await getMatches(); if (matches.subcommand?.name === 'run') { const args = matches.subcommand.matches.args; if (args.debug?.value === true) { /* handle debug mode */ } }
CLI plugin Rust usage example
Example showing how to read CLI matches in Rust: use tauri_plugin_cli::CliExt; in lib.rs, then call app.cli().matches() in setup callback. The returned matches struct contains args and subcommand fields that can be inspected and printed with println!("{:?}", matches).
CLI plugin permission configuration
The CLI plugin requires permissions defined in capabilities configuration. The default permission is 'cli:default'. Permissions must be added to the permissions array in the capability configuration file (e.g., src-tauri/capabilities/default.json).
CLI plugin overview
Tauri enables apps to have a CLI through clap, a robust command line argument parser. With a simple CLI definition in tauri.conf.json, you can define your interface and read its argument matches map on JavaScript and/or Rust.
CLI plugin supported platforms
The CLI plugin supports Windows, macOS, and Linux. On Windows, production apps are not able to write text back to the calling console by default due to an OS limitation.
CLI plugin automatic setup
To automatically install the CLI plugin, run: npm run tauri add cli (npm), yarn run tauri add cli (yarn), pnpm tauri add cli (pnpm), deno task tauri add cli (deno), bun tauri add cli (bun), or cargo tauri add cli (cargo).
CLI plugin manual setup steps
Manual setup requires three steps: (1) Run 'cargo add tauri-plugin-cli --target cfg(any(target_os = "macos", windows, target_os = "linux"))' in the src-tauri folder; (2) Modify lib.rs to initialize the plugin with app.handle().plugin(tauri_plugin_cli::init()); wrapped in #[cfg(desktop)]; (3) Install JavaScript bindings with npm install @tauri-apps/plugin-cli, yarn add @tauri-apps/plugin-cli, pnpm add @tauri-apps/plugin-cli, deno add npm:@tauri-apps/plugin-cli, or bun add @tauri-apps/plugin-cli.
CLI plugin configuration structure in tauri.conf.json
The CLI plugin is configured under plugins.cli with the following fields: description (string), args (array of argument objects), and subcommands (object mapping subcommand names to configurations with description, args, etc.).
CLI positional argument configuration
Positional arguments are identified by position. Configuration requires: name (string), index (number starting at 1), and takesValue (boolean). Example: an argument with name "source", index 1, takesValue true will capture the first positional argument.
CLI named argument configuration
Named arguments are key-value pairs. Configuration requires: name (string), and optionally: short (single character alias), takesValue (boolean), multiple (boolean to accept multiple values), and possibleValues (array of allowed values). Users can pass multiple values via --name value1 value2, -s value1 -s value2, or --name=value1,value2.
CLI flag argument configuration
Flag arguments are standalone keys. Configuration requires: name (string) and optionally: short (single character alias). Users can invoke flags via --name, -short, or combined like -vvv. The arg matches map defines flags as true with an occurrences count.
CLI subcommands structure
Subcommands are defined in the plugins.cli.subcommands object, where keys are subcommand names and values are configuration objects with the same structure as the root CLI configuration (description, longDescription, args, etc.). Example: subcommands like branch and push for git-like CLIs.
CLI plugin JavaScript API
Import getMatches from '@tauri-apps/plugin-cli'. Call await getMatches() to retrieve a matches object with structure: { subcommand?: { name: string, matches: { args: Record<string, ArgData> } }, args: Record<string, ArgData> } where ArgData contains { value, occurrences }. When using withGlobalTauri: true, access via window.__TAURI__.cli.getMatches().
CLI plugin Rust API
Use the CliExt trait from tauri_plugin_cli. Call app.cli().matches() in the setup callback to get a Matches struct with fields: args (HashMap<String, ArgData> where ArgData is a struct with { value, occurrences }), and subcommand (Option<Box<SubcommandMatches>> where SubcommandMatches is a struct with { name, matches }).
Tauri CLI installation with deno
Install the Tauri CLI using deno with the command: deno add -D npm:@tauri-apps/cli@latest
Tauri CLI purpose
The Tauri command line interface (CLI) is the primary way to interact with Tauri throughout the development lifecycle.
Tauri CLI installation with npm
Install the Tauri CLI using npm with the command: npm install --save-dev @tauri-apps/cli@latest
Tauri CLI installation with yarn
Install the Tauri CLI using yarn with the command: yarn add -D @tauri-apps/cli@latest
Tauri CLI installation with pnpm
Install the Tauri CLI using pnpm with the command: pnpm add -D @tauri-apps/cli@latest
Tauri CLI installation with cargo
Install the Tauri CLI using cargo with the command: cargo install tauri-cli --version "^2.0.0" --locked
Tauri system tray Linux environment variable
TAURI_LINUX_AYATANA_APPINDICATOR: Set this variable to true or 1 to force usage of libayatana-appindicator for system tray on Linux.
Tauri CLI environment variables - CI and configuration
CI: If set, the CLI will run in CI mode and won't require any user interaction. TAURI_CLI_CONFIG_DEPTH: Number of levels to traverse and find tauri configuration file. TAURI_CLI_PORT: Port to use for the CLI built-in dev server. TAURI_CLI_WATCHER_IGNORE_FILENAME: Name of a .gitignore-style file to control which files should be watched by the CLI in dev command. The CLI will look for this file name in each directory. TAURI_CLI_NO_DEV_SERVER_WAIT: Skip waiting for the frontend dev server to start before building the tauri application.
Tauri environment variable priority - CLI flag overrides
If both environment variable and CLI flag are used, the CLI flag will have priority.
Tauri bundler environment variables - WiX and GitHub mirror
TAURI_BUNDLER_WIX_FIPS_COMPLIANT: Specify the bundler's WiX FipsCompliant option. TAURI_BUNDLER_TOOLS_GITHUB_MIRROR: Specify a GitHub mirror to download files and tools used by tauri bundler. TAURI_BUNDLER_TOOLS_GITHUB_MIRROR_TEMPLATE: Specify a GitHub mirror template to download files and tools used by tauri bundler, for example: https://mirror.example.com/<owner>/<repo>/releases/download/<version>/<asset>.
Tauri code signing environment variables
TAURI_SIGNING_PRIVATE_KEY: Private key used to sign your app bundles, can be either a string or a path to the file. TAURI_SIGNING_PRIVATE_KEY_PASSWORD: The signing private key password. TAURI_SIGNING_RPM_KEY: The private GPG key used to sign the RPM bundle, exported to its ASCII-armored format. TAURI_SIGNING_RPM_KEY_PASSPHRASE: The GPG key passphrase for TAURI_SIGNING_RPM_KEY, if needed. TAURI_WINDOWS_SIGNTOOL_PATH: Specify a path to signtool.exe used for code signing the application on Windows. TAURI_SKIP_SIDECAR_SIGNATURE_CHECK: Skip signing sidecars.
Apple code signing environment variables
APPLE_CERTIFICATE: Base64 encoded of the .p12 certificate for code signing. To get this value, run openssl base64 -A -in MyCertificate.p12 -out MyCertificate-base64.txt. APPLE_CERTIFICATE_PASSWORD: The password you used to export the certificate. APPLE_SIGNING_IDENTITY: The identity used to code sign. Overwrites tauri.conf.json > bundle > macOS > signingIdentity. If neither are set, it is inferred from APPLE_CERTIFICATE when provided.
Apple notarization environment variables
APPLE_ID: The Apple ID used to notarize the application. If this environment variable is provided, APPLE_PASSWORD and APPLE_TEAM_ID must also be set. Alternatively, APPLE_API_KEY and APPLE_API_ISSUER can be used to authenticate. APPLE_PASSWORD: The Apple password used to authenticate for application notarization. Required if APPLE_ID is specified. An app-specific password can be used. Alternatively to entering the password in plaintext, it may also be specified using a '@keychain:' or '@env:' prefix followed by a keychain password item name or environment variable name. APPLE_TEAM_ID: Developer team ID. To find your Team ID, go to the Account page on the Apple Developer website, and check your membership details. APPLE_PROVIDER_SHORT_NAME: If your Apple ID is connected to multiple teams, you have to specify the provider short name of the team you want to use to notarize your app. Overwrites tauri.conf.json > bundle > macOS > providerShortName.
Apple API key authentication environment variables
APPLE_API_KEY: Alternative to APPLE_ID and APPLE_PASSWORD for notarization authentication using JWT. Also an option to allow automated iOS certificate and provisioning profile management. See creating API keys for more information. APPLE_API_ISSUER: Issuer ID. Required if APPLE_API_KEY is specified. APPLE_API_KEY_PATH: Path to the API key .p8 file. If not specified, for macOS apps the bundler searches the following directories in sequence for a private key file with the name of 'AuthKey_<api_key>.p8': './private_keys', '~/private_keys', '~/.private_keys', and '~/.appstoreconnect/private_keys'. For iOS this variable is required. API_PRIVATE_KEYS_DIR: Specify the directory where your AuthKey file is located.
Apple iOS development environment variables
APPLE_DEVELOPMENT_TEAM: The team ID used to code sign on iOS. Overwrites tauri.conf.json > bundle > iOS > developmentTeam. Can be found in https://developer.apple.com/account#MembershipDetailsCard.
Tauri platform and project path environment variables
TAURI_WEBVIEW_AUTOMATION: Enables webview automation (Linux Only). TAURI_ANDROID_PROJECT_PATH: Path of the tauri android project, usually will be <project>/src-tauri/gen/android. TAURI_IOS_PROJECT_PATH: Path of the tauri iOS project, usually will be <project>/src-tauri/gen/ios.
Tauri CLI hook command environment variables
These environment variables are set for each hook command (beforeDevCommand, beforeBuildCommand, etc.) which could be useful to conditionally build your frontend or execute a specific action. TAURI_ENV_DEBUG: true for dev command or build --debug, false otherwise. TAURI_ENV_TARGET_TRIPLE: Target triple the CLI is building. TAURI_ENV_ARCH: Target arch, x86_64, aarch64, etc. TAURI_ENV_PLATFORM: Target platform, windows, darwin, linux, etc. TAURI_ENV_PLATFORM_VERSION: Build platform version. TAURI_ENV_FAMILY: Target platform family unix or windows.
iOS commands availability
All iOS commands are only available on macOS hosts.
iOS CLI command structure
The tauri ios command has four subcommands: init (initialize iOS target), dev (run in development mode), build (build for release and generate IPAs), and run (run in production mode). All commands support -v/--verbose for verbose logging, -h/--help for help, and -V/--version for version information.
ios init command options
The ios init command accepts: --ci to skip prompting for values (env: CI=), -v/--verbose for verbose logging, -r/--reinstall-deps to reinstall dependencies, --skip-targets-install to skip installing rust toolchains via rustup, -c/--config to provide JSON/JSON5/TOML configuration files to merge with the default configuration (platform-specific files like tauri.ios.conf.json are merged by default).
ios dev command purpose and environment
The ios dev command runs the app in development mode on iOS with hot-reloading for Rust code. It uses the build.devUrl property from tauri.conf.json and runs the build.beforeDevCommand which usually starts the frontend dev server. When connected to a physical iOS device, the public network address must be used instead of localhost for the devUrl property, which Tauri changes automatically. The TAURI_DEV_HOST environment variable indicates whether the public network should be used.
ios dev command options
The ios dev command accepts: -f/--features to list cargo features to activate, -v/--verbose for verbose logging, -e/--exit-on-panic to exit on panic, -c/--config for configuration files, --release to run in release mode, --no-dev-server-wait to skip waiting for the frontend dev server (env: TAURI_CLI_NO_DEV_SERVER_WAIT=), --no-watch to disable file watcher, --additional-watch-folders for additional paths to watch, -o/--open to open Xcode instead of running on device, --force-ip-prompt to force IP prompting for dev server connection, --host to use public network address for dev server (optionally accepts an address, default: <none>, sets TAURI_DEV_HOST environment variable), --no-dev-server to disable built-in dev server for static files, --port to specify dev server port (default 1430, env: TAURI_CLI_PORT=), --root-certificate-path for HTTPS certificate file for mobile dev (env: TAURI_DEV_ROOT_CERTIFICATE_PATH=).
ios build command purpose
The ios build command builds the app in release mode for iOS and generates IPAs. It uses the build.frontendDist property from tauri.conf.json and runs the build.beforeBuildCommand which usually builds the frontend into build.frontendDist.
ios build command options
The ios build command accepts: -d/--debug to build with the debug flag, -v/--verbose for verbose logging, -t/--target to specify which targets to build (possible values: aarch64, aarch64-sim, x86_64, default: aarch64), -f/--features to list cargo features to activate, -c/--config for configuration files, --build-number to append a build number to the app version, -o/--open to open Xcode, --ci to skip prompting for values (env: CI=), --export-method to describe how Xcode should export the archive (possible values: app-store-connect, release-testing, debugging), --ignore-version-mismatches to not error out on version mismatch detected in Tauri packages.
ios run command purpose
The ios run command runs the app in production mode on iOS. It uses the build.frontendDist property from tauri.conf.json and runs the build.beforeBuildCommand which usually builds the frontend into build.frontendDist.
ios run command device and arguments
The ios run command accepts an optional [DEVICE] argument to run on a given device name, and command line arguments passed to the runner after '--'. Example usage: tauri ios run [device-name] -- [runnerArgs]
ios run command options
The ios run command accepts: -r/--release to run the app in release mode, -v/--verbose for verbose logging, -f/--features to list cargo features to activate, -c/--config for configuration files, --no-watch to disable file watcher, --additional-watch-folders for additional paths to watch, -o/--open to open Xcode, --ignore-version-mismatches to not error out on version mismatch detected in Tauri packages.
TAURI_DEV_HOST environment variable purpose
The TAURI_DEV_HOST environment variable is set by the CLI when running on an iOS device or when the --host option is used. It indicates whether the public network address should be used for the development server, allowing the framework's configuration to expose the development server on the public network address.