ai-persistence/build-cloudflare-adapter

A setup helper for saving TanStack AI chat data in a Cloudflare Worker using D1, Cloudflare’s database service. It can also add a Durable Object lock store for coordinating access.

In plain words
What is it for?
Use it to add chat storage, database migrations, request binding access, and lease-based locks to a Cloudflare Worker.
Why use it?
It removes the application-specific wiring between chat persistence, request database bindings, configuration, and migrations. A migration is a tracked database change applied over time.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/tanstack/ai/build-cloudflare-adapter
Any agent
npx skills add TanStack/ai --skill build-cloudflare-adapter
Clone the repo
git clone --depth 1 https://github.com/TanStack/ai

Made for: Claude Code, Codex.

Per session 68 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,372 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00068 $0.03372
Opus 5 $0.00034 $0.01686
Sonnet 5 $0.00014 $0.00674
Haiku 4.5 $0.00007 $0.00337

Measured 2d ago against content hash 6d9d7d142478, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

ai-persistence/build-cloudflare-adapter scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

| How `env` reaches code | the Worker `fetch(request, env)`, or an async-local helper (`getDb()`, `getCloudflareContext()`) | Whether the factory takes `env` or reads a helper |
packages/ai-persistence/skills/ai-persistence/build-cloudflare-adapter/SKILL.md · 314 lines

How it starts

The opening of the file, as written. The whole thing — 314 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Cloudflare Chat Persistence

The deliverable is one file in the Workersrc/lib/chat-persistence.ts — exporting a factory that builds a ChatPersistence from the request's D1 binding, plus (when the app needs coordination) a Durable Object lock store. Tables go into the app's existing migrations/ directory and are applied with wrangler d1 migrations apply.

Do not create a package or a migration runner. Wrangler already tracks applied migrations; a second bookkeeping table only creates drift.

Read the Store Reference (docs/persistence/store-reference.md) for the store contracts, and ai-persistence/stores for the shape rules. This skill covers only the Cloudflare-specific parts.

1. Read the app before writing anything

Find Where to look What it decides
D1 binding name wrangler.jsonc d1_databases[].binding env.DB vs env.AI_STATE in the factory
How env reaches code the Worker fetch(request, env), or an async-local helper (getDb(), getCloudflareContext()) Whether the factory takes env or reads a helper
Drizzle or raw D1 drizzle-orm in package.json, a src/db/schema.ts Which recipe below to follow
Migrations dir wrangler.jsonc migrations_dir, default migrations/ Where the new .sql file goes
Existing table names the current migrations / schema Prefix (chat_*) so nothing collides

Read the full file on GitHub · 314 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 314 lines · 68 tokens per session scan A 6d9d7d142478

Subscribe to this mod's changes

ai-persistence/build-cloudflare-adapter is a skill published in the GitHub repository TanStack/ai (3,056 stars, last pushed today), licensed MIT. It adds 68 tokens to every session and 3,372 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

eliza-cloud

Use when the task involves Eliza Cloud or elizaOS Cloud as a managed backend, app platform, deployment target, billing layer, or monetization surface. The catch-all skill for any user request about THEIR existing apps / containers / earnings / credits / api-keys / analytics / billing / payment requests / payouts …

elizaOS/eliza · 191 tokens

eliza-cloud-manage-domain

Use after a domain has been purchased through Eliza Cloud (via the eliza-cloud-buy-domain skill) when the user wants to look at, edit, or remove a domain or its DNS records. Covers org-wide domain listing, per-app DNS record CRUD on cloudflare-managed zones, status re-sync, external-attachment verification, and…

elizaOS/eliza · 125 tokens

healthcheck

Host security hardening and risk-tolerance configuration for OpenClaw deployments. Use when a user asks for security audits, firewall/SSH/update hardening, risk posture, exposure review, OpenClaw cron scheduling for periodic checks, or version status checks on a machine running OpenClaw (laptop, workstation, Pi, VPS).

the-open-agent/openagent · 70 tokens

agenticx-deployer

Guide for deploying AgenticX agents to production including Docker containerization, Kubernetes orchestration, Volcengine AgentKit cloud deployment, and API server setup. Use when the user wants to deploy agents, containerize applications, set up Kubernetes, configure cloud deployment, or run the AgenticX API server…

DemonDamon/AgenticX · 69 tokens

operate-tennis-alerts

Operate and maintain this repository's Shenzhen tennis alert platform across Apache Airflow 3, the Cloudflare Worker and D1 web subscription service, Tencent SES email, and the Android-host WeChat sender. Use for problem diagnosis, incident response, production health checks, DAG or notification failures…

claude89757/wechat-on-airflow · 105 tokens

aws-cost-optimizer

Analyze and optimize AWS costs with recommendations for Reserved Instances, right-sizing, and resource cleanup. Use when reducing AWS spending, analyzing costs, or optimizing cloud infrastructure expenses.

armanzeroeight/fastagent-plugins · 38 tokens