This file provides guidance to AI assistants (Claude Code, Cursor, etc.) when working with code in this repository.
Better Auth is a comprehensive, framework-agnostic authentication framework for TypeScript.
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Run all tests
pnpm test
# Lint code
pnpm lint
# Fix linting issues
pnpm lint:fix
# Type check
pnpm typecheck
# Format code
pnpm format
# Check formatting
pnpm format:checkDo not run pnpm test directly because it runs tests in all packages,
which takes a long time, use vitest /path/to/<test-file> -t <pattern> to
run specific tests.
packages/better-auth- Main authentication librarypackages/core- Core utilities and typespackages/cli- Command-line interfacepackages/*- Database adapters, plugins, and integrationsdocs/- Documentation site (Next.js + Fumadocs)demo/- Demo appse2e/- End-to-end tests (smoke, adapter, integration)
- Formatter: Biome (tabs for code, 2-space for JSON)
- Avoid unsafe typecasts or types like
any - Avoid classes, use functions and objects
- Do not use runtime-specific feature like
Bufferin codebase except test, useUint8Arrayinstead
- Most of the tests use Vitest
- Some tests under
e2e/directory use Playwright - Adapter tests require Docker containers running (
docker compose up -d) - Consider using test helpers like
getTestInstance()frombetter-auth/testfirst - If a test is to prevent regression of a specific numbered GitHub issue,
add a JSDoc
@seecomment with the issue URL above theit()ordescribe():/** * @see https://github.com/better-auth/better-auth/issues/{issue_number} */ it("should handle the previously broken behavior", async () => { // ... });
- Please update the documentation when you make changes to the public API
- Documentation is located in the
docs/directory, built with Next.js + Fumadocs - Content lives in
docs/content/docs/organized by topic (authentication, adapters, concepts, guides, plugins, examples, reference)
- PRs should target the
canarybranch - Commit format:
feat(scope): descriptionorfix(scope): description, following Conventional Commits - Use
docs:for documentation,chore:for non-functional changes
Check postmortem/ directory for lessons learned from past issues.
Unless the user asked for it or you are working on CI, DO NOT COMMIT
- Make sure
pnpm format:check,pnpm lintandpnpm typecheckpass