Send a text to yourself from Next.js

Yes. Homing Pigeon (homingpigeon.dev) lets your Next.js app text your phone from a server action or route handler, like when a new order comes in. Your key stays on the server, out of the browser, and your coding agent can add it to the app you already have.

What to tell your agent

Use Homing Pigeon to text me from this Next.js app when a new order comes in.

Your agent asks for your number, you read back the six-digit code, and it does the rest.

How it works in code

After npm install server-only, add this helper as lib/text-me.js. It runs only on the server, where it reads your key from HOMINGPIGEON_API_KEY:

import "server-only";

export async function textMe(message, idempotencyKey) {
  try {
    const res = await fetch("https://homingpigeon.dev/v1/send", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.HOMINGPIGEON_API_KEY}`,
        "Content-Type": "application/json"
      },
      body: JSON.stringify({ message, idempotency_key: idempotencyKey }),
      cache: "no-store",
      signal: AbortSignal.timeout(5000)
    });
    if (!res.ok) console.warn("Text alert failed:", (await res.json()).error.message);
  } catch (err) {
    console.warn("Text alert failed:", err.message);
  }
}

Then call it from a server action. This one, in app/actions.js, texts you after a new order is saved. Replace saveOrder with your own code and use your own fields:

"use server";

import { textMe } from "../lib/text-me";

export async function placeOrder(formData) {
  const order = await saveOrder(formData);
  await textMe(`New order ${order.id} for $${order.total}.`, `order-${order.id}`);
}

Good to know

  • Next.js copies any variable whose name starts with NEXT_PUBLIC_ into the JavaScript it sends to every visitor's browser. Name the key plain HOMINGPIGEON_API_KEY and read it only in server code like textMe, so it stays on your server.
  • The send must never run in the browser. Anyone who opens your site can read the code that runs there, and with your key they could text your phone whatever they like and use up your texts. A send from browser code fails anyway, because Homing Pigeon's API does not accept requests from web pages.
  • import "server-only" makes next build stop with an error if a Client Component, a file that starts with "use client", ever imports textMe.
  • The same helper works in a route handler: in app/api/orders/route.js, call await textMe(...) inside export async function POST(request). A route handler is a public address, so only send from one that already checks who is calling, such as a webhook that verifies its signature.
  • The try means a failed or slow text never breaks the form or the request. The failure goes to your server log, the 5-second timeout caps how long a send can hold up the response, and cache: "no-store" keeps Next.js from caching the call.
  • The order ID in the idempotency key means a retry never texts you twice for the same order.
  • Verify your phone with npx -y homingpigeondev verify +15551234567, then again with the six-digit code it texts you. npx -y homingpigeondev key then prints your key. Put it in .env.local as HOMINGPIGEON_API_KEY=..., which the .gitignore from create-next-app keeps out of git, and set the same variable in your host's environment settings for production.
  • Messages are limited to 480 characters and go only to the US mobile number you verified. Keep them plain, with no links. Delivery is not guaranteed, so treat each text as a heads-up.

Get started

Add Homing Pigeon to Claude Code, then ask for what you want:

claude mcp add homingpigeondev -- npx -y homingpigeondev mcp

You get 50 free texts every month, on US mobile numbers. See more use cases.