Introduction¶
Registration, login, contact forms, comment submissions—any user-triggered write operation is susceptible to script-based credential stuffing or spam flooding. Common practices involve deploying CAPTCHAs on the frontend and validating tokens on the backend. Turnstile is Cloudflare’s bot verification solution; its documentation emphasizes that it can be embedded into sites without relying on the Cloudflare CDN and adapts challenge intensity based on visitor risk.
In practice, the difficulty often lies not in “understanding the documentation,” but in: scanning existing repositories to identify necessary changes, creating a widget in the console and pairing it with a domain, writing the embed snippet according to the framework, integrating siteverify into the existing backend, and confirming the implementation actually works. Cloudflare provides the turnstile-spin Skill in the cloudflare/skills repository. It condenses the above steps into a script-driven, wizard-like orchestration where the Agent reads code, confirms insertion points, modifies the frontend and backend, and performs a real verification before reporting success.
What is this¶
turnstile-spin is an Agent Skill maintained officially by Cloudflare (Directory: skills/turnstile-spin). It is officially described as: creating, fixing, or migrating Cloudflare Turnstile bot verification in existing frontends and backends, including server-side Siteverify.
The Skill breaks “set up Turnstile” down into an executable chain: checking authentication, scanning the codebase, creating a widget (or using an existing sitekey), embedding the frontend snippet at selected locations, writing standard siteverify logic in the user’s existing backend, and completing a successful verification before finishing. Deterministic logic (API calls, retries, and error handling) is placed in scripts under scripts/; the Agent is responsible for orchestration, reading the repository, confirming with the user, and completing the frontend and backend edits. Behavior is defined by SKILL.md within the Skill as the source of truth, and product requirements align with the Turnstile documentation.
Core Features¶
Triggers and Scope¶
When a conversation includes mentions of Turnstile, CAPTCHA, bot protection, siteverify, cf-turnstile-response, or expressions like “protect forms/interfaces/buttons, block bot registration,” and relates to Cloudflare or bot scenarios, the Agent will load this Skill. Pure Workers, Pages, R2, etc., tasks that do not mention Turnstile should not trigger this Skill on their own.
If the user has stated that the widget is already created and provided the sitekey, the Skill requires following the “existing widget” branch and will not proceed with the widget creation wizard.
Multi-Framework References¶
When embedding the frontend, the Skill requires referencing the corresponding guide based on the existing tech stack:
| Frontend | Reference Path (in repo) |
|---|---|
| Vanilla HTML | references/vanilla-html.md |
| Next.js App Router | references/nextjs-app.md |
| Next.js Pages Router | references/nextjs-pages.md |
| Astro | references/astro.md |
| SvelteKit | references/sveltekit.md |
| Hugo | references/hugo.md |
Wizard-like Conversation Flow (Overview)¶
Summarized below according to the numbered wizard in the official SKILL.md; steps marked [wait for user] require user confirmation or reply before continuing.
- Brief Confirmation: Explain in one sentence that authentication, scanning, widget creation, embedding, siteverify, and verification will be completed end-to-end, and wait for user consent (do not expand the full plan at this step).
- CLI Check: The helper script accesses
api.cloudflare.comviacurl. Enumerating accounts requires an explicit$CLOUDFLARE_ACCOUNT_ID, or a canonicalWRANGLER_BINoutside the project and exactWRANGLER_VERSIONapproved by the user. Usingnpx,pnpm exec, in-project binaries, or unapproved executables to run commands with credentials is prohibited; the flow will also not automatically install Wrangler. - Auth and Scope Probe (First Irreversible Step): Run
scripts/auth-probe.shand handle branches based on the JSONstatus(see the next section). - Account Selection: In multi-account scenarios, the user selects
CLOUDFLARE_ACCOUNT_IDand then re-probes. - Domains:
localhostand127.0.0.1are included by default; production domains are scanned frompackage.jsonhomepage,wrangler.toml,README.md,AGENTS.md, git remotes, etc., registered after confirmation with the user. The documentation reminds: when registering both local and production domains for the same widget, backends in each environment should verify the exact frontend hostname returned by siteverify; the production backend’s expected hostname whitelist should not containlocalhost/127.0.0.1. - Codebase Scan: Identify the frontend framework, backend processing locations (Express routes, Next API, Rails, Workers, Pages Functions, etc.), and whether reCAPTCHA / hCaptcha already exists (if so, enter migration mode).
- Insertion Plan: List candidate insertion points (including
[recommended]/[skip by default]). After user confirmation, specify a stableactionfor each surface (e.g.,signup,login, 1–32 characters, alphanumeric/underscore/hyphen only), and confirm the mapping of action to handler. - Create Widget: Prioritize using approved Wrangler that supports the
turnstile widgetsubcommand; otherwise usescripts/widget-create.sh. Creation example (managed mode):
WRANGLER_WRITE_LOGS=false WRANGLER_LOG=log WRANGLER_LOG_SANITIZE=true \
"$WRANGLER_BIN" turnstile widget create "<name>" \
--domain <d1> --domain <d2> ... --mode managed --json
Capture the full stdout JSON in a set +x subshell, parse SITEKEY and non-empty WIDGET_SECRET with jq, and then unset response variables.
Subsequent steps (details not expanded in the truncated source) in the complete Skill also include: writing the secret to the backend environment, modifying the frontend according to the reference, writing siteverify, and performing a real-machine verification before success.
How to Handle Auth Probe Results¶
Common branches after running scripts/auth-probe.sh:
ok: Continue with scanning and integration.missing_token/missing_scope: Guide the user to create a Custom token in API Tokens withAccount.Turnstile:Editpermission, including the target account in Account Resources. Do not ask the user to paste the token into the chat; offer options like “export in terminal and restart Agent” or “write to a user-readable file.” Do not default to asking the user towrangler loginunless the OAuth scope of the used Wrangler version already includesAccount.Turnstile:Edit.network_failure/upstream_failure: Handle network issues or brief retries according to diagnostics; do not misinterpret as token permission issues.multiple_accounts/account_mismatch: Display the account list or correctCLOUDFLARE_ACCOUNT_ID.
Migration from Other CAPTCHAs¶
When reCAPTCHA or hCaptcha is scanned, Step 7 changes to display a migration plan (see the “Migrating from another CAPTCHA” section in the Skill for details) instead of just creating new embeds.
Installation and Activation¶
turnstile-spin is installed with the cloudflare/skills plugin or skills package; entry points for various Agents are as follows (excerpt from official README).
Codex
codex plugin marketplace add cloudflare/skills
codex plugin add cloudflare@cloudflare
Open a new Codex session after installation.
Claude Code
/plugin marketplace add cloudflare/skills
/plugin install cloudflare@cloudflare
VS Code / GitHub Copilot
- Enable
chat.plugins.enabledin settings. - Run Chat: Install Plugin From Source in the Command Palette.
- Enter
https://github.com/cloudflare/skills.
Cursor
Install from the Cursor Marketplace, or add cloudflare/skills via Settings > Rules > Add Rule > Remote Rule (Github).
npx skills
npx skills add https://github.com/cloudflare/skills
Copy Skill Directory Only
You can also clone the repository and copy the turnstile-spin (and other) skill folders to the Agent’s convention directory, e.g., ~/.cursor/skills/ for Cursor (see official README for full table).
Skills are loaded automatically based on conversation context; when a request matches the Skill’s trigger conditions, the Agent loads turnstile-spin and executes according to SKILL.md.
Typical Usage¶
Typical usage is not about manually writing a long list of configurations, but initiating integration with natural language in an IDE or CLI that supports Agent Skills, letting the Skill drive scripts and code changes.
Example 1: Anti-spam for new site forms
In Cursor with the Cloudflare plugin installed, you can say: “Add Turnstile to the registration form in this Next.js project and do siteverify in the API route.” The Skill will first confirm end-to-end steps, then run auth-probe.sh, scan the App Router structure, reference references/nextjs-app.md, create or use a widget after confirming registered domains and insertion points with the user, and finally modify the frontend and API and perform verification.
Example 2: Existing sitekey
If the widget is already created in the console, provide the sitekey directly in the conversation (and follow Skill guidance for subsequent secret configuration). The Agent should skip the widget creation wizard, enter the “existing widget” flow, and only perform embedding and siteverify.
Example 3: Migration from reCAPTCHA
State “The login page currently uses reCAPTCHA, I want to switch to Turnstile.” After scanning, it will enter migration mode, replacing frontend and verification logic after confirming insertion points and handler mappings.
The above examples describe behavior paths declared by the Skill documentation; specific command outputs and file changes are subject to your repository scan results and user confirmation.
Applicable Scenarios and Notes¶
Who it is for
- Teams that need to integrate or fix Turnstile in existing frontends and backends (not starting from scratch).
- Projects using Next.js (App/Pages), Astro, SvelteKit, Hugo, or pure HTML.
- Scenarios where bot protection is desired on user-triggered requests such as registration, login, contact forms, comments, download buttons, etc.
Limitations and Notes
- A Cloudflare API Token is required, including
Account.Turnstile:Edit; for multi-account scenarios,CLOUDFLARE_ACCOUNT_IDmust be explicit. - Wrangler is only used for widget creation when using an approved binary and the version supports the
turnstile widgetsubcommand; the flow will not automatically install Wrangler, nor usenpxetc. to execute commands with credentials. - Tokens should not appear in chat or shell history; the Skill documentation provides safer input methods.
- When local and production domains share the same widget, strictly verify siteverify results by hostname in the backend to prevent local configurations from being mistakenly used in production whitelists.
- This Skill focuses on Turnstile integration and does not replace configuration for Cloudflare products other than Turnstile.
Turnstile itself states in its official overview: challenges are completed client-side to distinguish humans from automated traffic; Managed mode is the recommended widget type and supports Non-interactive, Invisible types (the creation wizard example uses managed).
Conclusion¶
turnstile-spin converges Turnstile from “documentation + console + multiple code changes” into a confirmable end-to-end process: scripts handle API and probing, the Agent reads the repository, selects insertion points, modifies frontend and backend, and performs real-machine verification before success. If you are developing web applications requiring bot protection on Cursor, Codex, Claude Code, or VS Code Copilot, install cloudflare/skills and trigger this Skill via conversation.
Skill directory and full wizard: https://github.com/cloudflare/skills/tree/main/skills/turnstile-spin