Use the lms CLI
mainlms CLI provides subcommands to manage LM Studio, control the local API server, and manage models. Use lms --help to see all available subcommands, or lms <subcommand> --help for specific details on a command.lms --helprepository·main·Indexed 25 days ago
https://github.com/lmstudio-ai/lmsA command-line interface for LM Studio built with lmstudio.js. It enables developers to programmatically manage models, control the local API server, start interactive or non-interactive chat sessions, and manage the LM Studio daemon. The CLI includes subcommands for model lifecycle management (ls, ps, load, unload), server control (start, stop, log), and plugin development (dev).
lms CLI provides subcommands to manage LM Studio, control the local API server, and manage models. Use lms --help to see all available subcommands, or lms <subcommand> --help for specific details on a command.lms --helpThe lms command line tool ships with LM Studio version 0.2.22 and newer. If the command is not found in your path, you can install it using npx.
npx lmstudio install-cliThe CLI is part of the lmstudio-js monorepo and must be built within that environment. To build the project and test changes locally, follow these steps:
node pointing to the distribution index.# Clone and build the entire monorepo
git clone https://github.com/lmstudio-ai/lmstudio-js.git --recursive
cd lmstudio-js
npm install
npm run build
# Test your CLI changes
node publish/cli/dist/index.js <subcommand>The lms CLI is organized into several functional groups. Use lms --help to see the full list of available commands and their descriptions.
Commands for managing models on your local machine:
chat: Start an interactive chat session.get: Download a model.load: Load a model into memory.unload: Unload a model from memory.ls: List available models.ps: List currently loaded/running models.importCmd: Import models (internal/utility).Commands for running and monitoring servers:
server: Start a local server.log: View server logs.link: Link to remote instances.runtime: Manage the LM Studio runtime.Commands for developers and publishing workflows:
clone: Clone repositories.push: Push models/content.dev: Development mode.login: Authenticate with LM Studio.logout: Log out of LM Studio.whoami: Check current authentication status.Use these commands to control the LM Studio application and its local API server:
lms status: Check the current status of LM Studio.lms server start: Start the local API server.lms server stop: Stop the local API server.lms log stream: Stream logs from LM Studio.lms create command to initialize a new project using the LM Studio SDK.lms createUse these commands to view and control loaded or downloaded models:
lms ls: List all downloaded models. Use --json for machine-readable output.lms ps: List all loaded models available for inferencing. Use --json for machine-readable output.lms load <model path> -y: Load a model with maximum GPU acceleration without requiring confirmation.lms unload <model identifier>: Unload a specific model.lms unload --all: Unload all currently loaded models.Use createClient() to resolve an LM Studio instance and return an authenticated LMStudioClient.
host is not provided, it defaults to 127.0.0.1. The function will attempt to discover or start the local API server. If successful, it uses a privileged lms-cli identifier.host is provided, it is treated as a remote instance. The client will use a non-privileged identifier (e.g., lms-cli-remote-<random chars>), which restricts certain functionalities like lms push.logger: A SimpleLogger instance for logging.args: An object of type CreateClientArgs containing:host (string, optional): The host address. Must not include a protocol (e.g., http://) or a port number.port (number, optional): The port where LM Studio is reachable. Defaults to 1234 if a host is provided but no port is specified. If connecting locally to 127.0.0.1 and no port is provided, it attempts to discover the active port.yes (boolean, optional): Part of CreateClientArgs (usage context dependent)._opts: An object of type CreateClientOpts (currently empty).Use startInteractiveChat to launch the terminal-based interactive UI (built with ink). This function manages the lifecycle of the interactive session and resolves when the user exits the chat.
Parameters:
client: The LMStudioClient instance.chat: The Chat instance.opts: StartPredictionOpts (stats, ttl, reasoningMode).logger: SimpleLogger instance.llm: The loaded LLM instance (can be undefined to allow selection within the UI).shouldFetchModelCatalog: Boolean indicating if the catalog should be fetched.getServerConfig function allows you to retrieve the last known configuration of the server (port and network interface) from the persisted configuration file.Use handleNonInteractiveChat to execute a single prompt and exit. This is useful for automation or scripting where you want the model's response streamed to stdout without an interactive UI.
Parameters:
llm: The loaded LLM instance.chat: The Chat instance containing the conversation history.prompt: The string prompt to send.logger: A SimpleLogger instance.opts: An object of type StartPredictionOpts containing:stats (optional): If true, displays verbose prediction statistics.ttl (number): Time-to-live for the model.reasoningMode (ReasoningMode): The reasoning mode to use.When building custom CLI commands using commander.js, use addCreateClientOptions() to automatically attach the necessary connection flags to your command. This ensures consistent handling of host and port arguments.
--host <host>: Specify the host for a remote LM Studio instance. Note that remote connections use a non-privileged client identifier.--port <port>: The port where LM Studio can be reached. If the host is 127.0.0.1 (default) and no port is provided, the last used port is used; otherwise, it defaults to 1234.