Library MCP Setup About Template Factory ↗
← Library / Overlays & Feedback UI SDK Agentic

App Command Palette (⌘K)

Keyboard-first ⌘K command dialog: a readable raised search bar, grouped commands with shortcut badges, live filtering with a friendly empty state, arrow, Home, End and Enter navigation on a solid highlighted row, and a toast the moment a command runs.

Install UI SDK & packages

npm install @ui-sdk/react @ui-sdk/core lucide-react

Give your agent the UI SDK skill

npx skills add vercel-labs/ui --skill ui-sdk

UI SDK entries: @ui-sdk/react/dialog @ui-sdk/react/command
"use client";

import * as React from "react";
import { Blocks, LayoutDashboard, LifeBuoy, Link2, Moon, Plus, Search, Settings, Users, type LucideIcon } from "lucide-react";
import {
  Command,
  CommandEmpty,
  CommandGroup,
  CommandGroupLabel,
  CommandInput,
  CommandItem,
  CommandItemIcon,
  CommandList,
  CommandShortcut,
} from "@ui-sdk/react/command";
import { Dialog, DialogBackdrop, DialogContent, DialogShortcut, DialogTitle, DialogTrigger } from "@ui-sdk/react/dialog";

const card =
  "rounded-2xl border border-[#d8e0ea] bg-white shadow-[0_18px_44px_rgba(15,23,42,0.12)] dark:border-slate-400/20 dark:bg-[#111827] dark:shadow-[0_24px_60px_rgba(0,0,0,0.5)]";
const fieldBase =
  "w-full min-w-0 rounded-[10px] border-[1.5px] border-slate-300 bg-white text-sm font-medium text-slate-900 shadow-[0_1px_2px_rgba(15,23,42,0.06)] outline-none transition-[border-color,box-shadow] hover:border-slate-400 focus:border-sky-600 focus:ring-[3px] focus:ring-sky-600/25 dark:border-slate-400/35 dark:bg-[#182234] dark:text-slate-50 dark:shadow-[inset_0_1px_2px_rgba(0,0,0,0.35)] dark:hover:border-slate-400/55 dark:focus:border-sky-400 dark:focus:ring-sky-400/30";

const hairline = "border-[#d8e0ea] dark:border-slate-400/20";
const kbdCls =
  "inline-flex h-[22px] min-w-[22px] shrink-0 items-center justify-center rounded-md border border-slate-300 bg-slate-50 px-1.5 font-mono text-[11px] font-semibold text-slate-600 shadow-[inset_0_-1px_0_#d8e0ea] dark:border-slate-400/35 dark:bg-[#162033] dark:text-slate-300 dark:shadow-[inset_0_-1px_0_rgba(148,163,184,0.2)]";

export interface PaletteCommand {
  value: string;
  label: string;
  group: string;
  icon: LucideIcon;
  /** Runs the command while the palette is open, like "alt+d". */
  shortcut?: string;
  keywords?: string[];
  /** Plain-English warning an agent must get approved before running this command. */
  confirm?: string;
}

const DEFAULT_COMMANDS: PaletteCommand[] = [
  { value: "dashboard", label: "Dashboard", group: "Go to", icon: LayoutDashboard, shortcut: "alt+d", keywords: ["home", "overview"] },
  { value: "library", label: "Component library", group: "Go to", icon: Blocks, shortcut: "alt+l", keywords: ["browse", "components"] },
  { value: "settings", label: "Settings", group: "Go to", icon: Settings, shortcut: "alt+s", keywords: ["preferences", "account"] },
  { value: "new-component", label: "New component", group: "Create", icon: Plus, shortcut: "alt+n", keywords: ["add", "create"] },
  { value: "invite", label: "Invite a teammate", group: "Create", icon: Users, shortcut: "alt+i", keywords: ["team", "share", "member"] },
  { value: "copy-mcp", label: "Copy MCP link", group: "Workspace", icon: Link2, shortcut: "alt+c", keywords: ["connect", "claude", "cursor", "url"] },
  { value: "theme", label: "Switch light or dark theme", group: "Workspace", icon: Moon, shortcut: "alt+t", keywords: ["appearance", "mode"] },
  { value: "help", label: "Open help center", group: "Workspace", icon: LifeBuoy, shortcut: "alt+h", keywords: ["docs", "support", "guide"] },
];

export function CommandPaletteDialog({
  commands = DEFAULT_COMMANDS,
  triggerLabel = "Search or run a command",
  searchLabel = "Search commands",
  emptyMessage = "No commands match that. Try another word.",
  shortcut = "mod+k",
  onRun,
}: {
  commands?: PaletteCommand[];
  triggerLabel?: string;
  searchLabel?: string;
  emptyMessage?: string;
  /** Opens the palette from anywhere. "mod" is Command on Apple devices and Control elsewhere. */
  shortcut?: string;
  onRun?: (value: string) => unknown;
}) {
  const [open, setOpen] = React.useState(false);
  const groups = React.useMemo(() => Array.from(new Set(commands.map((item) => item.group))), [commands]);

  return (
    <Dialog open={open} onOpenChange={setOpen}>
      <DialogTrigger
        shortcut={shortcut}
        className="flex h-10 w-full max-w-[420px] cursor-pointer items-center gap-2.5 rounded-[10px] border-[1.5px] border-slate-300 bg-white pr-2.5 pl-3 text-left text-sm font-medium text-slate-600 shadow-[0_1px_2px_rgba(15,23,42,0.06)] transition hover:border-slate-400 hover:text-slate-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500 dark:border-slate-400/35 dark:bg-[#182234] dark:text-slate-400 dark:shadow-[inset_0_1px_2px_rgba(0,0,0,0.35)] dark:hover:border-slate-400/55 dark:hover:text-slate-50"
      >
        <Search className="size-4 shrink-0" aria-hidden="true" />
        <span className="min-w-0 flex-1 truncate">{triggerLabel}</span>
        <DialogShortcut className={`${kbdCls} max-sm:hidden`} />
      </DialogTrigger>
      <DialogBackdrop className="fixed inset-0 z-50 bg-slate-900/45 backdrop-blur-[3px] dark:bg-[#04070d]/70" />
      <DialogContent
        className={`${card} fixed inset-x-0 top-3.5 z-50 mx-auto flex max-h-[min(30rem,calc(100dvh-1.75rem))] w-[min(36rem,calc(100vw-1.75rem))] flex-col overflow-hidden p-0 sm:top-[12vh]`}
      >
        <DialogTitle className="sr-only">Command palette</DialogTitle>
        <Command
          loop
          onAction={(value) => {
            setOpen(false);
            return onRun?.(value);
          }}
          className="flex min-h-0 flex-1 flex-col text-slate-900 dark:text-slate-50"
        >
          <div className={`relative border-b p-3 ${hairline}`}>
            <Search
              className="pointer-events-none absolute top-1/2 left-[26px] size-[18px] -translate-y-1/2 text-slate-600 dark:text-slate-400"
              aria-hidden="true"
            />
            <CommandInput
              aria-label={searchLabel}
              placeholder={searchLabel}
              className={`${fieldBase} h-[46px] pr-3.5 pl-10 placeholder:text-slate-600 dark:placeholder:text-slate-400`}
            />
          </div>
          <CommandEmpty className="px-4 py-8 text-center text-sm text-slate-600 dark:text-slate-400">{emptyMessage}</CommandEmpty>
          <CommandList className="min-h-0 flex-1 overflow-y-auto p-2">
            {groups.map((group) => (
              <CommandGroup key={group}>
                <CommandGroupLabel className="px-2.5 pt-2 pb-1 text-xs font-bold text-slate-600 dark:text-slate-400">{group}</CommandGroupLabel>
                {commands
                  .filter((item) => item.group === group)
                  .map((item) => (
                    <CommandItem
                      key={item.value}
                      value={item.value}
                      label={item.label}
                      keywords={item.keywords}
                      shortcut={item.shortcut}
                      data-agent-confirm={item.confirm}
                      className="flex min-h-[42px] cursor-pointer items-center gap-2.5 rounded-[9px] px-2.5 text-sm font-medium data-highlighted:bg-sky-700 data-highlighted:font-semibold data-highlighted:text-white max-sm:min-h-[46px] dark:data-highlighted:bg-sky-400 dark:data-highlighted:text-[#031521]"
                    >
                      <CommandItemIcon>
                        <item.icon className="size-4" aria-hidden="true" />
                      </CommandItemIcon>
                      <span className="min-w-0 flex-1 truncate">{item.label}</span>
                      {item.shortcut && <CommandShortcut className={`${kbdCls} max-sm:hidden`} />}
                    </CommandItem>
                  ))}
              </CommandGroup>
            ))}
          </CommandList>
          <div
            className={`flex items-center gap-3.5 border-t bg-slate-50 px-3.5 py-2 text-xs text-slate-600 max-sm:hidden dark:bg-[#162033] dark:text-slate-400 ${hairline}`}
          >
            <span className="inline-flex items-center gap-1.5">
              <kbd className={kbdCls}>↑</kbd>
              <kbd className={kbdCls}>↓</kbd>
              to move
            </span>
            <span className="inline-flex items-center gap-1.5">
              <kbd className={kbdCls}>↵</kbd>
              to run
            </span>
            <span className="inline-flex items-center gap-1.5">
              <kbd className={kbdCls}>Esc</kbd>
              to close
            </span>
          </div>
        </Command>
      </DialogContent>
    </Dialog>
  );
}

export default CommandPaletteDialog;