Cline rules
.clinerules/general.mdCline rules
Quality
69/100
Scores the file, not the repository.Length
1,617 words
10 headings · 3 code blocksRepository
25
— · pushed 13 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- This is a VS Code extension—check `package.json` for available scripts before trying to verify builds (e.g., `npm run compile`, not `npm run build`).17- When creating PRs, if the change is user-facing and significant enough to warrant a changelog entry, run `npm run changeset` and create a patch changeset. Never create minor or major version bumps. Skip changesets for trivial fixes, internal refactors, or minor UI tweaks that users wouldn't notice.18- When adding new feature flags, see this PR as a reference https://github.com/cline/cline/pull/756619- Additional instructions about making requests: @.clinerules/network.md2021## gRPC/Protobuf Communication22The extension and webview communicate via gRPC-like protocol over VS Code message passing.2324**Proto files live in `proto/`** (e.g., `proto/cline/task.proto`, `proto/cline/ui.proto`)25- Each feature domain has its own `.proto` file26- For simple data, use shared types in `proto/cline/common.proto` (`StringRequest`, `Empty`, `Int64Request`)27- For complex data, define custom messages in the feature's `.proto` file28- Naming: Services `PascalCaseService`, RPCs `camelCase`, Messages `PascalCase`29- For streaming responses, use `stream` keyword (see `subscribeToAuthCallback` in `account.proto`)3031**Run `npm run protos`** after any proto changes—generates types in:32- `src/shared/proto/` - Shared type definitions33- `src/generated/grpc-js/` - Service implementations34- `src/generated/nice-grpc/` - Promise-based clients35- `src/generated/hosts/` - Generated handlers3637**Adding new enum values** (like a new `ClineSay` type) requires updating conversion mappings in `src/shared/proto-conversions/cline-message.ts`3839**Adding new RPC methods** requires:40- Handler in `src/core/controller/<domain>/`41- Call from webview via generated client: `UiServiceClient.scrollToSettings(StringRequest.create({ value: "browser" }))`4243**Example—the `explain-changes` feature touched:**44- `proto/cline/task.proto` - Added `ExplainChangesRequest` message and `explainChanges` RPC45- `proto/cline/ui.proto` - Added `GENERATE_EXPLANATION = 29` to `ClineSay` enum46- `src/shared/ExtensionMessage.ts` - Added `ClineSayGenerateExplanation` type47- `src/shared/proto-conversions/cline-message.ts` - Added mapping for new say type48- `src/core/controller/task/explainChanges.ts` - Handler implementation49- `webview-ui/src/components/chat/ChatRow.tsx` - UI rendering5051## Adding a New API Provider52When adding a new provider (e.g., "openai-codex"), you must update the proto conversion layer in THREE places or the provider will silently reset to Anthropic:53541. `proto/cline/models.proto` - Add to the `ApiProvider` enum (e.g., `OPENAI_CODEX = 40;`)552. `convertApiProviderToProto()` in `src/shared/proto-conversions/models/api-configuration-conversion.ts` - Add case mapping string to proto enum563. `convertProtoToApiProvider()` in the same file - Add case mapping proto enum back to string5758**Why this matters:** Without these, the provider string hits the `default` case and returns `ANTHROPIC`. The webview, provider list, and handler all work fine, but the state silently resets when it round-trips through proto serialization. No error is thrown.5960**Other files to update when adding a provider:**61- `src/shared/api.ts` - Add to `ApiProvider` union type, define models62- `src/shared/providers/providers.json` - Add to provider list for dropdown63- `src/core/api/index.ts` - Register handler in `createHandlerForProvider()`64- `webview-ui/src/components/settings/utils/providerUtils.ts` - Add cases in `getModelsForProvider()` and `normalizeApiConfiguration()`65- `webview-ui/src/utils/validate.ts` - Add validation case66- `webview-ui/src/components/settings/ApiOptions.tsx` - Render provider component6768## Responses API Providers (OpenAI Codex, OpenAI Native)69Providers using OpenAI's Responses API require native tool calling. XML tools don't work with the Responses API.7071**Symptoms of broken native tool calling:**72- Tools get called multiple times (e.g., `ask_followup_question` asks the same question twice)73- Tool arguments get duplicated or malformed74- The model responds but tools aren't recognized7576**Root causes to check:**771. **Provider missing from `isNextGenModelProvider()`** in `src/utils/model-utils.ts`. The native variant matchers (e.g., `native-gpt-5/config.ts`) call this function. If your provider isn't in the list, the matcher returns false and falls back to XML tools.78792. **Model missing `apiFormat: ApiFormat.OPENAI_RESPONSES`** in its model info (`src/shared/api.ts`). This property signals that the model requires native tool calling. The task runner in `src/core/task/index.ts` checks this and forces `enableNativeToolCalls: true` regardless of user settings.8081**When adding a new Responses API provider:**821. Add provider to `isNextGenModelProvider()` list in `src/utils/model-utils.ts`832. Set `apiFormat: ApiFormat.OPENAI_RESPONSES` on all models that use the Responses API843. The variant matcher and task runner will handle the rest automatically8586## Adding Tools to System Prompt87This is tricky—multiple prompt variants and configs. **Always search for existing similar tools first and follow their pattern.** Look at the full chain from prompt definition → variant configs → handler → UI before implementing.88891. **Add to `ClineDefaultTool` enum** in `src/shared/tools.ts`902. **Tool definition** in `src/core/prompts/system-prompt/tools/` (create file like `generate_explanation.ts`)91 - Define variants for each `ModelFamily` (generic, next-gen, xs, etc.)92 - Export variants array (e.g., `export const my_tool_variants = [GENERIC, NATIVE_NEXT_GEN, XS]`)93 - **Fallback behavior**: If a variant isn't defined for a model family, `ClineToolSet.getToolByNameWithFallback()` automatically falls back to GENERIC. So you only need to export `[GENERIC]` unless the tool needs model-specific behavior.943. **Register in `src/core/prompts/system-prompt/tools/init.ts`** - Import and spread into `allToolVariants`954. **Add to variant configs** - Each model family has its own config in `src/core/prompts/system-prompt/variants/*/config.ts`. Add your tool's enum to the `.tools()` list:96 - `generic/config.ts`, `next-gen/config.ts`, `gpt-5/config.ts`, `native-gpt-5/config.ts`, `native-gpt-5-1/config.ts`, `native-next-gen/config.ts`, `gemini-3/config.ts`, `glm/config.ts`, `hermes/config.ts`, `xs/config.ts`97 - **Important**: If you add to a variant's config, make sure the tool spec exports a variant for that ModelFamily (or relies on GENERIC fallback)985. **Create handler** in `src/core/task/tools/handlers/`996. **Wire up in `ToolExecutor.ts`** if needed for execution flow1007. **Add to tool parsing** in `src/core/assistant-message/index.ts` if needed1018. **If tool has UI feedback**: add `ClineSay` enum in proto, update `src/shared/ExtensionMessage.ts`, update `src/shared/proto-conversions/cline-message.ts`, update `webview-ui/src/components/chat/ChatRow.tsx`102103## Modifying System Prompt104**Read these first:** `src/core/prompts/system-prompt/README.md`, `tools/README.md`, `__tests__/README.md`105106System prompt is modular: **components** (reusable sections) + **variants** (model-specific configs) + **templates** (with `{{PLACEHOLDER}}` resolution).107108**Key directories:**109- `components/` - Shared sections: `rules.ts`, `capabilities.ts`, `editing_files.ts`, etc.110- `variants/` - Model-specific: `generic/`, `next-gen/`, `xs/`, `gpt-5/`, `gemini-3/`, `hermes/`, `glm/`, etc.111- `templates/` - Template engine and placeholder definitions112113**Variant tiers (ask user which to modify):**114- **Next-gen** (Claude 4, GPT-5, Gemini 2.5): `next-gen/`, `native-next-gen/`, `native-gpt-5/`, `native-gpt-5-1/`, `gemini-3/`, `gpt-5/`115- **Standard** (default fallback): `generic/`116- **Local/small models**: `xs/`, `hermes/`, `glm/`117118**How overrides work:** Variants can override components via `componentOverrides` in their `config.ts`, or provide a custom template in `template.ts` (e.g., `next-gen/template.ts` exports `rules_template`). If no override, the shared component from `components/` is used.119120**Example: Adding a rule to RULES section**1211. Check if variant overrides rules: look for `rules_template` in `variants/*/template.ts` or `componentOverrides.RULES` in `config.ts`1222. If shared: modify `components/rules.ts`1233. If overridden: modify that variant's template1244. XS variant is special—has heavily condensed inline content in `template.ts`125126**After any changes, regenerate snapshots:**127```bash128UPDATE_SNAPSHOTS=true npm run test:unit129```130Snapshots live in `__tests__/__snapshots__/`. Tests validate across model families and context variations (browser, MCP, focus chain).131132## Modifying Default Slash Commands133Three places need updates:134- `src/core/slash-commands/index.ts` - Command definitions135- `src/core/prompts/commands.ts` - System prompt integration136- `webview-ui/src/utils/slash-commands.ts` - Webview autocomplete137138## Adding New Global State Keys139Adding a new key to global state requires updates in multiple places. Missing any step causes silent failures.140141Required steps:1421. Type definition in `src/shared/storage/state-keys.ts` - Add to `GlobalState` or `Settings` interface1432. Read from globalState in `src/core/storage/utils/state-helpers.ts`:144 - Add `const myKey = context.globalState.get<GlobalStateAndSettings["myKey"]>("myKey")` in `readGlobalStateFromDisk()`145 - Add to the return object: `myKey: myKey ?? defaultValue,`1463. StateManager handles read/write via `setGlobalState()`/`getGlobalStateKey()` after initialization147148Common mistake: Adding only the return value without the `context.globalState.get()` call. This compiles but the value is always `undefined` on load.149150## StateManager Cache vs Direct globalState Access151StateManager uses an in-memory cache populated during `StateManager.initialize(context)` in `common.ts`. For most state, use `controller.stateManager.setGlobalState()`/`getGlobalStateKey()`.152153Exception: State needed immediately at extension startup (before cache is ready)154155When Window A sets state and immediately opens Window B, the new window's StateManager cache is populated from `context.globalState` during initialization. If you need to read state in Window B right at startup (e.g., in `common.ts` during `initialize()`), read directly from `context.globalState.get()` instead of StateManager's cache.156157Example pattern (see `lastShownAnnouncementId` and `worktreeAutoOpenPath`):158```typescript159// Writing (normal pattern)160controller.stateManager.setGlobalState("myKey", value)161162// Reading at startup in common.ts (bypass cache)163const value = context.globalState.get<string>("myKey")164```165166This is only needed for cross-window state read during the brief startup window before StateManager cache is fully usable. Normal state access after initialization should use StateManager.167168## ChatRow Cancelled/Interrupted States169When 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.170171**The pattern:**1721. A message has a `status` field (e.g., `"generating"`, `"complete"`, `"error"`) stored in `message.text` as JSON1732. When cancelled mid-operation, the status stays `"generating"` forever—no one updates it1743. To detect cancellation, check TWO conditions:175 - `!isLast` — if this message is no longer the last message, something else happened after it (interrupted)176 - `lastModifiedMessage?.ask === "resume_task" || "resume_completed_task"` — task was just cancelled and is waiting to resume177178**Example from `generate_explanation`:**179```tsx180const wasCancelled =181 explanationInfo.status === "generating" &&182 (!isLast ||183 lastModifiedMessage?.ask === "resume_task" ||184 lastModifiedMessage?.ask === "resume_completed_task")185const isGenerating = explanationInfo.status === "generating" && !wasCancelled186```187188**Why both checks?**189- `!isLast` catches: cancelled → resumed → did other stuff → this old message is stale190- `lastModifiedMessage?.ask === "resume_task"` catches: just cancelled, hasn't resumed yet, this message is still technically "last"191192**See also:** `BrowserSessionRow.tsx` uses similar pattern with `isLastApiReqInterrupted` and `isLastMessageResume`.193194**Backend side:** When streaming is cancelled, clean up properly (close tabs, clear comments, etc.) by checking `taskState.abort` after the streaming function returns.195
Also in adsumnetworks/Adsum-IoT-Coder
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 |
|---|---|---|---|---|---|
| adsumnetworks/Adsum-IoT-Coder.clinerules/cline-overview.md · 25 | Cline rules | archtypesapi | 54/100 | 3 days ago | |
| adsumnetworks/Adsum-IoT-Coder.clinerules/network.md · 25 | Cline rules | styletesting-strategydependencies | 54/100 | 3 days ago | |
| adsumnetworks/Adsum-IoT-Coder.clinerules/project-memory.md · 25 | Cline rules | setupteststyleui+2 | 71/100 | 3 days ago | |
| adsumnetworks/Adsum-IoT-Coder.clinerules/protobuf-development.md · 25 | Cline rules | buildstylearchapi+1 | 74/100 | 3 days ago |
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 · 6 | 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 · 6 | 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 |
