Skip to content

Files and Keystatic

By default, all of a template’s content is plain files inside your project: JSON for pages and settings, Markdown for posts and other collections, and the photos next to them. Keystatic is a visual editor for exactly these files. It runs inside your site at /keystatic, so there’s no extra service, account or cost.

You can use it in two ways:

  • On your computer (the default): Keystatic writes the files on disk. You commit and push them like any other change, and your host publishes the site.
  • On the live site (GitHub mode): you, or a client, edit at https://<your-domain>/keystatic. Every save becomes a commit to your GitHub repository, and your host rebuilds the site.

The examples below use Handy (npx wptom new my-site -t handy). The steps are the same for every template in the files/Sanity variant.

  1. In your project folder, start the site:

    Terminal window
    npm run dev
  2. Open the address it prints (127.0.0.1 and a port number, usually 4321) and add /keystatic at the end.

  3. Pick a page or an entry, change it and click Save. Reload the site in another tab to see the change.

The editor is organised like the site. Pages holds every single page (home, the other pages, the 404 page), site settings, legal pages and the brand; Content holds the collections (in Handy: services, jobs and tips) and the interface texts (buttons, labels, emails). Some templates add sections of their own, such as a blog. Fields follow the same rules as the build: required fields, lengths and formats such as colors are checked before you can save, so you can’t save something the site would reject.

What you edit File
A single page (home, contact, 404…) src/content/singletons/<language>/<page>.json
Site settings (name, navigation, footer, contact details) src/content/singletons/<language>/site.json
Interface texts src/content/singletons/<language>/ui.json
Brand (colors, fonts, corners) src/content/singletons/brand.json
An entry of a collection src/content/<collection>/<language>/<slug>.md (.json for a few collections without a body, such as landing pages)
Photos src/assets/photos/<page or collection>/…

<language> is the language code, en in a site with one language. An entry’s file name is its slug, which is also the last part of its address: renaming the slug renames the file and changes the page’s URL.

You can also edit these files directly in your code editor; Keystatic reads whatever is on disk.

Saving in Keystatic only changes files on your computer. To publish them, commit and push:

Terminal window
git add .
git commit -m "New services"
git push

If your site is on Vercel connected to GitHub, every push to main publishes it again. See Put your site online.

In GitHub mode, Keystatic signs editors in with their GitHub account and saves each change as a commit to your repository. Your host sees the new commit and rebuilds the site, usually within a minute or two.

You need:

  • your project on GitHub and deployed on Vercel (see Put your site online);
  • a GitHub account for each editor, with write access to the repository.
Variable What it is Where it comes from
PUBLIC_KEYSTATIC_GITHUB_REPO Your repository as owner/name, e.g. your-name/my-site You set it
PUBLIC_KEYSTATIC_GITHUB_APP_SLUG The name of the GitHub App in its URL Written by Keystatic
KEYSTATIC_GITHUB_CLIENT_ID The GitHub App’s client id Written by Keystatic
KEYSTATIC_GITHUB_CLIENT_SECRET The GitHub App’s client secret Written by Keystatic
KEYSTATIC_SECRET A random secret that protects editors’ sign-in sessions (at least 32 characters) Written by Keystatic

PUBLIC_KEYSTATIC_GITHUB_REPO is the switch. While it’s empty, Keystatic edits local files and is left out of the production build, so /keystatic doesn’t exist on the live site. Once it’s set, Keystatic uses GitHub everywhere, on your computer too.

  1. If you don’t have a .env file yet, copy the example: cp .env.example .env (Windows PowerShell: Copy-Item .env.example .env).

  2. In .env, set your repository:

    Terminal window
    PUBLIC_KEYSTATIC_GITHUB_REPO=your-name/my-site
  3. Start the site again (Ctrl C, then npm run dev).

Keystatic needs a GitHub App, a small app in your GitHub account that is allowed to read and write your repository. Keystatic creates it for you:

  1. Open the 127.0.0.1 address npm run dev prints, followed by /keystatic. Use that address, not localhost: GitHub will only send you back to the address the app was created on.
  2. Keystatic shows Keystatic Setup. Fill in:
    • Deployed App URL: your live address, e.g. https://www.example.com. Keystatic adds it to the app’s callback URLs, so you can skip step 4 below. Not sure yet? Leave it blank.
    • GitHub organization (if any): only if the repository belongs to an organisation (you must be an owner or GitHub App manager there). Blank creates the app in your own account.
  3. Click Create GitHub App. GitHub opens with the app filled in. The suggested name is “<owner> Keystatic”; GitHub app names must be unique, so change it if GitHub says it’s taken. Confirm with Create GitHub App.
  4. GitHub sends you back, and Keystatic adds four values to the end of your .env: KEYSTATIC_GITHUB_CLIENT_ID, KEYSTATIC_GITHUB_CLIENT_SECRET, KEYSTATIC_SECRET and PUBLIC_KEYSTATIC_GITHUB_APP_SLUG.
  5. Open .env and delete the empty lines with the same names higher up (they came from .env.example), so each name appears once.
  6. Install the app on your repository: click Install GitHub App on the page Keystatic shows (or open https://github.com/apps/<app-slug> and click Install), choose Only select repositories and pick your site’s repository.
  7. Restart npm run dev so it reads the new values.

The app gets only what Keystatic needs: write access to the repository’s contents, and read access to its metadata and pull requests.

Before you deploy, check that everything works locally:

  1. Open the same /keystatic address and click Log in with GitHub. Authorise the app.
  2. Change something small and click Save.
  3. On GitHub, open your repository: the change is there as a new commit. If Vercel is connected, it starts a new deployment.
  4. Bring the commit to your computer with git pull. In GitHub mode, saves go to GitHub, not to the files on your disk.

To go back to editing local files, empty PUBLIC_KEYSTATIC_GITHUB_REPO and restart npm run dev.

If you entered your live address as Deployed App URL in step 2, this is done. Otherwise the app only knows your computer’s address; add the live one:

  1. On GitHub: your profile picture → Settings → Developer settings → GitHub Apps → your app → Edit (for an organisation: the organisation’s Settings → Developer settings).

  2. Under Callback URL, click Add Callback URL and enter:

    https://<your-domain>/api/keystatic/github/oauth/callback

    Use the exact address editors will open, with or without www. Want to edit on the <project>.vercel.app address too? Add a callback URL for it as well.

  3. Click Save changes.

  1. In Vercel: your project → Settings → Environment Variables.
  2. Add all five, with the same values as in your .env: PUBLIC_KEYSTATIC_GITHUB_REPO, PUBLIC_KEYSTATIC_GITHUB_APP_SLUG, KEYSTATIC_GITHUB_CLIENT_ID, KEYSTATIC_GITHUB_CLIENT_SECRET and KEYSTATIC_SECRET.
  3. Redeploy: Deployments → the latest one → ⋯ → Redeploy, or push a commit. New variables only take effect in a new deployment.
  4. Open https://<your-domain>/keystatic and log in with GitHub.

Anyone who should edit needs a GitHub account and write access to the repository:

  1. On GitHub: your repository → Settings → Collaborators → Add people (in an organisation, give them a role with write access).
  2. Once they accept the invitation, they open https://<your-domain>/keystatic, click Log in with GitHub and authorise the app the first time.
  1. The editor clicks Save in Keystatic.
  2. Keystatic commits the changed files (and any new photos) to the repository, in the editor’s name.
  3. Vercel sees the commit on main and builds the site.
  4. About a minute later the new version is live. If the build fails (for example, a required field the build checks more strictly), the previous version stays online and Vercel shows the error under Deployments.

Keystatic can also work on a branch other than main (the branch menu at the top of the editor). Commits there don’t change the live site; Vercel builds them as a preview, and you merge the branch on GitHub to publish.

Because every save is a commit, pull before you change files on your computer (git pull), so your work and the editors’ don’t collide.

Upload photos through an image field in Keystatic. Each page and collection keeps its photos in its own folder under src/assets/photos/ (collections get a sub-folder per entry), and Keystatic names each file after its field. The site resizes them when it builds and serves modern formats, so you can upload the original photo; very large files only make commits and builds slower.

Upload a photo for each place you use it rather than pointing several entries at one file: when an entry is saved, Keystatic deletes photos in its folder that the entry no longer uses. Always fill in the alt text field that sits next to each photo; it describes the photo for people who can’t see it.

/keystatic shows “Not found” on the live site. PUBLIC_KEYSTATIC_GITHUB_REPO wasn’t set when Vercel built the site. Add it under Settings → Environment Variables and redeploy.

Missing required config in Keystatic API setup when using the 'github' storage mode One of KEYSTATIC_GITHUB_CLIENT_ID, KEYSTATIC_GITHUB_CLIENT_SECRET or KEYSTATIC_SECRET is missing on your host. The message names it; add it and redeploy.

KEYSTATIC_SECRET must be at least 32 characters long The value was cut off when copied. Copy the whole line from .env again.

redirect_uri_mismatch or “The redirect_uri MUST match the registered callback URL” The address you opened isn’t among the GitHub App’s callback URLs. Add https://<that-address>/api/keystatic/github/oauth/callback (step 4). Locally, open 127.0.0.1 rather than localhost.

App setup only allowed in development The GitHub App can only be created from npm run dev on your computer. Create it there (step 2), then copy the values to your host.

Expected "owner/name", got "…" PUBLIC_KEYSTATIC_GITHUB_REPO must be only the owner and repository name, like your-name/my-site, not the full GitHub URL.

You can sign in but don’t see the repository, or saving fails. The GitHub App isn’t installed on that repository, or your account doesn’t have write access. Check the app’s installation (https://github.com/apps/<app-slug> → Configure) and the repository’s collaborators.

A save worked, but the live site didn’t change. Look at Vercel’s Deployments: the build may still be running, or it failed and shows why. Check that Keystatic saved to main (the branch menu) and not to another branch.

Keystatic won’t let you save. A field doesn’t meet its rules (a required field is empty, a text is too long, a color isn’t valid). The field shows what’s wrong.