Skip to main content
skill CX Codex

contentful-nextjs — Claude Code skill: Contentful in Next.js

Wires Contentful into an existing Next.js app: SDK, env vars, production and preview clients, Draft Mode.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add contentful/skills --skill contentful-nextjs -a claude-code
Open on GitHub

What contentful-nextjs does

The skill walks the agent through the setup in order: check the project structure, configure environment variables, install and initialize contentful, implement published-content fetching, add Draft Mode behavior, then validate with a minimal test route. Both App Router and Pages Router are covered. If the router type is not given, the skill defaults to App Router.

Three variables are required: CONTENTFUL_SPACE_ID, CONTENTFUL_ACCESS_TOKEN, and CONTENTFUL_PREVIEW_ACCESS_TOKEN for preview. One API key in the space settings provides both tokens. When the variables are missing, the skill asks you to add them to .env.local before it continues. Normal delivery uses the CDA host; Draft Mode switches to preview.contentful.com with the preview token.

Client creation belongs in a shared utility module, and the environment value should be an alias such as master so runtime clients do not depend on release environment IDs. The skill refuses to guess Next.js versions: before suggesting an upgrade or a compatibility workaround it checks the releases on GitHub. Personalization and the Experiences SDK are out of scope here and live in a separate skill.

What it helps with

  • add Contentful to an existing Next.js project
  • separate production and preview clients
  • set up Draft Mode so editors can view drafts
  • pick between App Router and Pages Router for entry fetching
  • decouple runtime clients from release environment IDs with an alias

Example prompts for the agent

  • set up Contentful in this Next.js project
  • add Draft Mode preview for Contentful
  • fetch Contentful entries in Server Components

How to install contentful-nextjs

1Skills CLI (Vercel)

npx skills add contentful/skills --skill contentful-nextjs -a claude-code

2Manually: put the files in place

~/.claude/skills/contentful-nextjs/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/contentful-nextjs/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about contentful-nextjs

How do I install contentful-nextjs in Claude?

Run npx skills add contentful/skills --skill contentful-nextjs -a claude-code. The skill lands at ~/.claude/skills/contentful-nextjs/SKILL.md.

What does contentful-nextjs do?

It handles the Contentful integration in an existing Next.js app: SDK install, environment variables, production and preview clients, content fetching, and Draft Mode.

Which environment variables does it need?

CONTENTFUL_SPACE_ID, CONTENTFUL_ACCESS_TOKEN, and CONTENTFUL_PREVIEW_ACCESS_TOKEN for preview. Both tokens come from one API key in the Contentful space settings.

Source text

SKILL.md · MIT
---
name: contentful-nextjs
description: >-
  Add and configure Contentful in an existing Next.js project. Covers installing
  the JavaScript SDK, configuring environment variables, creating production and
  preview-aware clients, fetching content in App Router or Pages Router, and
  wiring Draft Mode preview flows. Use when users ask to integrate Contentful
  with Next.js, fetch entries, set up preview or draft content, or configure
  the Contentful client. Also triggers on "Contentful SDK Next.js",
  "contentful.js", "fetch Contentful entries", "get content from Contentful",
  "Contentful preview", "preview mode", "Contentful environment variables",
  "Contentful client setup", "create Contentful client", "Pages Router
  Contentful", "getStaticProps Contentful", "Server Components Contentful",
  "revalidate Contentful", "ISR Contentful". Not for personalization or
  Experiences SDK setup (contentful-personalization). Not for non-Next.js
  frameworks (contentful-guide can route to platform docs).
argument-hint: "[what to set up]"
allowed-tools: Bash(npm install contentful) Bash(npm install @contentful/rich-text-*) mcp__contentful-mcp__* mcp__plugin_contentful_contentful-mcp__*
---

# Contentful Next.js

Use this skill to integrate Contentful into an existing Next.js application.

Contentful is a headless, API-first CMS (composable content platform) that lets Next.js apps fetch structured content through delivery and preview APIs.

## Scope

- Next.js App Router and Pages Router.
- Published content delivery (CDA).
- Preview content delivery with Draft Mode (CPA).
- Environment variable and client setup patterns.
- Environment alias-aware setup for stable deployment paths.

## Not in scope

- Personalization/optimization implementations.
- Studio Experiences SDK setup.
- Full content-model strategy design.

## Contentful MCP note

- If the user wants easier agent-driven interaction with Contentful during setup, suggest the Contentful MCP server docs: `https://www.contentful.com/developers/docs/tools/mcp-server/`.
- Keep this skill focused on Next.js implementation. MCP guidance complements setup but does not replace app-side client wiring.

## Project state

```!
echo "=== Contentful packages ===" && node -e "try{const p=require('./package.json');const d={...p.dependencies,...p.devDependencies};const c=Object.entries(d).filter(([k])=>k.includes('contentful'));console.log(c.length?c.map(([k,v])=>k+'@'+v).join('\n'):'(Contentful SDK not installed)')}catch{console.log('(no package.json)')}" 2>/dev/null
echo ""
echo "=== Contentful env vars ===" && grep -h CONTENTFUL .env.local .env 2>/dev/null | sed 's/=.*/=<set>/' || echo "(no Contentful env vars found in .env.local or .env)"
echo ""
echo "=== Router type ===" && ([ -d "app" ] && echo "App Router detected (app/ directory exists)" || ([ -d "pages" ] && echo "Pages Router detected (pages/ directory exists)" || echo "(could not detect router type)"))
```

## Workflow

1. Check the latest stable Next.js release online at `https://github.com/vercel/next.js/releases` when version-specific guidance is needed.
2. Confirm Next.js project structure (App Router vs Pages Router).
3. Configure required env vars. If they are missing, ask the user to add them to `.env.local` before continuing, and explain where to find each value.
4. Install and initialize `contentful` SDK.
5. Implement published-content fetching.
6. Add preview-aware behavior for Draft Mode.
7. Validate with a minimal test route/page and troubleshooting checklist.

## Version-check policy

- Do not rely on memory for "latest Next.js version" claims.
- Verify against `https://github.com/vercel/next.js/releases` before recommending upgrades, compatibility workarounds, or version-specific fixes.
- Treat the latest non-prerelease tag as default unless the user explicitly asks for canary/RC guidance.

## Required environment variables

- `CONTENTFUL_SPACE_ID` - Find it in the Contentful URL (`/spaces/<SPACE_ID>/...`) or in **Space settings -> API keys**.
- `CONTENTFUL_ACCESS_TOKEN` - CDA token from **Space settings -> API keys**.
- `CONTENTFUL_PREVIEW_ACCESS_TOKEN` (for preview workflows) - CPA token from **Space settings -> API keys**.

Creating an API key in Contentful provides both tokens needed here:
- CDA token -> `CONTENTFUL_ACCESS_TOKEN`
- CPA token -> `CONTENTFUL_PREVIEW_ACCESS_TOKEN`

## Defaults

- If the user does not specify router type, default to Next.js App Router guidance.
- Use CDA host for normal delivery.
- Use `preview.contentful.com` and preview token when Draft Mode is enabled.
- Prefer an environment alias (for example `master`) as the client `environment` value to decouple runtime clients from release environment IDs.
- Keep Contentful client creation in a shared utility module.

## References

- [Next.js setup](references/nextjs-setup.md)
- [Preview and Draft Mode](references/preview-and-draft-mode.md)
- [Troubleshooting](references/troubleshooting.md)

© contentful · MIT · contentful/skills

Similar skills

Everything for Frontend and UI →

From the same set5

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor