bestpractices

bestpractices is a cursor rule for Cursor from Srajangpt1/agent-rule-sync. It costs 2,242 tokens per session, scanned B, original, MIT.

A set of coding rules covering security, performance, code reuse, and avoiding duplicated code. It includes guidance for handling secrets, external processes, errors, and time limits.

In plain words
What is it for?
Use it when writing or reviewing code that handles credentials, starts other programs, or performs operations that may take a long time.
Why use it?
It reduces common risks such as exposed API keys, unsafe command execution, hung processes, and repeated code.

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/bestpractices
Clone the repo
git clone --depth 1 https://github.com/Srajangpt1/agent-rule-sync

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for bestpractices

README.md
[![agentmods](https://agentmods.dev/badge/rules/srajangpt1/agent-rule-sync/bestpractices.svg)](https://agentmods.dev/rules/srajangpt1/agent-rule-sync/bestpractices)
Your own site
<a href="https://agentmods.dev/rules/srajangpt1/agent-rule-sync/bestpractices"><img src="https://agentmods.dev/badge/rules/srajangpt1/agent-rule-sync/bestpractices.svg" alt="Measured on agentmods" height="20"></a>
Per session 2,242 This file is loaded in full into every session.
When invoked 2,242 The same file — it is already loaded in full.
Security scan B 2 findings. 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.02242 $0.02242
Opus 5 $0.01121 $0.01121
Sonnet 5 $0.00448 $0.00448
Haiku 4.5 $0.00224 $0.00224

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

Security

Grade B, and why

bestpractices scanned grade B with 2 findings 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 4d 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.

Downloads and executes remote codemediumSupply chain

curl | sh runs whatever the server returns today, which is not necessarily what it returned when this was reviewed.

console.log(chalk.white(' curl https://cursor.com/install -fsS | bash\n'));

Downgraded: this mod is about security review, or the phrase is quoted, so it is likely naming the pattern rather than instructing it.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

console.log(chalk.white(' curl https://cursor.com/install -fsS | bash\n'));
.cursor/rules/bestpractices.mdc · 186 lines

How it starts

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

  • Security - Environment Variables: Never hardcode API keys or sensitive credentials. Always use environment variables for sensitive data (CURSOR_API_KEY). Inherit environment variables when spawning processes. Never pass sensitive data as command-line arguments.

    • env: { ...process.env, // Inherit all environment variables (includes CURSOR_API_KEY) PATH: process.env.PATH || '', }
    • // Security Note: Always use environment variables for API keys. Never pass them as command-line arguments.
  • Security - Process Execution: Use spawn for executing external commands rather than eval or exec with user input. Validate inputs before passing to external processes. Handle process errors and timeouts appropriately.

    • const childProcess = spawn('cursor-agent', args, { stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env }, });
    • const timeoutId = setTimeout(() => { childProcess.kill(); // handle timeout }, timeout);
  • Performance - Timeout Handling: Set reasonable timeouts for long-running operations (default 5 minutes). Always clear timeouts when operations complete. Kill processes that exceed timeout to prevent resource leaks.

    • const timeout = 300000; // 5 minute default timeout
    • const timeoutId = setTimeout(() => { childProcess.kill(); resolve({ success: false, error: Analysis timeout... }); }, timeout);
    • childProcess.on('close', (code) => { clearTimeout(timeoutId); // ... });
  • Performance - File Operations: Use synchronous file operations (readFileSync, writeFileSync) when appropriate for CLI tools. Check file existence before reading. Use recursive directory creation when needed. Normalize paths for comparison operations.

    • if (!fs.existsSync(rulesDir)) { fs.mkdirSync(rulesDir, { recursive: true }); }
    • const normalize = (s: string) => s.trim().replace(/\s+/g, ' '); return normalize(existingContent) !== normalize(newContent);
  • Code Reusability - Helper Functions: Extract reusable logic into helper functions. Create utility functions for common operations (filename generation, content comparison, directory management). Keep functions pure when possible (no side effects).

    • export function generateFilename(categoryName: string): string
    • export function needsUpdate(existingContent: string, newContent: string): boolean
    • export function ensureRulesDirectory(rulesDir: string): void
  • DRY Principle - Data Structures: Define shared data structures in types.ts to avoid duplication. Use consistent result object patterns across functions. Reuse type definitions rather than redefining similar structures.

    • // Define once in types.ts export interface AnalysisResult { ... }
    • // Reuse across modules import { AnalysisResult, RulesManagerResult } from './types';
  • DRY Principle - Conversion Logic: Centralize format conversion logic in single functions. Reuse conversion functions rather than duplicating logic. Create utility functions for repeated transformations.

    • export function convertToMDC(categoryName: string, category: RuleCategory): string { ... }
    • export function parseRawOutput(rawOutput: string): AnalysisData | null { ... }
  • Error Recovery - Fallback Parsing: Provide fallback mechanisms when primary operations fail. Attempt alternative parsing methods when primary method fails. Provide meaningful error messages that guide users toward solutions.

    • // Try to parse raw output as fallback if (analysisResult.rawOutput) { const parsedData = parseRawOutput(analysisResult.rawOutput); if (parsedData) { analysisResult.data = parsedData; analysisResult.success = true; } }
    • const jsonMatch = stdout.match(/{[\s\S]*}/); if (!jsonMatch) { // fallback logic }
  • User Experience - Clear Messaging: Provide clear, actionable error messages. Include installation instructions in error messages when tools are missing. Use color coding in CLI output for better UX. Show progress for long-running operations.

    • console.error(chalk.red('\nError: cursor-agent is not installed or not in PATH')); console.log(chalk.yellow('\nTo install cursor-agent, run:')); console.log(chalk.white(' curl https://cursor.com/install -fsS | bash\n'));
    • console.log(chalk.gray('Analyzing codebase with cursor-agent...')); console.log(chalk.gray('This may take a few minutes...\n'));

Read the full file on GitHub · 186 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. 4d ago First seen · 186 lines · 2,242 tokens per session scan B b133f02241a6

Subscribe to this mod's changes

bestpractices is a cursor rule published in the GitHub repository Srajangpt1/agent-rule-sync (12 stars, last pushed 5mo ago), licensed MIT. It adds 2,242 tokens to every session, about $0.0112 per session on Opus 5. A static security scan graded it B with 2 findings (downloads and executes remote code, makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.