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.
Edit on your computer
Section titled “Edit on your computer”-
In your project folder, start the site:
Terminal window npm run dev -
Open the address it prints (
127.0.0.1and a port number, usually 4321) and add/keystaticat the end. -
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.
Which files change
Section titled “Which files change”| 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.
Commit and publish
Section titled “Commit and publish”Saving in Keystatic only changes files on your computer. To publish them, commit and push:
git add .git commit -m "New services"git pushIf your site is on Vercel connected to GitHub, every push to main publishes it again. See
Put your site online.
Edit on the live site (GitHub mode)
Section titled “Edit on the live site (GitHub mode)”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.
The settings
Section titled “The settings”| 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. Turn it on locally
Section titled “1. Turn it on locally”-
If you don’t have a
.envfile yet, copy the example:cp .env.example .env(Windows PowerShell:Copy-Item .env.example .env). -
In
.env, set your repository:Terminal window PUBLIC_KEYSTATIC_GITHUB_REPO=your-name/my-site -
Start the site again (Ctrl C, then
npm run dev).
2. Create the GitHub App
Section titled “2. Create the GitHub App”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:
- Open the
127.0.0.1addressnpm run devprints, followed by/keystatic. Use that address, notlocalhost: GitHub will only send you back to the address the app was created on. - 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.
- Deployed App URL: your live address, e.g.
- 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. - GitHub sends you back, and Keystatic adds four values to the end of your
.env:KEYSTATIC_GITHUB_CLIENT_ID,KEYSTATIC_GITHUB_CLIENT_SECRET,KEYSTATIC_SECRETandPUBLIC_KEYSTATIC_GITHUB_APP_SLUG. - Open
.envand delete the empty lines with the same names higher up (they came from.env.example), so each name appears once. - 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. - Restart
npm run devso 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.
3. Try it on your computer
Section titled “3. Try it on your computer”Before you deploy, check that everything works locally:
- Open the same
/keystaticaddress and click Log in with GitHub. Authorise the app. - Change something small and click Save.
- On GitHub, open your repository: the change is there as a new commit. If Vercel is connected, it starts a new deployment.
- 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.
4. Add your domain to the GitHub App
Section titled “4. Add your domain to the GitHub App”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:
-
On GitHub: your profile picture → Settings → Developer settings → GitHub Apps → your app → Edit (for an organisation: the organisation’s Settings → Developer settings).
-
Under Callback URL, click Add Callback URL and enter:
https://<your-domain>/api/keystatic/github/oauth/callbackUse the exact address editors will open, with or without
www. Want to edit on the<project>.vercel.appaddress too? Add a callback URL for it as well. -
Click Save changes.
5. Set the same values on Vercel
Section titled “5. Set the same values on Vercel”- In Vercel: your project → Settings → Environment Variables.
- 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_SECRETandKEYSTATIC_SECRET. - Redeploy: Deployments → the latest one → ⋯ → Redeploy, or push a commit. New variables only take effect in a new deployment.
- Open
https://<your-domain>/keystaticand log in with GitHub.
6. Invite editors
Section titled “6. Invite editors”Anyone who should edit needs a GitHub account and write access to the repository:
- On GitHub: your repository → Settings → Collaborators → Add people (in an organisation, give them a role with write access).
- Once they accept the invitation, they open
https://<your-domain>/keystatic, click Log in with GitHub and authorise the app the first time.
How a save becomes a published change
Section titled “How a save becomes a published change”- The editor clicks Save in Keystatic.
- Keystatic commits the changed files (and any new photos) to the repository, in the editor’s name.
- Vercel sees the commit on
mainand builds the site. - 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.
Photos
Section titled “Photos”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.
Troubleshooting
Section titled “Troubleshooting”/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.
