LM Studio CLI

repository·main·Indexed 25 days ago

https://github.com/lmstudio-ai/lms

A 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).

Tokens
3.5K
Snippets
8
Records
30
Agent score
89%

What's inside lms

  1. Use the lms CLI

    main
    The 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 --help
  2. Build and test the lms CLI from source

    main

    The 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:

    1. Clone the monorepo recursively.
    2. Install dependencies.
    3. Run the build script.
    4. Execute the built CLI using 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>
  3. Available `lms` CLI Commands

    main

    The lms CLI is organized into several functional groups. Use lms --help to see the full list of available commands and their descriptions.

    Local models

    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).

    Serve

    Commands for running and monitoring servers:

    • server: Start a local server.
    • log: View server logs.

    Remote Instances

    • link: Link to remote instances.

    Runtime

    • runtime: Manage the LM Studio runtime.

    Develop & Publish (Beta)

    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.
  4. Manage LM Studio and API Server with lms

    main

    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.
  5. List and manage models with lms

    main

    Use 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.
  6. Create an authenticated LM Studio client with `createClient()`

    main

    Use createClient() to resolve an LM Studio instance and return an authenticated LMStudioClient.

    Connection Modes

    • Local Connection: If 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.
    • Remote Connection: If a 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.

    Arguments

    • 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).
  7. Start an interactive chat session

    main

    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.
  8. Handle non-interactive chat prompts

    main

    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.
  9. Configure CLI connection options with `addCreateClientOptions()`

    main

    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.

    Added Options

    • --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.