Skip to content

Deploy to Cloudflare ​

The server runs as one Cloudflare Worker that also serves the dashboard as static assets. Postgres is hosted elsewhere and reached through Hyperdrive, and embeddings come from Workers AI. It is the same code as the Docker build. Run these from a clone of the repository with pnpm install done.

1. A Postgres with pgvector ​

Any Postgres with the vector extension works. Neon's free tier is the easiest: create a project and copy the connection string (postgres://...?sslmode=require). Supabase also works. Migrations create the extension themselves.

For Hyperdrive, use the direct connection string, not a pooled one (for Neon, the host without -pooler). Hyperdrive does the pooling.

2. Migrate ​

sh
DATABASE_URL='postgres://...' pnpm --filter server migrate

3. Create the Hyperdrive ​

sh
cd apps/server
pnpm exec wrangler login
pnpm exec wrangler hyperdrive create carrybrain \
  --connection-string='postgres://...' --caching-disabled

Turn query caching off

Hyperdrive caches read results for a few seconds by default, so right after a write the app can read stale data: sign-in state after setup, your role after an admin changes it, lists after an edit. Create it with --caching-disabled, or for an existing one run pnpm exec wrangler hyperdrive update <id> --caching-disabled. Connection pooling is unaffected.

Put the printed id in apps/server/wrangler.jsonc (hyperdrive[0].id), or pass it when deploying with CARRYBRAIN_HYPERDRIVE_ID=<id>. The deploy command refuses to run while the placeholder id (all zeros) is still set. The connection string lives only in Hyperdrive, never in the file.

The Worker is configured with smart placement, which runs it near your database instead of near the caller. Each request makes several sequential queries, and every one would otherwise cross the world.

4. Build and deploy ​

sh
pnpm --filter dashboard build
CARRYBRAIN_HYPERDRIVE_ID=<id> pnpm --filter server cf:deploy

Open the deployed URL and finish setup. The setup code is logged on the first request (see it with pnpm exec wrangler tail), or fix it with pnpm exec wrangler secret put CARRYBRAIN_SETUP_TOKEN. Set CARRYBRAIN_PUBLIC_URL under vars in wrangler.jsonc so links use your domain.

5. Email and Google ​

Workers cannot open SMTP connections, so email uses Resend over HTTP.

  1. Verify your sending domain in Resend and create an API key.
  2. pnpm exec wrangler secret put RESEND_API_KEY
  3. Under vars in apps/server/wrangler.jsonc set CARRYBRAIN_MAIL_PROVIDER to "resend" and CARRYBRAIN_MAIL_FROM to something like "Carrybrain <hub@acme.dev>".
  4. Optional: CARRYBRAIN_ADMIN_EMAIL (a var or a secret) to be emailed the setup link on first run.

For Google sign-in, create the OAuth client as in Self-hosting, then pnpm exec wrangler secret put GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET. Optionally set CARRYBRAIN_GOOGLE_ALLOWED_DOMAINS as a var. Redeploy afterwards.

6. Custom domain ​

In the Cloudflare dashboard open Workers & Pages, the carrybrain Worker, Settings, Domains & Routes, and add a domain such as memory.acme.dev. The domain's DNS must be on Cloudflare.

7. Deploy from GitHub Actions ​

The repository's .github/workflows/deploy.yml migrates, builds and deploys on every push to master. Add these repository secrets: DATABASE_URL (for migrations only), CLOUDFLARE_API_TOKEN (the "Edit Cloudflare Workers" permission) and CLOUDFLARE_ACCOUNT_ID, plus the repository variable CARRYBRAIN_HYPERDRIVE_ID (not needed if you committed the id). CARRYBRAIN_SETUP_TOKEN, if you use it, is a Worker secret, not a GitHub one.

Then connect ​

sh
carrybrain install claude --url https://memory.acme.dev

Caveats ​

  • Workers AI has a daily free allocation; beyond it usage is billed. Check current pricing.
  • Hyperdrive has daily query limits on the Workers Free plan. Neon's free tier suspends idle databases, so the first request after a pause is slower.
  • Embeddings are compatible with self-hosted ones (the same bge-small-en-v1.5 model, 384 dimensions) but not bit-identical, so you can move a database between runtimes without re-embedding.

Carrybrain is open source under the MIT license.