Claude-Session: https://claude.ai/code/session_01LJm3SRL9k3gBPaVtfPhwcT Co-authored-by: Claude <noreply@anthropic.com>
Coucou Cloud
A Cloudflare Worker that runs the Mochis while the Mac is off. A pull request arrives on GitHub, the PR Reviewer Mochi reviews it in a sandbox on Claude Managed Agents, and the review waits in Coucou until you click to post it.
V0: your own Anthropic API key. Each session runs on the subscriber's own key, so Anthropic bills them directly. Coucou never pays for or resells Claude usage. See "Conditions d'Anthropic" in the Cloud spec.
How a run goes
- GitHub sends
pull_requesttoPOST /github/webhook(signed with the app's secret). - Each enabled Cloud Mochi with
trigger: pr-openedon that repo starts a session, once per PR head commit:- an agent and an environment are made once in the user's Anthropic organization;
- the session gets the repo cloned on the PR's commit, the prompt with the PR's diff, and a spend ceiling.
- Every minute, the cron collects the finished sessions: cost, model calls,
the final report. A review becomes a proposal,
waiting. A session still running after 30 minutes is stopped. POST /v1/runs/:id/apply(your click in Coucou) posts the review as a comment, as the Coucou Cloud app. Nothing is posted without it.
What it keeps (D1)
- Your GitHub id and login.
- The hash of the token your Mac uses.
- Your Anthropic key, sealed with AES-GCM using a Worker secret.
- Your Cloud Mochis.
- Each run's result.
It never keeps your code: the repository is cloned inside Anthropic's sandbox,
not here. It keeps no logs (observability off).
Deploy (once)
In order: the Worker first (the GitHub App needs its address), then the
webhook secret, the app, its key, and the Mac. From this folder, on a Mac
(pbcopy and brain are Mac commands; on Linux, wl-copy or xclip do the
clipboard part).
- The Worker, on Cloudflare:
npm install npx wrangler login npx wrangler d1 create coucou-cloud # its database_id goes in wrangler.toml npm run db:init npx wrangler deploy # prints https://coucou-cloud.<you>.workers.dev openssl rand -base64 32 | npx wrangler secret put KEY_ENCRYPTION_KEY - The webhook secret. This command makes it, sends it to Cloudflare and
leaves it in the clipboard for step 3, without printing it:
Paste it into the app right away (step 3). Clipboard managers and Universal Clipboard can keep it, so clear it afterwards. Running the command again is fine as long as the secret that ends up in the app comes from the last run.
S=$(openssl rand -hex 32); printf %s "$S" | pbcopy; printf %s "$S" | npx wrangler secret put GITHUB_WEBHOOK_SECRET; unset S - The GitHub App: github.com → Settings → Developer settings → GitHub Apps → New.
- Name: "Coucou Cloud". Homepage: the repo URL.
- Webhook URL:
https://coucou-cloud.<you>.workers.dev/github/webhook. Webhook secret: paste it (Cmd+V). Afterwards,pbcopy < /dev/nullclears the clipboard. - Permissions:
- Repository → Pull requests: Read and write;
- Contents: Read-only;
- Metadata: Read-only.
- Events: Pull request.
- Enable Device Flow, so the Mac can sign in.
- "Where can this GitHub App be installed?": Only on this account (for the beta).
- Create it, and put its App ID in
GITHUB_APP_IDinwrangler.toml. Note its Client ID for step 6.
- The app's private key. On the app's page: Credentials → Key pairs →
New key. A
<app>.<date>.private-key.pemfile downloads. It goes to Cloudflare in PKCS#8, which WebCrypto reads, with no intermediate file. The command only takes a key downloaded in the last 30 minutes, says which one, and deletes it only if both conversion and upload worked. It runs in a subshell, sopipefailandfdon't stay in your terminal:Then deploy again, so the App ID is taken:( set -o pipefail; f=$(find ~/Downloads -maxdepth 1 -name '*private-key.pem' -mmin -30 | head -1); [ -n "$f" ] || { echo "No private key downloaded in ~/Downloads in the last 30 minutes"; exit 1; }; echo "Key: $f"; openssl pkcs8 -topk8 -nocrypt -in "$f" | npx wrangler secret put GITHUB_APP_PRIVATE_KEY && rm "$f" )npx wrangler deploy. - Install the app on the repositories the Mochis should watch. Check it: the app's Advanced tab lists the deliveries, with a green tick when the Worker took them. A 401 means the two webhook secrets differ: run step 2 again, paste the new secret into the app (General → Webhook → Change secret), then Redeliver the failed delivery to see the tick.
- The Mac.
brain cloud keysends the Anthropic API key stored bybrain mochi key, so that one comes first:The next pull request is reviewed in the Cloud.brain mochi key brain cloud login --url https://coucou-cloud.<you>.workers.dev --client-id <Client ID> brain cloud key brain cloud add pr-reviewerbrain cloud runslists it a minute or two later.
Billing (Stripe)
Without STRIPE_SECRET_KEY, billing is off and every signed-in user may run in the Cloud (development).
With it, a user's Mochis run in the Cloud only with an active subscription, or when their GitHub login
is in COMP_LOGINS (wrangler.toml).
The offers live in src/billing.ts (PLANS); the app shows what GET /v1/plans says. Today only
Cloud · your key ($9/month, the AI on the user's own Anthropic key) can be bought; Solo, Pro and Max
are listed as coming. Stripe direct, under the VAT franchise: no VAT, and every invoice carries
INVOICE_FOOTER (« TVA non applicable, article 293 B du CGI »). STRIPE_TAX = "1" turns Stripe Tax on.
Once per mode, test first, then live, from cloud/. Best with a restricted key (rk_…, Developers › API keys ›
Create restricted key) allowed only: Customers, Checkout Sessions, Customer portal, Subscriptions (read),
Products, Prices, Webhook Endpoints (write for the rest).
- The secret key, typed, never in a file:
npx wrangler secret put STRIPE_SECRET_KEY - The same key for the setup script, without echo:
read -rs STRIPE_SECRET_KEY && export STRIPE_SECRET_KEY - The price, the customer portal and the webhook; its signing secret goes straight to the Worker:
node scripts/stripe-setup.mjs https://coucou-cloud.<you>.workers.dev | npx wrangler secret put STRIPE_WEBHOOK_SECRET unset STRIPE_SECRET_KEY, thennpx wrangler deploy
In the Stripe Dashboard, once: the business name, address and SIRET under Settings › Business (they go on every invoice), and Settings › Customer emails › « Successful payments » so receipts are sent.
API (for the Mac)
| Route | Body | Answer |
|---|---|---|
POST /v1/login |
{ github_token }, a user token from the app's device flow |
{ token, login, installations } |
PUT /v1/anthropic-key |
{ key, language } |
checked against Anthropic, then sealed |
PUT /v1/mochis |
{ mochis: [{ id, name, repo: "owner/name", trigger: "pr-opened", instructions, model, budget_cents, enabled }] } |
replaces the user's Cloud Mochis |
GET /v1/runs?since=ISO |
{ runs: [...] }, newest first, with proposal and proposal_state |
|
POST /v1/runs/:id/apply |
{ url } of the posted review |
|
POST /v1/runs/:id/discard |
Every /v1/ route except login takes Authorization: Bearer <token>.
Code
src/index.ts: routes and the cron.src/engine.ts: start, collect, apply.src/github.ts: GitHub calls.src/crypto.ts: webhook signature, app JWT, sealing.
The prompt and the Managed Agents requests come from the brain
(brain/src/prompt-core.ts, brain/src/cloud-core.ts). A review is written
the same way on the Mac (brain cloud try) and in the Cloud.
Tests: npm test. They use SQLite in memory for D1 and a fake fetch for
GitHub and Anthropic.