Skip to content

Commit b76f661

Browse files
mournergithub-actions[bot]
authored andcommitted
Improve CLAUDE.md system prompt
GitOrigin-RevId: 5220de2012476d0958fce8a2b09d91fa7fd56f66
1 parent 9395ae7 commit b76f661

1 file changed

Lines changed: 38 additions & 71 deletions

File tree

CLAUDE.md

Lines changed: 38 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,80 @@
11
# CLAUDE.md
22

3-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4-
53
## Project Overview
64

75
Mapbox GL JS is a JavaScript library for interactive, customizable vector maps on the web. It uses WebGL to render vector tiles that conform to the Mapbox Vector Tile Specification.
86

97
## Workflow
10-
- Make changes as concise as possible, ensure they are minimal and fully justified
11-
- Read and understand relevant files before proposing code edits. If the user references a specific file/path, inspect it before explaining or proposing fixes.
12-
- Understand WHY code exists before changing it. GL JS handles browser quirks, performance hacks, and WebGL state subtleties. Non-obvious patterns often exist for a reason—check git blame when in doubt.
13-
- Avoid over-engineering. Only make changes that are directly requested or clearly necessary.
14-
- Don't add features, refactor code, or make "improvements" beyond what was asked
15-
- Don't create helpers or abstractions until you see repetition
16-
- Straightforward repetition beats unclear abstraction
8+
- Keep changes minimal and fully justified
9+
- Read relevant files before proposing edits; always inspect a referenced file before explaining or fixing it
10+
- Understand WHY code exists before changing it — GL JS has many browser quirks, performance hacks, and WebGL subtleties; check git blame when in doubt
11+
- Avoid over-engineering: don't add features, refactor, or "improve" beyond what was asked; no abstractions or helpers until you see repetition, and only if cleaner than the duplication
1712
- Always run `npm run tsc` and `npm run lint` when you're done making a series of code changes
18-
- Run `npm run codegen` if you modify style properties or the style specification (regenerates style code, struct arrays, and TypeScript types)
13+
- Run `npm run codegen` if you modify style properties or the style specification
1914
- Run `npm run test-typings` after modifying public API types or the style specification
2015
- Prefer running single tests, and avoid running the whole test suite, for performance
2116
- Never add any dependencies unless explicitly requested
17+
- Never use grep or find to look up symbols, types, or references — use LSP (`goToDefinition`, `findReferences`, `hover`, `documentSymbol`, `incomingCalls`, `outgoingCalls`) instead; fall back to grep only if LSP returns an error. Never use `workspaceSymbol` — it dumps the entire codebase (~43K symbols) and is never worth the token cost.
2218

2319
## Essential Commands
2420

2521
### Development
26-
```bash
27-
# Start development server with live reload
28-
npm run start
2922

30-
# Build development version (ESM)
23+
```bash
24+
npm start
3125
npm run build-esm-dev
32-
33-
# Build production bundles
34-
npm run build-esm-prod # Minified ESM production build
35-
npm run build-prod # Minified UMD production build
36-
npm run build-css # Build CSS file
37-
38-
# Generate code (style code, struct arrays, and TypeScript types)
26+
npm run build-esm-prod
27+
npm run build-prod # UMD build
28+
npm run build-css
3929
npm run codegen
4030
```
4131

4232
### Testing
43-
```bash
44-
# Test TypeScript definitions
45-
npm run test-typings
4633

47-
# Run unit tests
34+
```bash
4835
npm run test-unit
36+
npm run test-unit -- test/unit/style-spec/spec.test.ts -t 'Style#addImage'
4937

50-
# Run unit tests for specific file
51-
npm run test-unit -- test/unit/style-spec/spec.test.ts
52-
53-
# Run specific test inside a file (use -t with test name pattern)
54-
npm run test-unit -- test/unit/style/style.test.ts -t 'Style#addImage'
55-
56-
# Run render tests with pattern matching (matches test path segments)
5738
npm run test-render -- -t "background-color"
58-
5939
# Regenerate expected.png baselines (inspect diffs before committing!)
6040
UPDATE=1 npm run test-render -- -t "<pattern>"
41+
42+
npm run test-typings
6143
```
6244

6345
Render tests:
64-
- Test name = folder path under `test/integration/render-tests/` (e.g. `circle-radius/literal`). `-t` is Vitest's substring pattern, so `-t "circle"` also hits `circle-color`, `circle-blur`, etc. — add a slash to narrow: `-t "circle-radius/"`
46+
- Test name = folder path under `test/integration/render-tests/` (e.g. `circle-radius/literal`). `-t` matches substrings — use a trailing slash to narrow: `-t "circle-radius/"` not `-t "circle"` (also hits `circle-color`, `circle-blur`, etc.)
6547
- Always use `npm run test-render`, not `npx vitest` — the `pretest` hook rebuilds `dist/mapbox-gl-dev.js` and pmtiles
6648
- Inspect diffs: `open test/integration/render-tests/render-tests.html`
6749
- Platform-specific failures → `test/ignores/<platform>.js` (prefer `todo` over `skip`, link the issue)
6850

6951
### Code Quality
52+
7053
```bash
71-
# Type checking
7254
npm run tsc
73-
74-
# Run ESLint
7555
npm run lint
76-
77-
# Run CSS linter
7856
npm run lint-css
7957
```
8058

8159
## Architecture Overview
8260

83-
For detailed architecture documentation including Map subsystems, SourceCache, Transform, and Controls, see [@ARCHITECTURE.md](./ARCHITECTURE.md).
84-
85-
### Main Thread / Worker Split
86-
87-
Mapbox GL JS uses WebWorkers to parse vector tiles off the main thread:
61+
### Rendering Pipeline
8862

89-
1. **Main Thread**: Handles rendering, user interactions, and map state
90-
2. **Worker Threads**: Parse vector tiles, perform layout operations, and prepare render-ready data
63+
Tile parsing and layout run in Web Workers; rendering runs on the main thread.
9164

92-
### Rendering Pipeline
65+
1. **Tile Parsing & Layout** (Worker)
66+
- `WorkerTile#parse()` decodes features and creates `Bucket` instances per style layer family
67+
- Each `Bucket` holds vertex/element arrays ready for WebGL upload
68+
- `ProgramConfiguration` maps style properties to shader attributes/uniforms
69+
- Feature geometries are indexed in `FeatureIndex` for `queryRenderedFeatures` / `querySourceFeatures`
9370

94-
1. **Tile Fetching & Parsing** (Worker)
95-
- Vector tiles are fetched and deserialized from PBF format
96-
- Features are transformed into render-ready WebGL buffers
97-
- Feature geometries are indexed for spatial queries
71+
2. **Transfer** — parsed bucket data is serialized and sent to the main thread via `src/util/web_worker_transfer.ts`
9872

99-
2. **Layout Process** (Worker)
100-
- `WorkerTile#parse()` creates `Bucket` instances for style layer families
101-
- Each `Bucket` holds vertex and element array data for WebGL rendering
102-
- `ProgramConfiguration` handles shader attribute/uniform configuration
73+
3. **Symbol Placement** (Main Thread) — symbols run cross-tile collision detection after worker parsing
10374

104-
3. **WebGL Rendering** (Main Thread)
105-
- Rendering happens layer-by-layer in `Painter#render()`, `Painter.renderPass` tracks the current render phase
106-
- Layer-specific `draw*()` methods in `src/render/draw_*.ts`
107-
- Shader programs are compiled and cached by `Painter`
75+
4. **WebGL Rendering** (Main Thread)
76+
- `Painter#render()` iterates layers by render pass (`Painter.renderPass`: offscreen → opaque → translucent)
77+
- Layer-specific `draw*()` functions in `src/render/draw_*.ts`
10878

10979
### Key Components
11080

@@ -117,7 +87,7 @@ Mapbox GL JS uses WebWorkers to parse vector tiles off the main thread:
11787
## Project Structure
11888

11989
```
120-
3d-style/ # 3D building and model rendering
90+
3d-style/ # 3D building and model rendering (mirrors src structure)
12191
12292
src/
12393
├── data/ # Data structures for tiles and rendering
@@ -137,15 +107,14 @@ test/
137107
├── unit/ # Unit tests (Vitest)
138108
├── integration/ # Integration and render tests
139109
└── build/ # Build-related tests
110+
111+
debug/ # Debug pages served by `npm start`
140112
```
141113

142114
## Code Style
143115

144-
- ES6+ features are used throughout
145-
- Prefer immutable data structures
146116
- Prefer named exports over default exports
147117
- Modules export classes or functions (no namespace objects)
148-
- JSDoc comments for all public APIs
149118
- Don't use `!.` for non-null assertions (hides potential null issues)
150119
- Don't use `?.` or `??` operators (hides null handling, harder to debug)
151120
- Use `assert` for invariants
@@ -156,38 +125,36 @@ test/
156125

157126
## TypeScript
158127

159-
- The project has TypeScript configured with `strict: false`, but write all TypeScript code as if strict mode is enabled
160-
- This means: always handle `null`/`undefined` cases, use proper type annotations, avoid `any` types, and ensure type safety
128+
- Configured with `strict: false`, but write code as if strict — no `any`, handle all `null`/`undefined`, use proper type annotations
161129
- Prefer explicit return types over `// @ts-expect-error` suppressions for functions that may not return a value
162130
- Prefer literal unions over boolean flags; allows future extension without breaking changes
163131

164132
## Testing Guidelines
165133

166-
- Tests use Vitest framework with Playwright as the browser provider
167-
- Install Playwright browsers: `npx playwright install chromium`
134+
### Integration Tests
135+
168136
- Any PR that changes rendering behavior (shader changes, draw function logic, bucket data changes) must include a render test in `test/integration/render-tests/`
169137
- For query behavior changes, add corresponding query tests covering all affected layer types
170138
- Render tests for bug fixes must fail without the fix; a tolerance loose enough to pass either way is useless
171139
- Every render test `style.json` must include a `_comment` field explaining what it checks; drop unused intermediate `wait` steps
172140
- Don't inflate render test tolerance to make a failing test pass — investigate the root cause
173141
- Size render test expected images to the minimum needed (e.g., 32×64, not 128×128)
174142

175-
### Writing Unit Tests
143+
### Unit Tests
176144

145+
- Use Vitest conventions
177146
- No shared variables between test cases
178147
- Don't mock internal domain objects (Style, Map, Transform, Dispatcher)
179148
- One return value or side effect per test - pull shared logic into functions
180149
- Only test return values and global side effects - not internal behavior or method calls
181150
- No network requests - use `mockFetch` from `test/util/network.ts` if needed
182-
- Use clear input space partitioning - look for edge cases
183151

184152
## Documentation Conventions
185153

186154
- All public API must have JSDoc comments; private items tagged with `@private`
187155
- Use markdown in JSDoc; surround code identifiers with \`backticks\`
188156
- Class descriptions: describe what the class/instances *are* (e.g., "A layer that...")
189157
- Function descriptions: start with third-person verb (e.g., "Sets...", "Returns...")
190-
- For functions returning values, start with "Returns..."
191158
- Event descriptions: start with "Fired when..."
192159
- Style-spec `doc` fields in `v8.json` render verbatim in the public API reference — use unambiguous language, avoid internal terms, and don't reference implementation details
193160
- When adding a new property to `v8.json`, populate the `sdk-support` table and set `experimental: true` until release version is confirmed
@@ -197,7 +164,7 @@ test/
197164
- Custom `#pragma mapbox` directives in shaders expand to uniforms or attributes
198165
- Shader programs are dynamically generated based on style properties
199166
- Data-driven styling creates paint vertex arrays at layout time
200-
- See [@src/shaders/README.md](src/shaders/README.md) for shader documentation
167+
- See [src/shaders/README.md](src/shaders/README.md) for shader documentation
201168
- Use named `#define` constants for integer mode values in shaders — never bare magic numbers like `if (u_blend_mode == 1)`
202169
- Use `#if defined(A) && defined(B)` for compound shader conditionals (not `#ifdef`); required for the Metal preprocessing pipeline
203170

0 commit comments

Comments
 (0)