codepatterns

A set of TypeScript coding conventions for indentation, names, documentation, and imports. TypeScript is a programming language that adds type checks to JavaScript.

In plain words
What is it for?
Use it when writing or reviewing TypeScript functions, classes, types, exports, and import statements.
Why use it?
It keeps code written by different people consistent and easier to read and maintain.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/srajangpt1/agent-rule-sync/codepatterns
Clone the repo
git clone --depth 1 https://github.com/Srajangpt1/agent-rule-sync

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,380 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01380
Opus 5 $0.00000 $0.00690
Sonnet 5 $0.00000 $0.00276
Haiku 4.5 $0.00000 $0.00138

Measured 2d ago against content hash cdcc0513f9b2, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

codepatterns scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Runs shell commandslowCapability

Expected in a hook, worth knowing in a rule or an instructions file.

- import { spawn } from 'child_process';
.cursor/rules/codepatterns.mdc · 114 lines

How it starts

The opening of the file, as written. The whole thing — 114 lines — stays where its author put it; the contents beside it link to each section on GitHub.

  • Indentation Style: Use 2 spaces for indentation, never tabs. All code files consistently use 2-space indentation.

    • function example() { const value = 1; return value; }
    • if (condition) { doSomething(); }
  • Naming Conventions: Use camelCase for functions, variables, and method names. Use PascalCase for interfaces, types, classes, and exported types. Use descriptive, clear names that indicate purpose.

    • camelCase: generateRules, checkCursorAgent, readExistingRules
    • PascalCase: GenerateRulesConfig, AnalysisResult, CursorAgentCheck, RuleCategory
  • Function Documentation: All exported functions must have JSDoc-style comments with /** */ syntax. Include a brief description of what the function does. Document parameters and return types in TypeScript types, not JSDoc tags.

    • /**
  • Check if cursor-agent is installed and accessible */ export async function checkCursorAgent(): Promise
  • /**
  • Main function to generate cursor rules */ export async function generateRules(config: GenerateRulesConfig = {}): Promise
  • Import Organization: Group imports logically: Node.js built-ins first (if any), then external dependencies, then local imports. Use named imports for clarity. Keep import statements at the top of the file.

    • import { spawn } from 'child_process'; import chalk from 'chalk'; import { Command } from 'commander'; import { generateRules } from './index';
    • import * as fs from 'fs'; import * as path from 'path'; import { AnalysisData, RulesManagerResult } from './types';
  • Export Patterns: Use named exports (export function, export const) rather than default exports. Export types and interfaces explicitly using export interface/export type. Re-export related items from index.ts using export *.

    • export async function generateRules(...) { }
    • export interface GenerateRulesConfig { }
    • export * from './types';
  • File Organization: One major concern per file. Related functions grouped together. Files named with kebab-case for multi-word names (e.g., rules-manager.ts), single words can use camelCase. Each file should have a clear, singular responsibility.

    • src/analyzer.ts - handles cursor-agent integration
    • src/rules-manager.ts - handles file system operations for rules
    • src/cli.ts - handles CLI interface
  • Code Formatting: Use consistent spacing around operators, after commas, and in object literals. Use trailing commas in multiline arrays and objects. Use semicolons at end of statements.

    • const config: GenerateRulesConfig = { outputDir: options.output, verbose: options.verbose, dryRun: options.dryRun, };
    • const files = ['file1', 'file2', 'file3'];
  • String Literals: Use single quotes for string literals throughout the codebase. Use template literals (backticks) for multi-line strings and string interpolation.

    • const message = 'Simple string';
    • const path = path.join(baseDir, '.cursor', 'rules');
    • const prompt = Analyze this entire codebase...;
  • Conditional Logic: Prefer early returns for error conditions. Use explicit boolean checks (=== true, === false) when clarity is needed. Use optional chaining and nullish coalescing where appropriate.

    • if (!agentCheck.installed) { return { success: false, error: '...' }; }
    • const alwaysApply = category.alwaysApply !== undefined ? category.alwaysApply : category.ruleType === 'always' ? true : false;
  • CLI Error Handling: In CLI entry points (cli.ts), use process.exit() with appropriate exit codes (1 for errors, 0 for success) after displaying error messages. Library functions should return error objects instead of exiting.

    • if (!agentCheck.installed) { console.error(chalk.red('Error: ...')); process.exit(1); }
    • // In library functions, return errors instead: return { success: false, error: '...' };
  • Filename Comparison: When comparing filenames for existence checks, use case-insensitive comparison by converting to lowercase. This prevents issues with case-sensitive file systems while maintaining compatibility.

    • const existingFilenames = new Set(existingRules.map((r) => r.filename.toLowerCase()));
    • const existingFile = existingRules.find((r) => r.filename.toLowerCase() === filename.toLowerCase());

Read the full file on GitHub · 114 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 114 lines · 0 tokens per session scan A cdcc0513f9b2

Subscribe to this mod's changes

codepatterns is a cursor rule published in the GitHub repository Srajangpt1/agent-rule-sync (12 stars, last pushed 5mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,380 tokens. A static security scan graded it A with 1 finding (runs shell commands). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.