Skip to main content

Overview

The pm x command executes packages directly from the registry without permanently installing them. It’s the Better PM equivalent of npx, pnpx, or bunx, automatically using the right tool for your package manager.

Syntax

pm x <package> [...args]

Arguments

package
string
required
The package or command to execute
args
string[]
Arguments to pass to the executed command

Examples

Run Package Binary

pm x typescript --version
Output
Running: pnpx typescript --version
Version 5.0.0

Execute One-off Command

pm x create-vite my-app
Output
Running: pnpx create-vite my-app

Run CLI Tool

pm x prettier --write .
Output
Running: pnpx prettier --write .

Execute with Arguments

pm x eslint --init
Output
Running: pnpx eslint --init

Run Versioned Package

pm x [email protected] --version
Output
Running: pnpx [email protected] --version

Package Manager Mapping

Better PM automatically uses the appropriate execution tool:
Package ManagerTool UsedExample
pnpmpnpxpnpx create-vite
bunbunxbunx create-vite
npmnpxnpx create-vite
You don’t need to remember which tool to use - pm x handles it automatically.
From src/commands/x.ts:13-14:
const execBin =
  pm.name === 'pnpm' ? 'pnpx' : pm.name === 'bun' ? 'bunx' : 'npx';

Use Cases

Project Scaffolding

Create new projects without global installs:
pm x create-next-app my-app
pm x create-vite my-app --template react
pm x degit user/repo my-project

One-time Tools

Run tools you don’t need permanently:
pm x prettier --check .
pm x eslint --fix src/
pm x markdownlint **/*.md

Version Testing

Test different package versions:
pm x [email protected] --version
pm x [email protected] --version
pm x typescript@latest --version

CI/CD Scripts

Run commands without adding to dependencies:
pm x semantic-release
pm x commitizen
pm x lint-staged

Common Commands

Create Projects

pm x create-next-app@latest

Development Tools

pm x prettier --write .

Generators

pm x license mit > LICENSE

How It Works

From src/commands/x.ts:10-19:
export const xCmd = cli.Command.make('x', { args: argsArg }, (args) =>
  Effect.gen(function* () {
    const pm = yield* PackageManagerService;
    const execBin =
      pm.name === 'pnpm' ? 'pnpx' : pm.name === 'bun' ? 'bunx' : 'npx';
    const passthrough = Array.from(args.args);
    const cmd = ShellCommand.make(execBin, ...passthrough);
    yield* Console.log(`Running: ${execBin} ${passthrough.join(' ')}`);
    yield* runShellCommand(cmd);
  }).pipe(Effect.provide(PackageManagerLayer)),
);
The command:
  1. Detects your package manager
  2. Maps to the appropriate execution binary (npx/pnpx/bunx)
  3. Passes all arguments through
  4. Executes the command

Benefits

No Global Installs

Keep your global environment clean:
# Instead of:
npm install -g create-vite
create-vite my-app

# Use:
pm x create-vite my-app

Always Latest Version

Run the latest version without updating:
pm x create-next-app@latest
# Always gets the newest version

Try Before Installing

Test tools before adding to package.json:
pm x vitest
# Try it out first

# If you like it:
pm add -D vitest

Package Manager Agnostic

Same command works everywhere:
pm x prettier --write .
# Works with pnpm, bun, or npm

Performance

Execution tools cache packages for faster subsequent runs:
# First run (downloads package)
pm x prettier --version
# ~2-3 seconds

# Second run (uses cache)
pm x prettier --version
# ~200ms
For frequently used tools, consider installing them locally with pm add -D for even better performance.

Best Practices

Use for Generators

# Perfect for project creation
pm x create-vite my-app

Use for One-off Tasks

# Great for occasional commands
pm x prettier --check .

Install for Repeated Use

# If used frequently, install it
pm add -D prettier
pm run format

Pin Versions for Consistency

# In CI/CD, use specific versions
pm x [email protected] --check .

Common Workflows

Quick Project Setup

pm x create-vite my-app --template react-ts
cd my-app
pm install
pm run dev

Format and Lint

pm x prettier --write .
pm x eslint --fix src/

Generate Files

pm x license mit > LICENSE
pm x gitignore node > .gitignore

Run Scripts

pm x tsx src/script.ts
pm x ts-node src/script.ts
  • pm run - Run package.json scripts
  • pm add - Install packages permanently
  • pm install - Install all dependencies