Cline rules
.clinerules/general.mdCline rules
Quality
86/100
Scores the file, not the repository.Length
1,623 words
9 headings · 7 code blocksRepository
66k
— · pushed 0 days agoLast changed
3 days ago
First indexed 3 days ago.1This file is the secret sauce for working effectively in this codebase. It captures tribal knowledge—the nuanced, non-obvious patterns that make the difference between a quick fix and hours of back-and-forth & human intervention.23**When to add to this file:**4- User had to intervene, correct, or hand-hold5- Multiple back-and-forth attempts were needed to get something working6- You discovered something that required reading many files to understand7- A change touched files you wouldn't have guessed8- Something worked differently than you expected9- User explicitly asks to "add this to CLAUDE.md"1011**Proactively suggest additions** when any of the above happen—don't wait to be asked.1213**What NOT to add:** Stuff you can figure out from reading a few files, obvious patterns, or standard practices. This file should be high-signal, not comprehensive.1415## Miscellaneous16- The whole repo (including `apps/vscode`) uses **bun** for package management and task running. Emit `bun run X` / `bun install` / `bunx <bin>` / `bun file.ts`, never npm/npx. Node remains the *runtime* (VS Code's extension host and the standalone cline-core are Node), so Node-runtime tokens are legitimate and must not be "fixed" to bun — see @.clinerules/bun-and-node.md for the keep-list vs rewrite-list.17- Avoid provider-specific string matching / hardcoded provider branches when fixing provider/config plumbing. Prefer provider metadata, shared catalog/defaults, explicit protocol/client capabilities, or centralized normalization utilities that apply by data shape rather than `providerId === "..."`. If a provider exception seems necessary, stop and explain why instead of adding ad-hoc string matching.18- This is a VS Code extension—check `package.json` for available scripts before trying to verify builds (e.g., `bun run compile`, not `bun run build`).19- When reading a configuration files that users may edit, use `readFileStrippingUtf8Bom`, `readFileSyncStrippingUtf8Bom`, or `stripUtf8Bom` from `@cline/shared/node`. DON'T strip byte order marks of user files handled by tools/passed to models.20- When creating PRs, contributors should not create changelog-entry files. Maintainers handle release versioning and changelog curation during the release process.21- When adding new feature flags, see this PR as a reference https://github.com/cline/cline/pull/756622- Additional instructions about making requests: @.clinerules/network.md2324## Searching the Codebase — Avoiding Build Output2526Several directories contain build output or generated code that produces27noisy or unusable results with `search_files` / `grep`:2829| Directory | What it is | Why it's a problem |30|-----------|-----------|-------------------|31| `out/` | esbuild bundle output | Mirrors `src/` structure as minified JS — every search gets duplicate hits on single-line files |32| `dist/` | Packaged extension | Entire extension bundled into one minified `extension.js` (~1 long line) |33| `dist-standalone/` | Standalone build output | Same minification issue |34| `src/generated/` | Generated protobuf code | Auto-generated from `proto/`; not the source of truth |35| `src/shared/proto/` | Generated proto type defs | Auto-generated from `proto/`; not the source of truth |36| `node_modules/` | Dependencies | Huge, not project source |3738### How to skip build output3940**`search_files`** — Point at `src/` (not the project root) and use `file_pattern`:41```42search_files(path="src/core", regex="myFunction", file_pattern="*.ts")43```44The `file_pattern` parameter is the most effective filter — e.g. `"*.ts"`,45`"*.tsx"`, `"*.proto"`.4647**`grep` directly** — Exclude build dirs and restrict to source extensions:48```bash49grep -rn "myFunction" src/ --include="*.ts" --exclude-dir={out,dist,node_modules,generated}50```5152### When you must search minified files5354Sometimes you need to verify what got bundled (e.g., checking if a change55made it into the build). Minified files are typically one long line, so56normal `grep` shows the entire file as context. Use these approaches:5758- **`grep -oP`** to extract just the match with limited surrounding context:59```bash60 grep -oP '.{0,40}myFunction.{0,40}' dist/extension.js61```62- **`read_file`** on files in `out/src/` — these have source maps and are63 more readable than `dist/extension.js` (which is the fully bundled output).64- **Source maps** — `out/src/*.js.map` and `dist/extension.js.map` can be65 used to trace minified output back to original source locations.6667## gRPC/Protobuf Communication68The extension and webview communicate via gRPC-like protocol over VS Code message passing.6970**Proto files live in `proto/`** (e.g., `proto/cline/task.proto`, `proto/cline/ui.proto`)71- Each feature domain has its own `.proto` file72- For simple data, use shared types in `proto/cline/common.proto` (`StringRequest`, `Empty`, `Int64Request`)73- For complex data, define custom messages in the feature's `.proto` file74- Naming: Services `PascalCaseService`, RPCs `camelCase`, Messages `PascalCase`75- For streaming responses, use `stream` keyword (see `subscribeToAuthCallback` in `account.proto`)7677**Run `bun run protos`** after any proto changes—generates types in:78- `src/shared/proto/` - Shared type definitions79- `src/generated/grpc-js/` - Service implementations80- `src/generated/nice-grpc/` - Promise-based clients81- `src/generated/hosts/` - Generated handlers8283**Adding new enum values** (like a new `ClineSay` type) requires updating conversion mappings in `src/shared/proto-conversions/cline-message.ts`8485**Adding new RPC methods** requires:86- Handler in `src/core/controller/<domain>/`87- Call from webview via generated client: `UiServiceClient.scrollToSettings(StringRequest.create({ value: "browser" }))`8889**Example—the `explain-changes` feature touched:**90- `proto/cline/task.proto` - Added `ExplainChangesRequest` message and `explainChanges` RPC91- `proto/cline/ui.proto` - Added `GENERATE_EXPLANATION = 29` to `ClineSay` enum92- `src/shared/ExtensionMessage.ts` - Added `ClineSayGenerateExplanation` type93- `src/shared/proto-conversions/cline-message.ts` - Added mapping for new say type94- `src/core/controller/task/explainChanges.ts` - Handler implementation95- `webview-ui/src/components/chat/ChatRow.tsx` - UI rendering9697## Adding New Global State Keys98Adding a new key to global state requires updates in multiple places. Missing any step causes silent failures.99100Required steps:1011. Type definition in `src/shared/storage/state-keys.ts` - Add to `GlobalState` or `Settings` interface1022. Add any default value or transform in `src/shared/storage/state-keys.ts` if the key needs one1033. Read and write the value through `StateManager` (`setGlobalState()` / `getGlobalStateKey()`) after initialization104105Persistent state is file-backed through `StateManager`; do not add new runtime reads or writes against VS Code `ExtensionContext` storage. That storage is only a legacy migration source.106107Settings plumbing gotcha: if a key is user-toggleable from settings, wire both controller update paths:108- `src/core/controller/state/updateSettings.ts` for webview `updateSetting(...)`109- `src/core/controller/state/updateSettingsCli.ts` for CLI/ACP settings updates110Missing one path causes a toggle to appear to change in one surface while the backend state stays unchanged.111112Webview toggle gotcha: settings changes must also round-trip back in state payloads.113- Add the field to `UpdateSettingsRequest` in `proto/cline/state.proto` (for webview update requests), then run `bun run protos`114- Include the key in `Controller.getStateToPostToWebview()` (`src/core/controller/index.ts`)115- Ensure `ExtensionState` and webview defaults include the key (`src/shared/ExtensionMessage.ts`, `webview-ui/src/context/ExtensionStateContext.tsx`)116If this round-trip wiring is missing, the backend value can update but the toggle in webview appears stuck or reverts.117118## StateManager Cache vs Direct globalState Access119StateManager uses an in-memory cache populated during `StateManager.initialize()` from file-backed storage. For most state, use `controller.stateManager.setGlobalState()`/`getGlobalStateKey()`.120121Exception: host migration code may read legacy VS Code storage before file-backed storage is initialized.122123Example pattern:124```typescript125// Writing (normal pattern)126controller.stateManager.setGlobalState("myKey", value)127128// Reading after initialization129const value = controller.stateManager.getGlobalStateKey("myKey")130```131132Use `context.globalState` only in VS Code migration code that copies legacy ExtensionContext values into the shared file-backed stores.133134## ChatRow Cancelled/Interrupted States135When a ChatRow displays a loading/in-progress state (spinner), you must handle what happens when the task is cancelled. This is non-obvious because cancellation doesn't update the message content—you have to infer it from context.136137**The pattern:**1381. A message has a `status` field (e.g., `"generating"`, `"complete"`, `"error"`) stored in `message.text` as JSON1392. When cancelled mid-operation, the status stays `"generating"` forever—no one updates it1403. To detect cancellation, check TWO conditions:141 - `!isLast` — if this message is no longer the last message, something else happened after it (interrupted)142 - `lastModifiedMessage?.ask === "resume_task" || "resume_completed_task"` — task was just cancelled and is waiting to resume143144**Example from `generate_explanation`:**145```tsx146const wasCancelled =147 explanationInfo.status === "generating" &&148 (!isLast ||149 lastModifiedMessage?.ask === "resume_task" ||150 lastModifiedMessage?.ask === "resume_completed_task")151const isGenerating = explanationInfo.status === "generating" && !wasCancelled152```153154**Why both checks?**155- `!isLast` catches: cancelled → resumed → did other stuff → this old message is stale156- `lastModifiedMessage?.ask === "resume_task"` catches: just cancelled, hasn't resumed yet, this message is still technically "last"157158**See also:** `BrowserSessionRow.tsx` uses similar pattern with `isLastApiReqInterrupted` and `isLastMessageResume`.159160**Backend side:** When streaming is cancelled, clean up properly (close tabs, clear comments, etc.) by checking `taskState.abort` after the streaming function returns.161162## Debug Harness: clear inherited VSCode/Electron env vars before launching163164The debug harness (`apps/vscode/src/dev/debug-harness/server.ts`) launches a child165VSCode via Playwright's `_electron.launch({ env: { ...process.env, ... } })`. If you166run the harness from a process that was itself spawned by VSCode (e.g. the Cline167extension host, an integrated terminal, or an agent running inside VSCode), the168parent's VSCode/Electron env vars leak into the child and break the launch.169170The fatal one is **`ELECTRON_RUN_AS_NODE=1`**: it makes the child VSCode binary run171as plain Node, so it rejects every VSCode CLI flag. Symptom:172173```174.../Visual Studio Code.app/Contents/MacOS/Code: bad option: --extensionDevelopmentPath=...175Error: Process failed to launch! (Playwright _electron.launch)176```177178This is NOT the macOS Playwright flakiness mentioned in the harness README — it's179env inheritance. Fix: strip the inherited vars before starting the harness:180181```bash182env -u ELECTRON_RUN_AS_NODE -u ELECTRON_NO_ATTACH_CONSOLE \183 -u VSCODE_CLI -u VSCODE_CODE_CACHE_PATH -u VSCODE_CRASH_REPORTER_PROCESS_TYPE \184 -u VSCODE_CWD -u VSCODE_ESM_ENTRYPOINT -u VSCODE_HANDLES_UNCAUGHT_ERRORS \185 -u VSCODE_IPC_HOOK -u VSCODE_NLS_CONFIG -u VSCODE_PID -u VSCODE_L10N_BUNDLE_LOCATION \186 bun src/dev/debug-harness/server.ts --auto-launch --skip-build187```188189Check your own env with `env | grep -iE 'electron|vscode_'` first; `ELECTRON_RUN_AS_NODE=1`190present means you must scrub before launching.191192Other harness notes confirmed in practice:193- The extension host is **ESM** (`VSCODE_ESM_ENTRYPOINT`), so `ext.evaluate` has no194 `require` and module-internal functions aren't reachable as globals. To inspect195 internal builders (e.g. `buildBedrockProviderConfig`), set a breakpoint with196 `ext.set_breakpoint` and read locals via `ext.evaluate` with the paused `callFrameId`197 — don't try to `require()` the bundle.198- `web.evaluate` wraps the expression as a single returned expression; multi-statement199 snippets must be an IIFE `(() => { ...; return x; })()`, otherwise you get200 `SyntaxError: Unexpected token ';'`.201- Webview settings inputs are `vscode-text-field` web components with debounced React202 onChange. Setting `.value` + dispatching events via `web.evaluate` is unreliable for203 some fields; focus the inner shadow `input` then use real keystrokes (`ui.type` +204 `ui.press Tab`, or click the dropdown option) to make the value persist.205206
Also in cline/cline
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| cline/cline.clinerules/bun-and-node.md · 66k | Cline rules | setuptestmonorepodo-not | 74/100 | 3 days ago | |
| cline/cline.clinerules/cline-overview.md · 66k | Cline rules | archtypesapi | 54/100 | 3 days ago | |
| cline/cline.clinerules/debug-harness.md · 66k | Cline rules | buildtesttesting-strategysecurity+1 | 85/100 | 3 days ago | |
| cline/cline.clinerules/sdk-migration.md · 66k | Cline rules | style | 59/100 | 3 days ago | |
| cline/cline.clinerules/storage.md · 66k | Cline rules | stylearchdatabasedo-not | 65/100 | 3 days ago | |
| cline/cline.clinerules/network.md · 66k | Cline rules | styletesting-strategydependencies | 54/100 | 3 days ago | |
| cline/cline.clinerules/protobuf-development.md · 66k | Cline rules | buildstylearchapi+1 | 74/100 | 3 days ago | |
| cline/cline.github/copilot-instructions.md · 66k | Copilot instructions | buildteststyleapi+1 | 75/100 | 3 days ago | |
| cline/clineAGENTS.md · 66k | AGENTS.md | buildtestlint-formatstyle+2 | 83/100 | 3 days ago | |
| cline/clinesdk/AGENTS.md · 66k | AGENTS.md | setupbuildteststyle+5 | 89/100 | 3 days ago | |
| cline/clinesdk/packages/llms/AGENTS.md · 66k | AGENTS.md | no sections | 45/100 | 3 days ago |
Diff against .clinerules/bun-and-node.md Diff against .clinerules/cline-overview.md Diff against .clinerules/debug-harness.md Diff against .clinerules/sdk-migration.md Diff against .clinerules/storage.md Diff against .clinerules/network.md Diff against .clinerules/protobuf-development.md Diff against .github/copilot-instructions.md Diff against AGENTS.md Diff against sdk/AGENTS.md Diff against sdk/packages/llms/AGENTS.md
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| bashdeban/fastmind.clinerules/.project-consistency-keeper2.md · 5 | Cline rules | setupbuildtestlint-format+11 | 100/100 | 3 days ago | |
| JCodesMore/ai-website-cloner-template.clinerules · 31k | Cline rules | buildlint-formatstylearch+3 | 97/100 | 2 days ago | |
| BryaanF/LiantPortfolio.clinerules/project-guidelines.md · 0 | Cline rules | buildstylearchgit+2 | 96/100 | 3 days ago | |
| u9401066/zotero-keeper.clinerules/50-pubmed-project.md · 7 | Cline rules | testlint-formatstylearch+1 | 94/100 | 3 days ago | |
| u9401066/zotero-keepervscode-extension/resources/repo-assets/pubmed-search-mcp/.clinerules/50-pubmed-project.md · 7 | Cline rules | testlint-formatstylearch+1 | 94/100 | 3 days ago | |
| VaillerTeeter/HoshimiNest.clinerules/project-identity.md · 1 | Cline rules | setuparchtypesdo-not | 93/100 | yesterday | |
| HerringtonDarkholme/megarepo.clinerules/02-development.md · 17 | Cline rules | setupbuildteststyle+3 | 92/100 | 3 days ago | |
| blendsdk/codeops-mcp.clinerules/project.md · 0 | Cline rules | buildteststylearch+7 | 91/100 | 3 days ago |
