12k
All articles

Building a Raycast Extension with React

Build a Raycast extension with React and TypeScript: create a live npm package search with List, keyboard actions, user preferences, and Store publishing.

OpenReplay Team
OpenReplay Team
Building a Raycast Extension with React

A Raycast extension is an npm project written in React and TypeScript. Your components return Raycast primitives such as List, Detail and ActionPanel, and Raycast draws them in its own interface, so you never write HTML, DOM code or CSS.

Most developers have a few lookups they run dozens of times a day, like finding a package name, checking its version and copying the install line. Those small trips through a browser tab add up. This guide builds one complete command, a live npm package search, with a List view, keyboard actions, a user preference, and the steps to publish it to the Store.

Key Takeaways

  • Each entry in the commands array of package.json maps to a file in src/ with the same name, and the default-exported React component in that file runs when the command opens.
  • useFetch from @raycast/utils returns data and isLoading, and its execute option delays the request until the query is ready.
  • Setting throttle on List delays onSearchTextChange while the user types, which suits search that hits the network.
  • npm run publish opens a pull request against raycast/extensions, and Raycast publishes the extension to the Store once that PR is reviewed and merged.

What Is a Raycast Extension?

A Raycast extension adds commands to the search bar of Raycast, a keyboard-driven launcher for macOS and Windows. As the Raycast for Windows announcement puts it, extensions are built with React and TypeScript. So if you know web development, you already know how to build for Raycast. The main difference is the render target. You don’t write markup. You compose Raycast’s components, and Raycast draws them with its own native-looking styling. The same idea shows up in OpenReplay’s article on building command-line apps with React Ink, where React renders to a terminal instead of the DOM.

How Do You Create a Raycast Extension?

To create a Raycast extension, open Raycast, run the Create Extension command (it requires sign-in), pick a List-based template, and choose a folder. Then install and start the dev server:

npm install && npm run dev

The Getting Started page asks for npm 7 or higher and Node.js 22.14 or higher, but the API changelog entry for version 2.0.0 (August 25, 2026) raises the CLI’s minimum to Node.js 22.22.2, so install that version or newer. As the Create Your First Extension guide describes, npm run dev puts the command at the top of root search with hot reloading. The command stays installed after you stop the dev server. The entry file is ./src/index.tsx.

Project Layout and the package.json Manifest

The package.json file is both your npm config and the extension manifest. Raycast reads commands, metadata and preferences from it. The manifest reference defines these fields:

FieldPurpose
nameUnique extension identifier
titleDisplay name in Raycast and the Store
description, iconStore listing text and image
authorYour Raycast Store handle
categoriesStore categories; at least one is required to publish
commands[].nameCommand ID; matches src/<name>.tsx
commands[].modeview for commands that render UI
preferences[]User settings shown in Raycast
platforms"macOS" and/or "Windows"
{
  "$schema": "https://www.raycast.com/schemas/extension.json",
  "name": "npm-search",
  "title": "npm Search",
  "description": "Search the npm registry from Raycast",
  "icon": "extension-icon.png",
  "author": "your-raycast-username",
  "license": "MIT",
  "categories": ["Developer Tools"],
  "platforms": ["macOS", "Windows"],
  "commands": [
    { "name": "index", "title": "Search npm Packages", "description": "Search npm and open or copy results", "mode": "view" }
  ],
  "preferences": [
    { "name": "resultLimit", "type": "textfield", "required": false, "default": "20", "title": "Result Limit", "description": "Maximum packages to show" }
  ]
}

Keep the dependencies block that the template generated. Don’t copy version pins from older tutorials.

Search npm Packages with List and useFetch

To search as the user types, pass a state setter to List’s onSearchTextChange and feed that query into useFetch. According to the List reference, adding an onSearchTextChange handler turns off Raycast’s built-in filtering, so the list shows the registry’s results as they arrive. The same reference suggests turning on throttle whenever your own search logic makes async calls, such as network requests.

The npm registry search endpoint is GET /-/v1/search. It accepts text and size (default 20, max 250) and returns an objects array in which each entry has a package with name, version, description and links.npm.

import { Action, ActionPanel, List, getPreferenceValues } from "@raycast/api";
import { useFetch } from "@raycast/utils";
import { useState } from "react";

type NpmSearch = {
  objects: { package: { name: string; version: string; description?: string; links: { npm: string } } }[];
};

export default function Command() {
  const { resultLimit } = getPreferenceValues<{ resultLimit?: string }>();
  const size = Math.min(Number(resultLimit) || 20, 250);
  const [query, setQuery] = useState("");
  const hasQuery = query.trim().length > 0;

  const { data, isLoading } = useFetch<NpmSearch>(
    `https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(query)}&size=${size}`,
    { execute: hasQuery, keepPreviousData: true },
  );

  const packages = hasQuery ? (data?.objects ?? []) : [];

  return (
    <List isLoading={isLoading} onSearchTextChange={setQuery} throttle searchBarPlaceholder="Search npm packages">
      <List.EmptyView title={hasQuery ? "No packages found" : "Type to search npm"} />
      {packages.map(({ package: pkg }) => (
        <List.Item
          key={pkg.name}
          title={pkg.name}
          subtitle={pkg.description}
          accessories={[{ text: pkg.version }]}
          actions={
            <ActionPanel>
              <Action.OpenInBrowser url={pkg.links.npm} />
              <Action.CopyToClipboard title="Copy Install Command" content={`npm install ${pkg.name}`} />
            </ActionPanel>
          }
        />
      ))}
    </List>
  );
}

The useFetch execute flag lets you define the hook right away but wait until all the arguments are ready before the request runs. keepPreviousData keeps the last results on screen while the next request is in flight, which stops the list from flickering.

In useFetch, data stays undefined until the first response arrives. A call like data.objects.map(...) therefore throws on the first render. The data?.objects ?? [] fallback covers that render, and isLoading shows the spinner in the meantime.

Add Actions: Open in Browser and Copy to Clipboard

An ActionPanel attached to each List.Item turns a result into something the user can act on. The Actions reference defines both components used here. Action.OpenInBrowser opens a URL in the default browser, then closes the main window. Action.CopyToClipboard copies the content, hides the main window and confirms the copy with a HUD.

Action order matters in a Raycast ActionPanel. According to the Raycast manual, pressing ↵ triggers the primary action (the first action in the list) immediately, and ⌘K opens the full panel. Put the action users want most often first.

Read a Preference with getPreferenceValues

Settings such as result limits or API tokens belong in the manifest’s preferences array. The command reads them at runtime with getPreferenceValues. Raycast shows a settings form for every declared preference, so you don’t need to build any UI for it.

The npm search example passes an inline type argument to getPreferenceValues. Raycast also generates a global Preferences type from the manifest, so getPreferenceValues<Preferences>() stays in sync automatically, as code in the raycast/extensions repository commonly does. If you switch to a GitHub search, declare a password-type githubToken preference and send it as an Authorization header through useFetch’s request options.

How Do You Publish a Raycast Extension?

Publishing a Raycast extension means opening a pull request against the raycast/extensions repository. Run lint and build first:

npm scriptRunsUse
devray developLocal development with hot reload
buildray buildProduction build check
lint / fix-lintray lint / ray lint --fixFix every issue before publishing
publishnpx @raycast/api@latest publishOpens the Store PR

The Publish an Extension page describes the flow. npm run publish asks you to authenticate with GitHub, opens the PR automatically, and squashes your commits. Raycast reviews the PR and may request changes. Once the PR is merged, the extension goes to the Store automatically.

On Windows, the Raycast for Windows page says all extensions that do not require native code will work out of the box on both platforms. Set platforms to ["macOS", "Windows"] to opt in. The Store guidelines require platforms to match what the extension actually needs, so restrict it if you call platform-specific APIs.

Conclusion

A useful Raycast extension needs three pieces: a List driven by throttled search, an ActionPanel that puts the most common action on ↵, and preferences declared in the manifest. Run npm run dev on the command above, swap the npm endpoint for the API you query most, and run npm run lint until it passes before you open your Store PR.

FAQs

What is the difference between view, no-view and menu-bar commands in a Raycast extension?

The mode field on each commands entry decides how the command runs. A view command default-exports a React component that Raycast renders as the main UI, such as a List or Detail. A no-view command exports an async function and talks to the user through APIs like showHUD or showToast, which suits opening a URL. A menu-bar command returns a MenuBarExtra item shown in the macOS menu bar.

Can I share a Raycast extension with my team without publishing it to the public Store?

Yes. Set the owner field in package.json to your Raycast organization handle, then run npm run publish. For a private extension, the command verifies, builds and publishes it straight to the organization's private store. It opens no pull request against raycast/extensions, and only members of that organization can install it. You must be logged in, and npx ray login handles that from the CLI.

Can I style a Raycast extension with CSS or custom HTML?

No. Raycast renders its supported React components to its own native UI, so there is no stylesheet or DOM to target. You customize through component props such as icons, tag colors and list accessories. For richer content, the Detail component renders a CommonMark markdown string with an optional metadata panel, and raycast-width and raycast-height query parameters on markdown images set their size.

DevTools for the frontend

Gain Debugging Superpowers

Unleash the power of session replay to reproduce bugs, track slowdowns and uncover frustrations in your app. Get complete visibility into your frontend with OpenReplay — the most advanced open-source session replay tool for developers.

Star on GitHub12k

We use cookies to improve your experience. By using our site, you accept cookies.