Capacitor CLI provides a comprehensive command-line interface for managing Capacitor projects throughout the development lifecycle.
Primary functions for running the Capacitor CLI programmatically.
/**
* Main CLI entry point - loads config and runs the program
*/
function run(): Promise<void>;
/**
* Configures and runs the CLI program with provided config
* @param config - Loaded Capacitor configuration
*/
function runProgram(config: Config): void;Initialize Capacitor configuration in an existing project.
npx cap init [appName] [appId] [options]Options:
--web-dir <value> - Directory of your project's built web assets--skip-appid-validation - Skip validating the app ID for iOS and Android compatibilityfunction initCommand(
config: Config,
name: string,
id: string,
webDirFromCLI?: string,
skipAppIDValidation?: boolean
): Promise<void>;Usage Examples:
# Interactive initialization
npx cap init
# Specify app details
npx cap init "My App" com.example.myapp
# Custom web directory
npx cap init "My App" com.example.myapp --web-dir buildAdd a native platform project to your Capacitor app.
npx cap add [platform] [options]Options:
--packagemanager <packageManager> - Package manager for dependency installs (CocoaPods or SPM)function addCommand(config: Config, platform: string): Promise<void>;Usage Examples:
# Add iOS platform
npx cap add ios
# Add Android platform
npx cap add android
# Add iOS with Swift Package Manager
npx cap add ios --packagemanager SPMCopy web assets and update native dependencies (combines copy + update).
npx cap sync [platform] [options]Options:
--deployment - Use deployment option for pod install--inline - Inline all source maps for easier debugging on mobile devicesfunction syncCommand(
config: Config,
selectedPlatformName: string,
deployment: boolean,
inline?: boolean
): Promise<void>;
function sync(
config: Config,
platformName: string,
deployment: boolean,
inline?: boolean
): Promise<void>;Copy web app build into the native app.
npx cap copy [platform] [options]Options:
--inline - Inline all source maps for easier debugging on mobile devicesfunction copy(config: Config, platformName: string, inline?: boolean): Promise<void>;Update native plugins and dependencies based on package.json.
npx cap update [platform] [options]Options:
--deployment - Use deployment option for pod installfunction update(config: Config, platformName: string, deployment: boolean): Promise<void>;Usage Examples:
# Sync all platforms
npx cap sync
# Sync specific platform
npx cap sync ios
# Copy with inline source maps
npx cap copy android --inline
# Update with deployment flag
npx cap update ios --deploymentBuild the release version of the selected platform.
npx cap build <platform> [options]Options:
--scheme <schemeToBuild> - iOS Scheme to build--flavor <flavorToBuild> - Android Flavor to build--keystorepath <keystorePath> - Path to the keystore (Android)--keystorepass <keystorePass> - Password to the keystore (Android)--keystorealias <keystoreAlias> - Key Alias in the keystore (Android)--keystorealiaspass <keystoreAliasPass> - Password for the Key Alias (Android)--androidreleasetype <type> - Release type: APK or AAB--signing-type <signingtype> - Program used to sign apps (apksigner or jarsigner)--configuration <name> - Configuration name of the iOS Schemeinterface BuildCommandOptions {
scheme?: string;
flavor?: string;
keystorepath?: string;
keystorepass?: string;
keystorealias?: string;
keystorealiaspass?: string;
androidreleasetype?: 'AAB' | 'APK';
signingtype?: 'apksigner' | 'jarsigner';
configuration: string; // Required property
xcodeTeamId?: string;
xcodeExportMethod?: string;
xcodeSigningType?: 'automatic' | 'manual';
xcodeSigningCertificate?: string;
xcodeProvisioningProfile?: string;
}Run sync, then build and deploy the native app.
npx cap run [platform] [options]Options:
--scheme <schemeName> - Set the scheme of the iOS project--flavor <flavorName> - Set the flavor of the Android project--list - List targets, then quit--target <id> - Use a specific target--no-sync - Do not run sync--forwardPorts <port:port> - Automatically run "adb reverse" for better live-reloading support-l, --live-reload - Enable Live Reload--host <host> - Host used for live reload--port <port> - Port used for live reload--configuration <name> - Configuration name of the iOS Schemeinterface RunCommandOptions {
scheme?: string;
flavor?: string;
list?: boolean;
json?: boolean;
target?: string;
sync?: boolean;
forwardPorts?: string;
liveReload?: boolean;
host?: string;
port?: string;
configuration?: string;
}Usage Examples:
# Build Android APK
npx cap build android --androidreleasetype APK
# Build iOS with specific scheme
npx cap build ios --scheme MyAppScheme
# Run on device with live reload
npx cap run ios --live-reload --host 192.168.1.100
# List available targets
npx cap run android --list
# Run on specific target
npx cap run ios --target "iPhone 15 Pro"Open the native project workspace (Xcode for iOS, Android Studio for Android).
npx cap open [platform]function openCommand(config: Config, platform: string): Promise<void>;Check the current setup for common errors.
npx cap doctor [platform]function doctorCommand(config: Config, platform?: string): Promise<void>;List installed Cordova and Capacitor plugins.
npx cap ls [platform]function listCommand(config: Config, platform?: string): Promise<void>;Usage Examples:
# Open iOS project in Xcode
npx cap open ios
# Open Android project in Android Studio
npx cap open android
# Check setup for all platforms
npx cap doctor
# Check iOS-specific setup
npx cap doctor ios
# List all plugins
npx cap ls
# List Android-specific plugins
npx cap ls androidMigrate your current Capacitor app to the latest major version of Capacitor.
npx cap migrate [options]Options:
--noprompt - Do not prompt for confirmation--packagemanager <packageManager> - Package manager to use for dependency installs (npm, pnpm, yarn)function migrateCommand(
config: Config,
noprompt?: boolean,
packagemanager?: string
): Promise<void>;Remove Cocoapods from project and switch to Swift Package Manager.
npx cap spm-migration-assistantUsage Examples:
# Interactive migration
npx cap migrate
# Migrate without prompts using yarn
npx cap migrate --noprompt --packagemanager yarn
# Migrate iOS to Swift Package Manager
npx cap spm-migration-assistantPrint evaluated Capacitor config (hidden command).
npx cap config [options]Options:
--json - Print in JSON formatfunction configCommand(config: Config, json?: boolean): Promise<void>;Enable or disable telemetry (hidden command).
npx cap telemetry [on|off]Usage Examples:
# View current config
npx cap config
# View config as JSON
npx cap config --json
# Enable telemetry
npx cap telemetry on
# Disable telemetry
npx cap telemetry offStart a new Capacitor plugin (hidden command).
npx cap plugin:generateUsage Example:
# Create a new plugin
npx cap plugin:generateAll commands operate within the context of a loaded Capacitor configuration and provide comprehensive error handling and validation.
type CommanderAction = (...args: any[]) => void | Promise<void>;
function wrapAction(action: CommanderAction): CommanderAction;