# Comments

Pin comments on any page of your site, sign in with GitHub, and post threads to the preview's pull request.

Hosts: Node, Docker, Cloudflare, Vercel, Netlify.

```ts [vite.config.ts]
import vue from '@vitejs/plugin-vue'
import comments from '@vite-hub/comments/vite'
import { defineConfig } from 'vite'

// One plugin turns Comments on. No Database, no login of your own.
export default defineConfig({
  plugins: [vue(), comments()],
})
```

```bash [.env]
# Sign in with GitHub: people who can push to the repository may comment
VITEHUB_GITHUB_CLIENT_ID=Iv23li...
VITEHUB_GITHUB_CLIENT_SECRET=...
VITEHUB_SECRET=...
```

```ts [server/comments.ts]
import { defineComments } from '@vite-hub/comments'

// Optional: change who may comment, and post threads to pull requests.
export const comments = defineComments({
  authorize: ({ user, action }) => action === 'read' || user?.github?.write === true,
  forge: { provider: 'github' },
})
```

```ts [server/api/open-threads.get.ts]
import { defineEventHandler } from 'h3'
import { comments } from '../comments'

// The same threads, from server code
export default defineEventHandler(async () => {
  const [error, threads] = await comments.list({ status: 'open' })
  if (error) throw error
  return threads.map(thread => thread.page)
})
```

## Pick a setup

Start with one plugin and add more later.

| Setup | You add | You get |
| --- | --- | --- |
| [Comments alone](https://vitehub.dev/docs/comments/get-started) | `comments()` in `vite.config.ts` | Pins, threads, replies, and resolve on every page. Threads in your database, Turso, Cloudflare D1, or a SQLite file, in tables Comments creates. Guests on the dev server. |
| [With GitHub sign-in](https://vitehub.dev/docs/comments/configure#sign-in-with-github) | A GitHub App and three server variables | People who can push to the repository sign in and comment. Pull request comments show their GitHub account. |
| [In a ViteHub app](https://vitehub.dev/docs/comments/with-vite-hub) | `vitehub()` with a Database, and `server/comments.ts` | Any ViteHub Database on every host. Live cursors, Content edits in place, the Console section, MCP tools for Agents, and your own sign-in. |
| [On a docs site](https://vitehub.dev/docs/docs-site/configure#comments) | `vite-hub/nuxt` beside `@vite-hub/docs/nuxt` | On by default on every docs page, with threads in the Console. `docs: { comments: false }` turns it off. |

### [One plugin turns it on](https://vitehub.dev/docs/comments/get-started#turn-on-comments)

Add `comments()` to `vite.config.ts` to get the API, the overlay, and a SQLite file for threads.

### [Sign in with GitHub](https://vitehub.dev/docs/comments/configure#sign-in-with-github)

People who can push to the repository may comment. The session is a cookie; the server stores no users.

### [Public visitors get nothing extra](https://vitehub.dev/docs/comments/configure#turn-comment-mode-on-and-off)

The overlay loads only for readers that `authorize` allows, on a request with `?vitehub` or the `vitehub-tools` cookie.

### [Pins follow the text](https://vitehub.dev/docs/comments/server-api#anchors)

A pin finds its element after a resize or layout change. A pin on a Content field survives a redesign.

### [See who is on the page](https://vitehub.dev/docs/comments/with-vite-hub#see-who-else-is-on-the-page)

With Realtime, people on a page see each other's avatars and cursors, and new comments appear at once.

### [Edit Content text in place](https://vitehub.dev/docs/comments/with-vite-hub#edit-content-text-in-place)

Mark an element with `contentField()`. Edits save a Content draft that you publish in the Console.

### [Decide who can comment](https://vitehub.dev/docs/comments/configure#decide-who-can-comment)

`authorize()` allows or denies `read`, `write`, `resolve`, and `delete` per user, and can let guests comment.

### [Notify the people you mention](https://vitehub.dev/docs/comments/configure#notify-mentioned-people)

`people` fills the `@` list. `onComment` runs after each comment, for example to send an Email.

### [Triage in the Console](https://vitehub.dev/docs/comments/configure#triage-in-the-console)

The Comments section lists each thread with its page and status, and links to the pin.

## Comments through Operations

The same `server/comments.ts` also runs the [comment operations](https://vitehub.dev/docs/comments/operations/get-started): numbered threads on your own subjects, for the CLI, MCP, the Console, and your UI. Export the definition as `comments` or as the default export. Both use the same tables.

<!-- vitehub-docs:section-links -->
## In this section

- [Overview](https://vitehub.dev/raw/docs/comments.md) (this page)
- [Get started](https://vitehub.dev/raw/docs/comments/get-started.md)
- [Configure](https://vitehub.dev/raw/docs/comments/configure.md)
- [Server API](https://vitehub.dev/raw/docs/comments/server-api.md)
- [Hosts](https://vitehub.dev/raw/docs/comments/hosts.md)
- [Limits and errors](https://vitehub.dev/raw/docs/comments/limits-and-errors.md)
- [With ViteHub](https://vitehub.dev/raw/docs/comments/with-vite-hub.md)
- [Operations overview](https://vitehub.dev/raw/docs/comments/operations.md)
- [Operations tutorial](https://vitehub.dev/raw/docs/comments/operations/get-started.md)
- [Configure operations](https://vitehub.dev/raw/docs/comments/operations/configure.md)
- [Operations server API](https://vitehub.dev/raw/docs/comments/operations/server-api.md)
- [Operations limits and errors](https://vitehub.dev/raw/docs/comments/operations/limits-and-errors.md)

Next: [COMMENTS_R0001](https://vitehub.dev/raw/docs/comments/diagnostics/comments_r0001.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
