# Editlet > Editlet is a small Git CMS for Next.js and Astro. Content is Markdown in your repo, described by cms/schema.json. Your coding agent edits it with the bundled skill, your team edits it with ?editlet on any page, and every change is a commit on an editlet/* branch that goes live when a person merges the pull request. # What is Editlet > Editlet is a Git-based CMS for Next.js and Astro: what it does and what it needs. Editlet is a Git-based CMS for **Next.js** and **Astro**. Your content is Markdown files in your own repository. There is no database and no hosted service. ## How it works - **Content is files.** Each entry is a `.md` file with YAML frontmatter under `cms/content/`. One file, `cms/schema.json`, describes the fields. See [Content model](https://editlet.gunkin.dev/docs/content-model.md). - **Your agent edits content.** Claude Code or another agent uses the bundled `editlet` skill. See [The agent skills](https://editlet.gunkin.dev/docs/agent-skills.md). - **People edit on the site.** Add `?editlet` to the URL of any page, and the editor opens over that page. - **Every edit is a commit.** On the live site the editor commits to `editlet/` branches on GitHub and opens a pull request. A developer merges it on GitHub, and your host redeploys. See [Dev mode and production](https://editlet.gunkin.dev/docs/dev-and-production.md). ## Requirements | Requirement | Version | |---|---| | Node.js | 22.12 or newer | | Next.js | `next >=16` with `react >=19` | | Astro | `astro ^6 \|\| ^7` | | Browsers (editor) | Chrome 125+, Edge 125+, Firefox 128+, Safari 17.5+ | | Git host | GitHub, for editing on the live site | ## Status Editlet is alpha, and names and options can still change. The npm package is [`editlet`](https://www.npmjs.com/package/editlet). License: MIT. ## Next steps - [Quick start: Next.js](https://editlet.gunkin.dev/docs/quick-start-next.md) or [Quick start: Astro](https://editlet.gunkin.dev/docs/quick-start-astro.md) - [Docs for AI agents](https://editlet.gunkin.dev/docs/docs-for-agents.md): these docs as Markdown # Quick start: Next.js > Add Editlet to a Next.js App Router site and edit your first entry with ?editlet. Follow these steps to add Editlet to a Next.js App Router site (`next >=16`, `react >=19`) and edit an entry in `next dev`. ## Install with your agent Give Claude Code, Codex or another coding agent this prompt in your project: ```text Install Editlet in this project: add the package `editlet` with the project's package manager, then read node_modules/editlet/skills/editlet-setup/SKILL.md and follow it. ``` ## Install by hand 1. Install the package and link the [agent skills](https://editlet.gunkin.dev/docs/agent-skills.md): ```bash npm install editlet node node_modules/editlet/skills/editlet/scripts/link.mjs --hooks ``` 2. Wrap your Next config. In `next dev` and `next build`, `withEditlet` writes the types to `.editlet/content.d.ts` and the editor to `public/editlet/`. In `next dev` it also serves the dev file API at `/__editlet`. ```ts // next.config.ts import { withEditlet } from 'editlet/next/config'; export default withEditlet({ reactStrictMode: true }); ``` 3. Add the generated folders to `.gitignore`: ```text /.editlet/ /public/editlet/ ``` 4. Render `` last in `` of `app/layout.tsx` (or `src/app/layout.tsx`). It renders nothing until the URL has `?editlet`. ```tsx import { EditletLoader } from 'editlet/next'; // inside : {children} ``` 5. Create `cms/schema.json`. Set `git.baseBranch` to the branch your site deploys from. See [Content model](https://editlet.gunkin.dev/docs/content-model.md). ```json { "contentDir": "cms/content", "git": { "baseBranch": "main" }, "collections": { "post": { "label": "Post", "titleField": "title", "slugFrom": "title", "fields": { "title": { "type": "string", "label": "Title", "required": true }, "body": { "type": "markdown", "label": "Body" } } } } } ``` 6. Create one entry, `cms/content/post/hello-world.md`: ```md --- title: Hello world --- The first post. ``` 7. Run `npm run dev` and open `http://localhost:3000/?editlet`. In dev, a save changes the local file. ## Show content on a page Create the reader once, then call it in Server Components, `generateStaticParams` and `generateMetadata`: ```ts // src/lib/cms.ts import { createReader } from 'editlet/next'; import type { EntryMap } from '../../.editlet/content'; export const { getEntries, getEntry, getRef, getReferrers } = createReader(); ``` ```ts const posts = await getEntries('post'); // sorted by slug const post = await getEntry('post', 'hello-world'); // undefined when missing const home = await getEntry('home'); // a singleton: the slug is 'index' const author = await getRef(post.data.author); // 'author/jane' → that entry const full = await getEntry('post', 'hello-world', { depth: 1 }); // references → entries, 0–10 levels const byJane = await getReferrers('author/jane', { from: 'post' }); // entries that reference author/jane ``` An entry is `{ collection, slug, data, body }`, and `body` holds the `markdown` field. Production builds leave out `draft: true` entries. An invalid entry throws an error with every issue, so `next build` fails. Image fields hold a public URL in `src`. Pass images in a Markdown body through `assetUrl`: ```tsx import Markdown, { defaultUrlTransform } from 'react-markdown'; import { assetUrl } from 'editlet/next'; defaultUrlTransform(key === 'src' ? assetUrl(post, url) : url)}> {post.body} ; ``` Mark the element that shows an entry with `data-editlet-entry="post/hello-world"`. The editor can then point at it, and you can select words in it and press **Edit**. Tell the schema which page shows an entry: `"url": "/blog/{slug}"` on the collection, matching your route `src/app/blog/[slug]/page.tsx`. The editor then shows the page's address in *New entry* and *Details*, and **⋯ → Open on the page** goes there. Add `"pluralLabel": "Posts"` for the list heading. See [Content model](https://editlet.gunkin.dev/docs/content-model.md#page-urls). ## Limits - `basePath` is not supported. The editor is always at `/editlet/` and the dev API at `/__editlet`. - With `cacheComponents: true`, wrap reads in `'use cache'` with `cacheLife('max')`. In dev, a content edit then needs a restart. To edit the live site through GitHub, read [Dev mode and production](https://editlet.gunkin.dev/docs/dev-and-production.md). # Quick start: Astro > Add Editlet to an Astro site, read entries as content collections and edit your first entry with ?editlet. Follow these steps to add Editlet to an Astro site (`astro ^6 || ^7`) and edit an entry in `astro dev`. Your entries become Astro content collections. ## Install with your agent Give your coding agent the prompt from [Quick start: Next.js](https://editlet.gunkin.dev/docs/quick-start-next.md). The same skill sets up Astro. ## Install by hand 1. Install the package and link the [agent skills](https://editlet.gunkin.dev/docs/agent-skills.md): ```bash npm install editlet node node_modules/editlet/skills/editlet/scripts/link.mjs --hooks ``` 2. Add the integration. It adds the `?editlet` loader to every page. `astro dev` serves the editor at `/editlet/` and the dev file API at `/__editlet`, and `astro build` copies the editor into the output. ```js // astro.config.mjs import editlet from 'editlet/astro'; import { defineConfig } from 'astro/config'; export default defineConfig({ integrations: [editlet()] }); ``` 3. Create `cms/schema.json` and one entry, as in steps 5 and 6 of [Quick start: Next.js](https://editlet.gunkin.dev/docs/quick-start-next.md). 4. Create `src/content.config.ts`. It makes one Astro collection per schema collection. ```ts import { editletCollections } from 'editlet/astro/content'; export const collections = editletCollections(); ``` 5. Run `npm run dev` and open `http://localhost:4321/?editlet`. In dev, a save changes the local file. To keep your own collections too, add each Editlet one with `editletLoader`, and give it no `schema`: ```ts import { defineCollection } from 'astro:content'; import { editletLoader } from 'editlet/astro/content'; export const collections = { post: defineCollection({ loader: editletLoader('post') }), // your other collections }; ``` ## Show content on a page ```astro --- import { getCollection, getEntries, getEntry, render } from 'astro:content'; import { Image } from 'astro:assets'; const home = await getEntry('home', 'index'); // a singleton: the id is 'index' const posts = await getCollection('post'); // the id is the slug const author = await getEntry(posts[0].data.author); // a reference → that entry const related = await getEntries(posts[0].data.related ?? []); // a list of references; one call per level const { Content } = await render(posts[0]); // the Markdown body --- {posts[0].data.cover && {posts[0].data.cover.alt}} ``` Mark the element that shows an entry with `data-editlet-entry="post/hello-world"`. The editor can then point at it, and you can select words in it and press **Edit**. Tell the schema which page shows an entry: `"url": "/posts/{slug}/"` on the collection, matching your route `src/pages/posts/[slug].astro` and the trailing `/` of your links. The editor then shows the page's address in *New entry* and *Details*, and **⋯ → Open on the page** goes there. Add `"pluralLabel": "Posts"` for the list heading. See [Content model](https://editlet.gunkin.dev/docs/content-model.md#page-urls). ## Options `editlet()` takes `schemaPath` (default `cms/schema.json`, relative to the Astro root) and `admin`, the settings for the [live site](https://editlet.gunkin.dev/docs/dev-and-production.md). ## Limits - Astro `base` is not supported. The editor is always at `/editlet/` and the dev API at `/__editlet`. - `astro build` leaves out `draft: true` entries, and a reference to a draft resolves to `undefined`. - A static site has no server, so the [auth handler](https://editlet.gunkin.dev/docs/auth-handler.md) for GitHub sign-in runs elsewhere. # Docs for AI agents > Get these docs as Markdown for your agent: llms.txt, llms-full.txt and a .md file per page. Give your agent these docs as plain Markdown, without the site around it. The files follow the [llms.txt](https://llmstxt.org) convention. | URL | What it has | |---|---| | [`/llms.txt`](https://editlet.gunkin.dev/llms.txt) | An index: a link to each page's Markdown file with its one-line description, grouped like the sidebar | | [`/llms-full.txt`](https://editlet.gunkin.dev/llms-full.txt) | Every page in one file, in sidebar order | | `/docs/.md` | One page, for example [`/docs/quick-start-next.md`](https://editlet.gunkin.dev/docs/quick-start-next.md) | Each Markdown page starts with its title and description. Links in it are absolute and point to the other pages' `.md` files, so an agent can follow them. The site builds these files from the same entries as the HTML pages. ## Which one to use - **To install Editlet**, use the prompt in [Quick start: Next.js](https://editlet.gunkin.dev/docs/quick-start-next.md) or [Quick start: Astro](https://editlet.gunkin.dev/docs/quick-start-astro.md). The package ships the skills the agent needs. - **To answer a question** or plan a change, give the agent `/llms.txt`. It opens only the pages it needs. - **For one large context**, such as a chat without web access, paste `/llms-full.txt`. # Dev mode and production > Edit local files in dev, and edit on the live site through GitHub branches and pull requests. The editor at `?editlet` works in dev and on the live site. Use this page to set up the live site. | | Dev (`next dev`, `astro dev`) | Production (the live site) | |---|---|---| | Where edits go | Files in your working tree | Commits on `editlet/` branches on GitHub | | Sign-in | None | GitHub | | Go live | You commit and push | A developer merges the pull request | Edits you have not saved yet stay in the browser when you leave an entry, reload or close the editor, and you save them together as one commit from *Your changes* (on the live site, to the same branch and pull request). The editor picks the mode itself: if `GET /__editlet/files` answers `200`, it is in dev mode. ## Edit in dev The editor writes files through the dev API at `/__editlet`. Only `next dev` and `astro dev` serve it; `next build` fails if dev API code ends up in the output. The editor also shows your agent's changes within seconds. ## Set up the live site The editor talks to GitHub from the browser with the editor's own token. Your server runs only the [auth handler](https://editlet.gunkin.dev/docs/auth-handler.md) for the sign-in. 1. Set the admin options. They go into the public file `/editlet/config.json`, so never put a secret there. Astro takes the same options in `editlet({ admin: { … } })`. ```ts // next.config.ts export default withEditlet(nextConfig, { admin: { repo: 'acme/site', authUrl: 'https://example.com/api/editlet/oauth' }, }); ``` | Option | Default | Use | |---|---|---| | `repo` | Vercel's git env, else `GITHUB_REPOSITORY` | The repository, `owner/name` | | `authUrl` | none | The auth handler's public URL. Without it, only token sign-in works | | `sessionMinutes` | `CMS_SESSION_MINUTES`, else 60 | Sign out after this many idle minutes (1 to 1440) | | `param` | `EDITLET_PARAM`, else `editlet` | The query parameter that opens the editor | 2. Set `git.baseBranch` in `cms/schema.json`. Without it, or without a repository, the editor says "Editing on the live site is not set up". 3. Protect the base branch with a ruleset: require a pull request with one approval, and allow no bypass. An editor's token can merge through the API, so only GitHub can enforce review. See [Roles for admins and editors](https://editlet.gunkin.dev/docs/roles.md). 4. Do not send `Cross-Origin-Opener-Policy: same-origin`: it breaks the sign-in popup. ## Edit and publish on the live site 1. **Sign in** with GitHub, or with a fine-grained token: **Contents** and **Pull requests** read and write, **Deployments** read. Each browser tab signs in on its own. 2. **Save.** The base branch is read-only. The first save creates a branch such as `editlet/post-hello-world`. Each later save is one more commit there. 3. **Review changes** opens `?editlet=branch:`: the steps to publish (saved, the branch preview if your host reports deployments to GitHub, the review, live), and the changes with a diff per field. Vercel reports deployments; Netlify and Cloudflare Pages do not. 4. **Create pull request.** A developer merges it on GitHub, and the host redeploys. The editor never merges. If someone changed the same file on the branch since you opened it, the save stops and your edits stay. **Compare changes** shows each field they changed next to yours; pick one per field, apply, and save again on top of their version. ## Names of branches, commits and pull requests Branches start with `git.branchPrefix` (default `editlet/`). A commit reads `Update post/hello-world`, and a pull request `Update editlet/` with the label `editlet`. Change them in the `git` section of the schema ([Content model](https://editlet.gunkin.dev/docs/content-model.md)). Each commit ends with `Editlet-Source: admin` or `Editlet-Source: agent`. In *Your changes* the editor can add a **Note**: it becomes the commit message's body, above that line. Each changed field's diff there has **Revert this change**, which puts that field back before the save. # Content model and field types > Define collections and fields in cms/schema.json, and see how each field type is stored in entry files. You describe your content in one file, `cms/schema.json`. The editor, the agent skill, the build and the generated types all read it, and every entry file must match it. ## The schema file ```json { "contentDir": "cms/content", "git": { "baseBranch": "main" }, "collections": { "post": { "label": "Post", "pluralLabel": "Posts", "url": "/posts/{slug}", "titleField": "title", "slugFrom": "title", "fields": { "title": { "type": "string", "label": "Title", "required": true }, "body": { "type": "markdown", "label": "Body" } } }, "home": { "label": "Home page", "singleton": true, "url": "/", "fields": { "title": { "type": "string", "label": "Title" } } } } } ``` | Key | Meaning | |---|---| | `contentDir` | The entries folder, relative to the project root | | `git.baseBranch` | The branch the site deploys from; the editor opens pull requests into it | | `collections..label` | The name of one entry in the editor (*Post*); a singleton's only name | | `pluralLabel` | Optional: the name for many entries (*Posts*), for headings; not on a singleton. Without it the editor shows `label` | | `url` | Optional: the path of the collection's page on your site; see [Page URLs](#page-urls) | | `singleton` | `true`: the collection has one entry, `index.md` | | `titleField` | The field that names an entry in lists | | `slugFrom` | The field the **New** dialog fills with the title; the slug is made from that title | | `groups` | Optional tabs of the entry in the editor; see [Field groups](#field-groups) | | `fields` | A map of field key to field | An unknown key anywhere is an error. Collection and field keys start with a letter and hold only letters and digits. Optional `git` keys name what the editor and the agent create: | Key | Default | Placeholders and rules | |---|---|---| | `branchPrefix` | `editlet/` | Ends in `/`; must not clash with the base branch | | `commitMessage` | `{Action} {target}` | `{action}` (`create`, `update`, `delete`, `upload`), `{Action}`, `{collection}`, `{slug}`, `{target}` | | `pullRequest.title` | `Update {branch}` | `{branch}`, `{name}` (without the prefix), `{login}` | | `pullRequest.labels` | `["editlet"]` | At most 10; `[]` adds none | | `pullRequest.draft` | `false` | `true` opens draft pull requests | ## Page URLs `url` tells the editor where an entry is shown on your site. It is a path from the site's root: - `/posts/{slug}`: one page per entry. `{slug}` is replaced by the entry's slug (`/posts/tires`), the only placeholder. - `/`: a fixed path. Every entry of the collection is shown on that one page (sections of the homepage). A singleton's `url` is always a fixed path. - Keep your site's trailing `/` if it has one (`/posts/{slug}/`). - Leave `url` out for a collection that has no page of its own (authors, site settings). With `url`, the editor shows an entry's page address and can open the entry's page on the site. Write the slug as `{slug}`, not as your framework's `[slug]` or `:slug`. A path must start with `/`, use plain ASCII (no spaces, `?`, `#`, `%`, quotes, `<`, `>` or `//`), have at most 200 characters, and not be under `/editlet/` or `/__editlet`. Routes that depend on a field (`/2026/05/{slug}`, `/{category}/{slug}`), language prefixes and base paths cannot be written yet; leave `url` out for those collections. ## Field groups A collection with many fields can split them into tabs in the editor. List the tabs in `groups` and put `group` on the fields that belong to a tab other than the first: ```json "post": { "label": "Post", "groups": { "content": { "label": "Content" }, "media": { "label": "Media" }, "settings": { "label": "Settings" } }, "fields": { "title": { "type": "string", "label": "Title" }, "cover": { "type": "image", "label": "Cover image", "group": "media" }, "featured": { "type": "boolean", "label": "Show in the header", "group": "settings" } } } ``` Fields without `group` are in the first tab. Only top-level fields take `group`, and it must name one of the collection's `groups`. A tab with changed fields shows an amber dot, one with errors a red dot; with one group the editor shows no tabs. Groups only change the editor: entry files and types stay the same. ## Entry files Each entry is one UTF-8 file, `//.md`, with YAML frontmatter and a Markdown body: ```md --- title: Hello world cover: src: hello-world/cover.webp alt: A lighthouse at dusk draft: true --- The body is the collection's markdown field. ``` - **Slug:** lowercase letters and digits with single hyphens. The editor makes it from the title and drops other characters, so type it yourself for a non-Latin title. - **Drafts:** `draft: true` keeps the entry out of production builds. New entries from the editor start as drafts, copies made with ⋯ → Duplicate too. ⋯ → Set as draft (or Set as published) changes the flag; the editor saves it as any edit. - **Files:** besides entries, `contentDir` may hold only images and names starting with `.`. Anything else is an error. - **YAML:** the 1.2 core schema, so `2026-01-15` and `yes` stay strings. Saving in the editor drops comments. - Leave out empty optional fields instead of writing `null` or `''`. ## Field types There are 14 types. Every field takes `label` (required), `hint` (help text) and `required`; a top-level field can also take `group`. | Type | Options | In the file | |---|---|---| | `string` | `list`, `default` | `title: Hello`; a list of strings with `list: true` | | `text` | `rows` (editor height), `default` | A string, often a YAML block scalar | | `markdown` | none | The body. One per collection. Inside an `object` or block: a Markdown string | | `boolean` | `default`, `labels` (`true` and `false` texts) | `featured: true` | | `select` | `options` (`{ label, value }`), `multiple`, `default` | `status: live`; a list with `multiple` | | `number` | `min`, `max`, `integer`, `step` (editor only), `default` | `price: 9.5` | | `datetime` | `dateOnly`, `defaultNow` | `2026-01-15T09:00:00Z` (`Z`, offset or local time); `2026-01-15` with `dateOnly` | | `json` | none | Any YAML value | | `url` | none | `https://…`, `http://…` or a path like `/about` | | `color` | `default` | `accent: '#1a2b3c'`, quoted because `#` starts a YAML comment | | `image` | none | `{ src, alt }`, both required | | `reference` | `collections`, `multiple`, `min`, `max` | `author: author/jane`; a list with `multiple` | | `object` | `fields`, `list`, `min`, `max` | A mapping of its fields; a list of them with `list: true`. See [Objects and blocks](#objects-and-blocks) | | `blocks` | `blocks` (kind → `{ label, fields }`), `min`, `max` | A list of mappings, each with `block: `. See [Objects and blocks](#objects-and-blocks) | New entries get each `default` (it must pass its own field) and `defaultNow` sets the current time. `min` and `max` count list items and need `multiple` or `list`. A required list needs at least one item. ## References A reference is `collection/slug`; a singleton is `/index`, such as `home/index`. A list cannot hold one reference twice. To build a tree (a survey with sections with questions), give each level its own collection and a `multiple` reference to the next. Next.js reads a tree in one call, `getEntry('survey', 'onboarding', { depth: 2 })`; Astro needs one `getEntries` per level. Cycles are fine: reading stops at `depth`. In the editor, **Rename…** rewrites every reference and image path in one commit, and **Delete** can remove the references too, unless a required one would break. ## Objects and blocks Use them for parts that never live on their own. An `object` groups fields (an SEO group), or with `list: true` makes a list of groups (FAQ items). `blocks` is a list of items of different kinds: ```json "content": { "type": "blocks", "label": "Content", "blocks": { "hero": { "label": "Hero", "fields": { "title": { "type": "string", "label": "Title", "required": true } } }, "prose": { "label": "Text", "fields": { "text": { "type": "markdown", "label": "Text" } } } } } ``` ```yaml content: - block: hero title: Spring sale - block: prose text: | Two weeks of **discounts**. ``` Any field type works inside, nesting included. `block` cannot be a field key in a block, and neither type takes a `default`. In code, `if (b.block === 'hero')` narrows an item to the hero's fields. ## Images `src` is relative to the entry file's folder: `cms/content/post/hello-world.md` uses `hello-world/cover.webp`. The file must exist inside `contentDir` and end in `webp`, `png`, `jpg`, `jpeg`, `avif`, `gif` or `svg`; URLs are errors. The editor uploads to `///` in the same commit as the entry. Body images are not checked. ## Validation The editor checks before each save, the guard hook before a commit, and `next build` or `astro build` fail on an invalid entry. Run the check yourself: ```bash node node_modules/editlet/skills/editlet/scripts/validate.mjs ``` It prints `✓ N entries valid`, or one `file: field.path — message` line per issue and exit code 1. | Message | Fix | |---|---| | `Unknown field` | Add the field to the schema, or remove the key | | `Referenced entry not found: author/jane` | Create the entry, or fix the reference | | `This collection has no markdown field, but the entry has body content` | Remove the body, or add a `markdown` field | | `Not an entry file` | Move the file out of `contentDir`, or name it `/.md` | ## Generated types In Next.js, `withEditlet` writes `.editlet/content.d.ts` when `next dev` or `next build` starts; pass its `EntryMap` to `createReader`. Astro types come from `astro:content`. To write the file by hand, run `node node_modules/editlet/skills/editlet/scripts/types.mjs`. Do not commit it. ## Change the schema Ask your agent, for example "rename `cover` to `image` in posts". The skill shows which entries change or lose values first, then updates the schema and the entries. The editor's **Content model** screen (`?editlet=schema`) shows the collections, fields and any problems. # The agent skills > Install the three bundled agent skills, see what they do, and use their scripts and the guard hook. The `editlet` package ships three agent skills for Claude Code and other agents that read `.agents/skills/`. | Skill | Use it to | |---|---| | `editlet` | Edit content and the schema, validate, show changes in `?editlet`, publish through a pull request | | `editlet-setup` | Install Editlet in Next.js or Astro, set up the live site, upgrade, find what is broken | | `editlet-migrate` | Import content from Markdown or MDX folders, Astro collections, Decap, TinaCMS, Keystatic and others | ## Install the skills Give your agent this prompt in the project: ```text Install Editlet in this project: add the package `editlet` with the project's package manager, then read node_modules/editlet/skills/editlet-setup/SKILL.md and follow it. ``` To link the skills by hand, run this from the project root after you install the package: ```bash node node_modules/editlet/skills/editlet/scripts/link.mjs --hooks ``` It links each skill into `.claude/skills/` and `.agents/skills/` and adds the guard hook to `.claude/settings.json`. Add `--check` to only report what is missing. In a monorepo, run it where you start Claude Code. ## What the agent does with content 1. It reads `cms/schema.json` and runs `git status`, so it keeps your own edits. 2. It tells you which files it will change, and asks again before it deletes data. 3. It edits, then runs `validate` until it passes. Schema changes get a dry run first. 4. If a dev server runs, it opens the matching `?editlet` screen. 5. When you ask to publish, it commits only its own files on an `editlet/` branch and opens a pull request. 6. It merges only after you approve that pull request in the conversation. ## Run the scripts Run them with `node .claude/skills/editlet/scripts/