Skip to content

Commit aa14d86

Browse files
authored
chore(claude): set some sane defaults (#14445)
### Summary Sets up Claude Code configuration for the Payload repository with automatic formatting hooks, permission presets, and improved documentation. ### Changes **1. Added `.claude/hooks/post-edit.sh`** - Post-edit hook that auto-formats files after Edit/Write operations - Runs `sort-package-json` for package.json - Runs `prettier` for yml/json/md/mdx/js/jsx/ts/tsx files - Runs `markdownlint` for markdown files - Runs `eslint --fix` for JavaScript/TypeScript files **2. Added `.claude/settings.json`** - Configures post-edit hook to trigger on Edit/Write tool use - Pre-allows common readonly commands (git, gh, pnpm, web tools) to reduce permission prompts **3. Updated `CLAUDE.md`** - Added missing packages to documentation (kv-redis, R2 storage adapter) - Standardized all pnpm commands to use `pnpm run` prefix to match allowed commands in `.claude/settings.json` - Clarified that Turbo commands should use `pnpm turbo`, not `turbo` directly
1 parent 80d7781 commit aa14d86

File tree

3 files changed

+121
-27
lines changed

3 files changed

+121
-27
lines changed

.claude/hooks/post-edit.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Post-edit hook to format files after creating/editing
4+
# This is the bash equivalent of lint-staged in package.json
5+
6+
# To test this file directly via cli:
7+
# echo '{"tool_input": {"file_path": "path/to/your/file"}}' | .claude/hooks/post-edit.sh
8+
9+
# Read JSON from stdin and extract file path
10+
FILE=$(jq -r '.tool_input.file_path' 2>/dev/null)
11+
12+
if [ -z "$FILE" ] || [ "$FILE" = "null" ]; then
13+
exit 0
14+
fi
15+
16+
# Check if file exists
17+
if [ ! -f "$FILE" ]; then
18+
exit 0
19+
fi
20+
21+
# Format based on file type
22+
case "$FILE" in
23+
*/package.json)
24+
npx sort-package-json "$FILE" 2>/dev/null
25+
;;
26+
*.yml|*.json)
27+
npx prettier --write "$FILE" 2>/dev/null
28+
;;
29+
*.md|*.mdx)
30+
npx prettier --write "$FILE" 2>/dev/null
31+
if command -v markdownlint >/dev/null 2>&1; then
32+
markdownlint -i node_modules "$FILE" 2>/dev/null
33+
fi
34+
;;
35+
*.js|*.jsx|*.ts|*.tsx)
36+
npx prettier --write "$FILE" 2>/dev/null
37+
npx eslint --cache --fix "$FILE" 2>/dev/null
38+
;;
39+
esac
40+
41+
exit 0

.claude/settings.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"hooks": {
3+
"PostToolUse": [
4+
{
5+
"matcher": "Edit|Write",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": ".claude/hooks/post-edit.sh"
10+
}
11+
]
12+
}
13+
]
14+
},
15+
"permissions": {
16+
"allow": [
17+
"Bash(gh issue view:*)",
18+
"Bash(gh pr view:*)",
19+
"Bash(gh release view:*)",
20+
"Bash(gh run list:*)",
21+
"Bash(gh run view:*)",
22+
"Bash(git branch:*)",
23+
"Bash(git describe:*)",
24+
"Bash(git diff:*)",
25+
"Bash(git log:*)",
26+
"Bash(git ls-files:*)",
27+
"Bash(git remote:*)",
28+
"Bash(git rev-parse:*)",
29+
"Bash(git show:*)",
30+
"Bash(git status)",
31+
"Bash(pnpm --version)",
32+
"Bash(pnpm audit:*)",
33+
"Bash(pnpm install)",
34+
"Bash(pnpm list:*)",
35+
"Bash(pnpm run:*)",
36+
"Bash(pnpm turbo:*)",
37+
"Bash(pnpm view:*)",
38+
"Bash(pnpm why:*)",
39+
"Bash(pwd)",
40+
"Bash(which:*)",
41+
"WebFetch(domain:docs.aws.amazon.com)",
42+
"WebFetch(domain:docs.claude.com)",
43+
"WebFetch(domain:github.com)",
44+
"WebFetch(domain:payloadcms.com)",
45+
"WebFetch(domain:pure.md)",
46+
"WebFetch(domain:raw.githubusercontent.com)",
47+
"WebFetch(domain:www.anthropic.com)",
48+
"WebFetch(domain:www.npmjs.com)",
49+
"WebSearch"
50+
]
51+
}
52+
}

CLAUDE.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ Payload is a monorepo structured around Next.js, containing the core CMS platfor
1414
- `packages/next` - Next.js integration layer
1515
- `packages/db-*` - Database adapters (MongoDB, Postgres, SQLite, Vercel Postgres, D1 SQLite)
1616
- `packages/drizzle` - Drizzle ORM integration
17+
- `packages/kv-redis` - Redis key-value store adapter
1718
- `packages/richtext-*` - Rich text editors (Lexical, Slate)
18-
- `packages/storage-*` - Storage adapters (S3, Azure, GCS, Uploadthing, Vercel Blob)
19+
- `packages/storage-*` - Storage adapters (S3, Azure, GCS, Uploadthing, Vercel Blob, R2)
1920
- `packages/email-*` - Email adapters (Nodemailer, Resend)
2021
- `packages/plugin-*` - Additional functionality plugins
2122
- `packages/graphql` - GraphQL API layer
@@ -35,21 +36,28 @@ Payload is a monorepo structured around Next.js, containing the core CMS platfor
3536
- Source files are in `src/`, compiled outputs go to `dist/`
3637
- Monorepo uses pnpm workspaces and Turbo for builds
3738

39+
## Quick Start
40+
41+
1. `pnpm install`
42+
2. `pnpm run build:core`
43+
3. `pnpm run dev` (MongoDB) or `pnpm run dev:postgres`
44+
3845
## Build Commands
3946

40-
- `pnpm install` - Install all dependencies (pnpm required - run `corepack enable` first)
41-
- `pnpm build` or `pnpm build:core` - Build core packages (excludes plugins and storage adapters)
42-
- `pnpm build:all` - Build all packages
43-
- `pnpm build:<directory_name>` - Build specific package (e.g. `pnpm build:db-mongodb`, `pnpm build:ui`)
47+
- `pnpm install` - Install all dependencies
48+
- `pnpm turbo` - All Turbo commands should be run from root with pnpm - not with `turbo` directly
49+
- `pnpm run build` or `pnpm run build:core` - Build core packages (excludes plugins and storage adapters)
50+
- `pnpm run build:all` - Build all packages
51+
- `pnpm run build:<directory_name>` - Build specific package (e.g. `pnpm run build:db-mongodb`, `pnpm run build:ui`)
4452

4553
## Development
4654

4755
### Running Dev Server
4856

49-
- `pnpm dev` - Start dev server with default config (`test/_community/config.ts`)
50-
- `pnpm dev <directory_name>` - Start dev server with specific test config (e.g. `pnpm dev fields` loads `test/fields/config.ts`)
51-
- `pnpm dev:postgres` - Run dev server with Postgres
52-
- `pnpm dev:memorydb` - Run dev server with in-memory MongoDB
57+
- `pnpm run dev` - Start dev server with default config (`test/_community/config.ts`)
58+
- `pnpm run dev <directory_name>` - Start dev server with specific test config (e.g. `pnpm run dev fields` loads `test/fields/config.ts`)
59+
- `pnpm run dev:postgres` - Run dev server with Postgres
60+
- `pnpm run dev:memorydb` - Run dev server with in-memory MongoDB
5361

5462
### Development Environment
5563

@@ -60,19 +68,12 @@ Payload is a monorepo structured around Next.js, containing the core CMS platfor
6068

6169
## Testing
6270

63-
### Running Tests
64-
65-
- `pnpm test` - Run all tests (integration + components + e2e)
66-
- `pnpm test:int` - Run integration tests (MongoDB, recommended for verifying local changes)
67-
- `pnpm test:int <directory_name>` - Run specific integration test suite (e.g. `pnpm test:int fields`)
68-
- `pnpm test:int:postgres` - Run integration tests with Postgres
69-
- `pnpm test:int:sqlite` - Run integration tests with SQLite
70-
- `pnpm test:unit` - Run unit tests
71-
- `pnpm test:e2e` - Run end-to-end tests (Playwright)
72-
- `pnpm test:e2e:headed` - Run e2e tests in headed mode
73-
- `pnpm test:e2e:debug` - Run e2e tests in debug mode
74-
- `pnpm test:components` - Run component tests (Jest)
75-
- `pnpm test:types` - Run type tests (tstyche)
71+
- `pnpm run test` - Run all tests (integration + components + e2e)
72+
- `pnpm run test:int` - Integration tests (MongoDB, recommended)
73+
- `pnpm run test:int <dir>` - Specific test suite (e.g. `fields`)
74+
- `pnpm run test:int:postgres|sqlite` - Integration tests with other databases
75+
- `pnpm run test:e2e` - Playwright tests (add `:headed` or `:debug` suffix)
76+
- `pnpm run test:unit|components|types` - Other test suites
7677

7778
### Test Structure
7879

@@ -86,19 +87,19 @@ test/<feature-name>/
8687
└── payload-types.ts # Generated types
8788
```
8889

89-
Generate types for a test directory: `pnpm dev:generate-types <directory_name>`
90+
Generate types for a test directory: `pnpm run dev:generate-types <directory_name>`
9091

9192
## Linting & Formatting
9293

93-
- `pnpm lint` - Run linter across all packages
94-
- `pnpm lint:fix` - Fix linting issues
94+
- `pnpm run lint` - Run linter across all packages
95+
- `pnpm run lint:fix` - Fix linting issues
9596

9697
## Internationalization
9798

9899
- Translation files are in `packages/translations/src/languages/`
99100
- Add new strings to English locale first, then translate to other languages
100-
- Run `pnpm translateNewKeys` to auto-translate new keys (requires `OPENAI_KEY` in `.env`)
101-
- Lexical translations: `cd packages/richtext-lexical && pnpm translateNewKeys`
101+
- Run `pnpm run translateNewKeys` to auto-translate new keys (requires `OPENAI_KEY` in `.env`)
102+
- Lexical translations: `cd packages/richtext-lexical && pnpm run translateNewKeys`
102103

103104
## Commit & PR Guidelines
104105

0 commit comments

Comments
 (0)