copilotkit-setup
Use when adding CopilotKit to an existing project or bootstrapping a new CopilotKit project from scratch. Covers framework detection, package installation, runtime wiring, provider setup, and first working chat integration.
What this skill does
# CopilotKit Setup
## Prerequisites
### Live Documentation (MCP)
This plugin includes an MCP server (`copilotkit-docs`) that provides `search-docs` and `search-code` tools for querying live CopilotKit documentation and source code.
- **Claude Code:** Auto-configured by the plugin's `.mcp.json` -- no setup needed.
- **Codex:** Requires manual configuration. See the [copilotkit-debug skill](../copilotkit-debug/SKILL.md#mcp-setup) for setup instructions.
### Environment
Before starting setup, verify:
1. **Node.js >= 18** (required for `fetch` globals used by the runtime)
2. **An AI provider API key** (one of: `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GOOGLE_API_KEY`)
3. **A React-based frontend** (Next.js App Router, Next.js Pages Router, Vite + React, or Angular)
4. **A backend capable of running the runtime** (same Next.js app via API routes, or a standalone Express/Hono server)
## Framework Detection
Before generating any code, detect the project's framework by checking files in the project root. See `references/framework-detection.md` for the full decision tree.
**Quick summary:**
| Signal File | Framework |
|---|---|
| `next.config.{js,ts,mjs}` + `app/` directory | Next.js App Router |
| `next.config.{js,ts,mjs}` + `pages/` directory | Next.js Pages Router |
| `angular.json` | Angular |
| `vite.config.{js,ts}` + React deps in package.json | Vite + React |
## Setup Workflow
### Step 1: Install packages
All packages use the `@copilotkit` namespace.
**Frontend (React) packages:**
```bash
npm install @copilotkit/react @copilotkit/core
```
**Runtime packages (backend):**
```bash
npm install @copilotkit/runtime @copilotkit/agent
```
If the runtime runs in the same Next.js app as the frontend, install all four packages together.
For standalone Express backends, also install Express adapter dependencies:
```bash
npm install express cors
npm install -D @types/express @types/cors
```
### Step 2: Configure the runtime
The runtime is the server-side component that manages agent execution. See `references/runtime-architecture.md` for details.
There are two endpoint styles:
1. **Multi-route (Hono)** -- uses `createCopilotEndpoint`. Requires a catch-all route (`[[...slug]]` in Next.js). Each operation (run, connect, stop, info, transcribe, threads) gets its own HTTP path.
2. **Single-route (Hono or Express)** -- uses `createCopilotEndpointSingleRoute` or `createCopilotEndpointSingleRouteExpress`. All operations go through a single POST endpoint with method multiplexing.
#### Next.js App Router (recommended: multi-route with Hono)
Create `src/app/api/copilotkit/[[...slug]]/route.ts`:
```typescript
import {
CopilotRuntime,
createCopilotEndpoint,
InMemoryAgentRunner,
} from "@copilotkit/runtime";
import { BuiltInAgent } from "@copilotkit/agent";
import { handle } from "hono/vercel";
const agent = new BuiltInAgent({
model: "openai/gpt-4o",
prompt: "You are a helpful AI assistant.",
});
const runtime = new CopilotRuntime({
agents: {
default: agent,
},
runner: new InMemoryAgentRunner(),
});
const app = createCopilotEndpoint({
runtime,
basePath: "/api/copilotkit",
});
export const GET = handle(app);
export const POST = handle(app);
```
This requires `hono` as a dependency:
```bash
npm install hono
```
#### Next.js App Router (alternative: single-route)
Create `src/app/api/copilotkit/route.ts`:
```typescript
import {
CopilotRuntime,
createCopilotEndpointSingleRoute,
InMemoryAgentRunner,
} from "@copilotkit/runtime";
import { BuiltInAgent } from "@copilotkit/agent";
import { handle } from "hono/vercel";
const agent = new BuiltInAgent({
model: "openai/gpt-4o",
prompt: "You are a helpful AI assistant.",
});
const runtime = new CopilotRuntime({
agents: {
default: agent,
},
runner: new InMemoryAgentRunner(),
});
const app = createCopilotEndpointSingleRoute({
runtime,
basePath: "/api/copilotkit",
});
export const POST = handle(app);
```
When using single-route, the frontend must set `useSingleEndpoint` on the provider (see Step 3).
#### Standalone Express Server
Create `src/index.ts`:
```typescript
import express from "express";
import { CopilotRuntime } from "@copilotkit/runtime";
import { createCopilotEndpointSingleRouteExpress } from "@copilotkit/runtime/express";
import { BuiltInAgent, defineTool } from "@copilotkit/agent";
import { z } from "zod";
const agent = new BuiltInAgent({
model: "openai/gpt-4o",
});
const runtime = new CopilotRuntime({
agents: {
default: agent,
},
});
const app = express();
app.use(
"/api/copilotkit",
createCopilotEndpointSingleRouteExpress({
runtime,
basePath: "/",
}),
);
const port = Number(process.env.PORT ?? 4000);
app.listen(port, () => {
console.log(`CopilotKit runtime listening at http://localhost:${port}/api/copilotkit`);
});
```
For multi-route Express, use `createCopilotEndpointExpress` instead (imported from `@copilotkit/runtime/express`).
#### Standalone Hono Server (non-Vercel)
```typescript
import { CopilotRuntime, createCopilotEndpoint } from "@copilotkit/runtime";
import { BuiltInAgent } from "@copilotkit/agent";
import { serve } from "@hono/node-server";
const runtime = new CopilotRuntime({
agents: {
default: new BuiltInAgent({ model: "openai/gpt-4o" }),
},
});
const app = createCopilotEndpoint({
runtime,
basePath: "/api/copilotkit",
});
serve({ fetch: app.fetch, port: 8787 });
```
Requires `@hono/node-server`:
```bash
npm install hono @hono/node-server
```
### Step 3: Set up the frontend provider
Wrap your application with `CopilotKitProvider` from `@copilotkit/react`.
**Important:** Import the stylesheet in your root layout:
```typescript
import "@copilotkit/react/styles.css";
```
#### Next.js App Router
In `src/app/page.tsx` (or a client component):
```tsx
"use client";
import { CopilotKitProvider, CopilotChat } from "@copilotkit/react";
export default function Home() {
return (
<CopilotKitProvider runtimeUrl="/api/copilotkit">
<div style={{ height: "100vh" }}>
<CopilotChat />
</div>
</CopilotKitProvider>
);
}
```
#### Connecting to an external runtime
When the runtime runs on a separate server (e.g., Express on port 4000):
```tsx
<CopilotKitProvider
runtimeUrl="http://localhost:4000/api/copilotkit"
useSingleEndpoint
>
{children}
</CopilotKitProvider>
```
Set `useSingleEndpoint` when the backend uses single-route endpoints (`createCopilotEndpointSingleRoute` or `createCopilotEndpointSingleRouteExpress`).
#### CopilotKitProvider key props
| Prop | Type | Description |
|---|---|---|
| `runtimeUrl` | `string` | URL of the CopilotKit runtime endpoint |
| `useSingleEndpoint` | `boolean` | Set to `true` when using single-route endpoints |
| `headers` | `Record<string, string>` | Custom headers sent with every request |
| `credentials` | `RequestCredentials` | Fetch credentials mode (e.g., `"include"` for cookies) |
| `publicApiKey` | `string` | Copilot Cloud public API key (if using hosted runtime) |
| `showDevConsole` | `boolean \| "auto"` | Show the dev inspector (`"auto"` = development only) |
| `renderToolCalls` | `ReactToolCallRenderer[]` | Custom renderers for tool call UI |
| `frontendTools` | `ReactFrontendTool[]` | Frontend-defined tools (declarative alternative to `useFrontendTool`) |
| `onError` | `(event) => void` | Global error handler |
### Step 4: Add a chat UI component
CopilotKit provides three pre-built chat layouts:
| Component | Usage |
|---|---|
| `CopilotChat` | Inline chat, fills its container |
| `CopilotSidebar` | Collapsible sidebar panel |
| `CopilotPopup` | Floating popup widget |
Example with sidebar:
```tsx
<CopilotKitProvider runtimeUrl="/api/copilotkit" showDevConsole="auto">
<YourApp />
<CopilotSidebar
defaultOpen
width="420px"
labels={{
modalHeaderTitle: "AI Assistant",
chatInputPlaceholder: "Ask me anything...",
}}
/>
</CopilotKitProvider>
```
### Step 5: Set environment vRelated in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.