Log inStart Free Trial
Meta Tech Provider

Build a WhatsApp bot with Claude Code or Codex, on the number you keep in the app

Add a WhatsApp MCP server to Claude Code or Codex and let the coding agent do the setup: it reads the number's Cloud API credentials, scaffolds a webhook receiver, routes incoming messages to it and sends a test reply to someone who wrote in the last 24 hours. What you end up with is your own agent, running as your code on your server.

easyCoexistence connects the WhatsApp Business number you keep in the app to Meta's Cloud API through Coexistence and gives Claude Code and Codex more than 30 MCP tools to build with: credentials, routing, templates, test sends and automations.

--scope user

Claude Code flag that loads a server in all your projects; the default local scope loads it only where it was added.

codex mcp login

Codex command that stores a server's OAuth sign-in; with no credential, Codex can connect without authentication.

HTTPS

What a direct webhook destination must use, and it must echo hub.challenge in Meta's GET handshake.

20 seconds

How long a Call my webhook step waits for your endpoint's {"reply"} before the step fails.

24 hours

Customer service window after the user's last message; outside it, Meta accepts only template messages.

20 msg/s

Fixed throughput of a number used with both the WhatsApp Business app and the Cloud API.

What does a coding agent need to build a WhatsApp agent?

Four things. A WhatsApp Business number connected to Meta's Cloud API through Coexistence, so the app stays on the phone while code can send and receive. An MCP connection from Claude Code or Codex to that number, which lets the coding agent read credentials, change routing and send test messages without you opening a dashboard. A public HTTPS address for the receiver, from a host you deploy to or a tunnel while you develop. And a model key for the agent you are building.

Keep the two agents apart in your head. Claude Code or Codex is the builder: it acts only while you work with it in the terminal. The program it writes is the one that answers customers, and it keeps running after you close the session.

How do you add the WhatsApp tools to Claude Code and Codex?

Each takes one URL from the terminal and signs in with OAuth, so no key goes into a file. In Claude Code, add the server with --scope user so it loads in every project, then start claude, run /mcp, pick easycoexistence and sign in in the browser. In Codex, add the server and run codex mcp login, which stores the sign-in; codex mcp list shows what is configured. Codex keeps the entry in ~/.codex/config.toml, which the ChatGPT desktop app and the Codex IDE extension read too.

Check it worked by asking for something only the tools can answer, such as "list my WhatsApp numbers". The agent calls list_numbers and gets each number's connection_id, which every other tool takes.

Add the server, then sign in
# Claude Code: then start claude and run /mcp to sign in
claude mcp add --transport http easycoexistence --scope user https://easycoexistence.com/api/mcp

# Codex: add, store the OAuth sign-in, check
codex mcp add easycoexistence --url https://easycoexistence.com/api/mcp
codex mcp login easycoexistence
codex mcp list

Which route should the agent build?

Three routes bring a customer's message to your code, and they differ in how much the code has to handle. For a first version, the Call my webhook step is the shortest: easyCoexistence skips duplicates, steps back when you answer from the phone and checks the 24-hour window before your endpoint is called, so your code only writes the reply. Move to a Forward URL or a direct destination when the agent needs every event, not only the messages an automation picks.

Call my webhook stepAn automation POSTs the message and the chat's last 10 messages, signed; return {"reply": "..."} within 20 seconds
Forward URL (Automations on)A signed copy of each Meta event goes to your code; automations keep running; you send through the Graph API
Direct destinationMeta posts straight to your endpoint; easyCoexistence never sees the messages; automations stop for that number

What should you ask the coding agent to do?

Give it the route, the language and the rules up front, and ask for a plan before it writes code. Tell it which tool calls it may make on its own: reading credentials and docs is harmless, while changing where messages go affects the live number. get_docs returns easyCoexistence's documentation, including how a receiver authenticates deliveries, so the agent can read the rules instead of guessing them. A request like this one produces a receiver you can review in one sitting:

A request for Claude Code or Codex
Build a WhatsApp agent in Node.js for my number +55 11 4000 1234.
1. Call list_numbers, then get_api_credentials for that number.
   Put send_endpoint and access_token in .env, never in code.
2. Scaffold an HTTPS server with POST /wa/<long random path>.
   Verify X-EC-Signature (HMAC-SHA256 of "<t>.<raw body>").
   Skip message ids already handled.
   On smb_message_echoes, stay quiet on that chat for 4 hours.
3. Reply with my model only within 24 hours of the
   customer's last message.
4. Write tests for the signature check and the 24-hour rule.
Do not call set_inbound_mode or set_webhook_destination
until I say so.

How do you connect the receiver and test it?

Start the server where Meta and easyCoexistence can reach it over HTTPS, then let the agent do the routing. For the Forward URL route, it calls set_inbound_mode with your URL on a number in Automations on mode; the forward secret comes back once, and the agent writes it to your .env. For the direct route, the endpoint has to answer Meta's GET handshake first, then the agent calls set_webhook_destination with the URL, a long random secret in its path, and your verify token.

To test, message the business number from your own phone and watch the logs: the receiver should see the event, the model should answer, and the reply should appear in the chat. Because you just wrote, the 24-hour window is open, so the coding agent can also try send_message to your own number.

Does the finished agent still need the MCP server?

No. The MCP server is the builder's tool, signed in as you. The agent you deploy sends through Meta's Graph API with the send_endpoint and access_token that get_api_credentials returned, the business's own token scoped to its WhatsApp assets, and it receives through the route you set up. If access_token came back null, reconnecting the number from the dashboard issues one without replacing a token that already works.

Keep the MCP connection for the work around the agent: creating templates with create_template, checking get_number_health when something looks wrong, and reading the run log of any automation that hands messages to your code.

How to set it up

  1. Connect your numberAt easycoexistence.com, run Meta's Embedded Signup and scan the code with the WhatsApp Business app; the app keeps its chats.
  2. Add the server to your coding agentRun the claude mcp add or codex mcp add command, then sign in with /mcp in Claude Code or codex mcp login in Codex.
  3. Ask for credentials and a planHave the agent call list_numbers and get_api_credentials, store the values in .env and propose the receiver before writing it.
  4. Expose the receiver over HTTPSDeploy it, or run a tunnel while developing, and confirm the URL answers from outside your machine.
  5. Route the messagesLet the agent call set_inbound_mode with a Forward URL, or set_webhook_destination for the direct route, once you approve.
  6. Test from your phoneSend the business number a message and check that your agent's reply arrives in the same chat.

Common mistakes

  • Saving a throwaway tunnel as the direct destination in the first 24 hours. Meta's one-time import of contacts and up to 6 months of chats goes to that URL and is lost when the tunnel closes.
  • Setting a direct destination on a number that runs automations. The number switches to direct and its automations stop; use a Forward URL in Automations on mode to keep both.
  • Committing the .env the agent wrote. Add it to .gitignore first, because anyone holding the access token can message customers as the business.
  • Testing send_message on a contact who has not written in 24 hours. Meta refuses free-form text outside the window, so message the number from your own phone first.
Doing this with EasyCoexistence

Your agent then runs on your own server, and every number is monitored 24/7 with alerts. US$ 9 down to US$ 0.75 per number per month, falling as you add numbers, with the first 3 days free.

easyCoexistence is a multichannel API and MCP server that connects AI agents such as Claude and ChatGPT to WhatsApp, Instagram, TikTok, Facebook and more. On WhatsApp it uses Coexistence: the business keeps using its number in the WhatsApp Business app while the AI works through Meta's official API.

Frequently asked questions

Does this work in Cursor or other coding tools?

Yes. Any MCP client that connects to remote servers over Streamable HTTP with OAuth can use the same URL, including Cursor, VS Code, Gemini CLI and Antigravity. Only the configuration format changes from one client to another.

Which language should the agent write?

Any language that can serve HTTPS and compute an HMAC-SHA256. Node.js and Python are the common choices, and tested samples for both, with signature checks, duplicate handling and the phone pause, are on the Node.js and Python agent page.

Do I need my own Meta app or App Review?

No. The number joins the Cloud API through easyCoexistence's Meta app and stays in the business's own portfolio. The token your code sends with is the business's own, so no Meta app of yours is involved.

Can the coding agent create the templates the agent needs?

Yes, with create_template, then get_template_status until Meta answers, usually within minutes and at most about 24 hours. Your agent needs an approved template to start a conversation or to write after the 24-hour window closes.

Keep reading

Ready to get started?

Set up WhatsApp Coexistence in minutes, not months. The app keeps working on the phone.

Start Free Trial

Verified on