agentleFS
VersoXBTVersoXBT/claude-initial-setup/.cursor/rules/claude-initial-setup.mdc

claude-initial-setup / rules

Cursor rule4 starsChanged 9 months agoMITView on GitHub

Coding standards, patterns, and best practices from claude-initial-setup skill library

  • Reads credentials

The file

Show its rules and text

We split this claude-initial-setup.mdc into the rules it gives an agent

23 rules. About 0 are common, 19 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈19

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Always create new objects instead of mutating.

    line 11
  2. Very specific:

    No god files (utils.ts with 40 exports)

    line 34
  3. Distinctive:

    No nesting deeper than 4 levels

    line 39
  4. Distinctive:

    Use early returns and guard clauses

    line 40
  5. Distinctive:

    Never force-push during review

    line 69
  6. Distinctive:

    Do NOT mock: pure functions, internal utilities, code under test

    line 90
  7. Distinctive:

    Always restore mocks in afterEach

    line 91
  8. Distinctive:

    Use dependency injection for testability

    line 92
  9. Distinctive:

    Use Zod (TS), Pydantic (Python), struct tags (Go)

    line 99
  10. Distinctive:

    Prefer allowlists over denylists

    line 100
  11. Distinctive:

    Always use parameterized queries or ORMs.

    line 105
  12. Distinctive:

    Use framework escaping (React auto-escapes)

    line 118
  13. Distinctive:

    Never hardcode secrets in source code

    line 124
  14. Very specific:

    Use .env files (never committed) with schema validation at startup

    line 125
  15. Distinctive:

    Use platform secret storage for CI/CD (GitHub Secrets, GitLab Variables)

    line 127
  16. Distinctive:

    Always handle errors explicitly

    line 149
  17. Distinctive:

    Never swallow errors silently

    line 150
  18. Very specific:

    Check response.ok on fetch calls

    line 151
  19. Distinctive:

    Use custom error classes for domain-specific errors

    line 152
  20. Distinctive:

    Follow the loop: REPRODUCE -> HYPOTHESIZE -> TEST -> ISOLATE -> FIX -> VERIFY

    line 157
  21. Distinctive:

    Use git bisect to find breaking commits

    line 159
  22. Distinctive:

    Test one hypothesis at a time

    line 161
  23. Distinctive:

    Avoid N+1 queries (use joins, include, select_related)

    line 166

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
claude-initial-setup.mdc
---
description: Coding standards, patterns, and best practices from claude-initial-setup skill library
globs:
alwaysApply: true
---

# Coding Standards

## Immutability

Always create new objects instead of mutating. Use spread operators, `structuredClone`, or library solutions like immer.

```typescript
// WRONG
user.name = name;
items.push(newItem);

// CORRECT
const updated = { ...user, name };
const added = [...items, newItem];
const removed = items.filter(x => x.id !== id);
const mapped = items.map(x => x.id === id ? { ...x, ...changes } : x);
```

Python: Use `@dataclass(frozen=True)` and `replace()`. Use tuples and frozensets for immutable collections.
Go: Use value receivers and return new structs.

## File Organization

- 200-400 lines per file, 800 max
- Organize by feature/domain, not by type
- Co-locate tests next to source files
- Move to `shared/` only when used by 3+ features
- No god files (`utils.ts` with 40 exports)

## Functions

- Under 50 lines each
- No nesting deeper than 4 levels
- Use early returns and guard clauses

## Naming

- Variables: describe WHAT (`activeUsers`), not HOW (`data`)
- Booleans: `is/has/can/should` prefix (`isActive`, `hasPermission`)
- Functions: verb + noun (`getUserById`, `formatDate`, `validateEmail`)
- Collections: plural nouns (`users`, `orderItems`)
- Constants: `SCREAMING_SNAKE` (`MAX_RETRIES`, `API_BASE_URL`)
- Language casing: camelCase (JS/TS), snake_case (Python), PascalCase (Go exports)

## Git Conventions

### Commits

Format: `<type>(<scope>): <description>`
Types: feat, fix, refactor, docs, test, chore, perf, ci
Rules: imperative mood, lowercase, under 72 chars, no period

### Branches

Format: `<type>/<ticket>-<description>` in kebab-case
Types: feature/, fix/, hotfix/, release/

### Pull Requests

- Under 400 lines of changes
- Include summary, changes, test plan
- Squash merge for features, merge commit for releases
- Never force-push during review

## Testing

### TDD Workflow

1. RED: Write failing test
2. GREEN: Write minimal code to pass
3. REFACTOR: Clean up, keep tests green
4. Target 80%+ coverage

### Test Structure

- Unit tests co-located: `auth.ts` / `auth.test.ts`
- Integration tests: `test/integration/`
- E2E tests: `test/e2e/`
- Factories for dynamic data, fixtures for static data

### Mocking Rules

- Mock at boundaries: external APIs, databases, file I/O
- Do NOT mock: pure functions, internal utilities, code under test
- Always restore mocks in afterEach
- Use dependency injection for testability

## Security

### Input Validation

- Validate all user input at system boundaries
- Use Zod (TS), Pydantic (Python), struct tags (Go)
- Prefer allowlists over denylists
- Parse, then validate into typed domain objects

### SQL Injection

Always use parameterized queries or ORMs. Never concatenate user input into SQL.

```typescript
// WRONG
const q = `SELECT * FROM users WHERE email = '${email}'`;

// CORRECT
const q = 'SELECT * FROM users WHERE email = $1';
await db.query(q, [email]);
```

### XSS Prevention

- Use framework escaping (React auto-escapes)
- Sanitize with DOMPurify for rich HTML
- Set Content Security Policy headers

### Secrets

- Never hardcode secrets in source code
- Use `.env` files (never committed) with schema validation at startup
- `.gitignore`: `.env`, `.env.local`, `*.pem`, `*.key`, `credentials.json`
- Use platform secret storage for CI/CD (GitHub Secrets, GitLab Variables)

### Additional Defenses

- CSRF: anti-CSRF tokens + SameSite cookies
- SSRF: allowlist permitted domains
- IDOR: authorization check on every resource access
- Auth: bcrypt (12+ rounds), rate limiting, secure session cookies
- Headers: helmet middleware (CSP, HSTS, Referrer-Policy)
- Logging: never log passwords, tokens, or PII

## Error Handling

```typescript
try {
  const result = await riskyOperation();
  return result;
} catch (error) {
  throw new Error(`Operation failed for ${id}: ${error.message}`);
}
```

- Always handle errors explicitly
- Never swallow errors silently
- Check `response.ok` on fetch calls
- Use custom error classes for domain-specific errors
- Return consistent API error responses with field-level detail

## Debugging

Follow the loop: REPRODUCE -> HYPOTHESIZE -> TEST -> ISOLATE -> FIX -> VERIFY

- Use `git bisect` to find breaking commits
- Create minimal reproductions
- Test one hypothesis at a time
- Fix root causes, not symptoms

## Performance

- Avoid N+1 queries (use joins, include, select_related)
- Bound queries with LIMIT/pagination
- Cache appropriately: in-memory LRU, Redis, CDN
- Set proper Cache-Control headers
- Lazy load and code split frontend bundles

## Docker

- Multi-stage builds (separate build from runtime)
- Non-root user (`USER appuser`)
- Layer caching (dependencies before source code)
- HEALTHCHECK directives
- Alpine-based images

## Database

- Normalize to 3NF, denormalize selectively for performance
- snake_case for tables, columns, indexes
- Index columns used in WHERE, JOIN, ORDER BY
- Foreign key constraints for integrity
- Zero-downtime migrations (nullable first, backfill, then constrain)

## Code Review Priority

1. Correctness: edge cases, error handling, async errors
2. Security: input validation, authorization, secrets
3. Performance: N+1 queries, unbounded results
4. Maintainability: focused functions, clear naming
5. Testing: coverage, edge cases, behavior over implementation
6. Style: enforce with linters, not review comments

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.