Skip to content

Commit 5655e2e

Browse files
royangerclaude
andcommitted
fix(shared): reject inherited keys in isClerkAgentRulesSdk and clarify when agent rules are skipped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5b83411 commit 5655e2e

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎.changeset/shared-agent-rules.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'@clerk/shared': minor
33
---
44

5-
Add `@clerk/shared/agentRules`, `@clerk/shared/agentRulesWriter`, and `@clerk/shared/vite` for writing Clerk sections to a project's `AGENTS.md`. Add `isClerkAgentRulesWriteAllowed()` to `@clerk/shared/utils`, which returns `false` in production, in tests, in CI, or when `CLERK_AGENTS_MD=false`.
5+
Add `@clerk/shared/agentRules`, `@clerk/shared/agentRulesWriter`, and `@clerk/shared/vite` for writing Clerk sections to a project's `AGENTS.md`. Add `isClerkAgentRulesWriteAllowed()` to `@clerk/shared/utils`, which returns `false` when `NODE_ENV=production`, in tests, in CI, or when `CLERK_AGENTS_MD=false`. Deployments that don't set `NODE_ENV=production` should set `CLERK_AGENTS_MD=false` to turn writes off.

‎.changeset/write-agents-md-in-dev.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
'@clerk/tanstack-react-start': minor
1212
---
1313

14-
When your app runs in development, Clerk now adds a Clerk section to the project's root `AGENTS.md`, creating the file if needed. It also creates a `CLAUDE.md` that imports `AGENTS.md`, or adds an `@AGENTS.md` import to an existing `CLAUDE.md` that doesn't load it. The section tells the agent to read `node_modules/@clerk/<sdk>/AGENTS.md` before writing auth code and recommends the Clerk plugin (`npx plugins add clerk/skills`). Nothing is written in production, tests, or CI, and setting `CLERK_AGENTS_MD=false` turns it off. The section is written by the Astro and Nuxt dev servers, the Expo config plugin, the first `auth()` call or `clerkMiddleware()` request in Next.js, TanStack React Start's `clerkMiddleware()`, `clerkMiddleware()` in Express, Hono, and React Router, Fastify's `clerkPlugin`, and `createClerkBridge()` in an unpackaged Electron app.
14+
When your app runs in development, Clerk now adds a Clerk section to the project's root `AGENTS.md`, creating the file if needed. It also creates a `CLAUDE.md` that imports `AGENTS.md`, or adds an `@AGENTS.md` import to an existing `CLAUDE.md` that doesn't load it. The section tells the agent to read `node_modules/@clerk/<sdk>/AGENTS.md` before writing auth code and recommends the Clerk plugin (`npx plugins add clerk/skills`). Nothing is written when `NODE_ENV=production`, in tests, or in CI, and setting `CLERK_AGENTS_MD=false` turns it off. If your deployment doesn't set `NODE_ENV=production`, set `CLERK_AGENTS_MD=false` there. The section is written by the Astro and Nuxt dev servers, the Expo config plugin, the first `auth()` call or `clerkMiddleware()` request in Next.js, TanStack React Start's `clerkMiddleware()`, `clerkMiddleware()` in Express, Hono, and React Router, Fastify's `clerkPlugin`, and `createClerkBridge()` in an unpackaged Electron app.

‎packages/shared/src/__tests__/agentRules.spec.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
CLERK_SDK_PLUGIN_END,
55
CLERK_SDK_PLUGIN_START,
66
type FileSystemAdapter,
7+
isClerkAgentRulesSdk,
78
logClerkAgentRulesResult,
89
renderClerkAgentRulesBlock,
910
renderClerkSdkPluginBlock,
@@ -280,6 +281,17 @@ describe('writeClerkAgentRules with an existing CLAUDE.md', () => {
280281
});
281282
});
282283

284+
describe('isClerkAgentRulesSdk', () => {
285+
it('accepts supported SDKs', () => {
286+
expect(isClerkAgentRulesSdk('nextjs')).toBe(true);
287+
});
288+
289+
it('rejects inherited object keys', () => {
290+
expect(isClerkAgentRulesSdk('constructor')).toBe(false);
291+
expect(isClerkAgentRulesSdk('toString')).toBe(false);
292+
});
293+
});
294+
283295
describe('logClerkAgentRulesResult', () => {
284296
it('logs the files that changed', () => {
285297
const log = vi.spyOn(console, 'log').mockImplementation(() => undefined);

‎packages/shared/src/agentRules/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ const appendAgentsImport = (content: string) => {
8181
return content.trim() ? `${content.trimEnd()}${eol}${eol}@AGENTS.md${eol}` : `@AGENTS.md${eol}`;
8282
};
8383

84-
export const isClerkAgentRulesSdk = (value: string): value is ClerkAgentRulesSdk => value in SDK_LABELS;
84+
export const isClerkAgentRulesSdk = (value: string): value is ClerkAgentRulesSdk =>
85+
Object.prototype.hasOwnProperty.call(SDK_LABELS, value);
8586

8687
export const clerkAgentRulesSdks = Object.keys(SDK_LABELS) as ClerkAgentRulesSdk[];
8788

0 commit comments

Comments
 (0)