This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a SvelteKit application (TypeScript) that calculates Social Security retirement benefits for https://ssa.tools/. It emphasizes precision, privacy (client-side only), and educational value. All user data (earnings, birthdates) is ephemeral and client-side only.
npm run dev # Start development server
npm run build # Build for production
npm run test # Run Vitest tests
npm run quality # Run Biome linting + svelte-check (run before finalizing changes)
npm run storybook # Start Storybook for UI component development
npm run fix # Auto-fix linting issues with BiomeTo run a single test file:
npm test src/test/money.test.tsNote: Fuzz tests are excluded by default. Run manually with:
npm test src/test/strategy/fuzz.test.tsThe core logic strictly follows SSA rules:
Money(money.ts): Use for ALL financial calculations. Stores values as integer cents to prevent floating-point errors. Never use raw numbers for currency.MonthDate/MonthDuration(month-time.ts): Use for ALL time calculations. SSA calculations operate on months, not days. JSDateobjects are rarely appropriate for domain logic.Recipient(recipient.ts): Central user model. Uses a pub/sub pattern with privateval_fields and public getters/setters that callpublish_()to notify Svelte subscribers. Implements Svelte store contract.EarningRecord(earning-record.ts): Handles parsing and indexing of SSA earnings history.PrimaryInsuranceAmount(pia.ts): Calculates PIA using bend points and COLA adjustments.constants.ts: Annual SSA constants (bend points, COLA, wage indices, retirement ages). Requires annual updates.
Global application state uses Svelte stores:
context.recipient/context.spouse: The two possible RecipientsrecipientFilingDate/spouseFilingDate: Writable stores for filing dates- Session persistence via
sessionStorage(not server-side)
Filing date optimization logic:
calculations/: Core calculation logic (benefit periods, alternative strategies)data/: Data fetching (Treasury yields)ui/: Display formatting and colors
Standard SvelteKit file-based routing in src/routes/:
/calculator: Main calculator page/strategy: Filing strategy optimizer/guides/*: Educational content pages
- Unit tests in
src/test/using Vitest - Storybook stories in
src/stories/for UI components - Coverage thresholds: 70% lines/functions/statements, 60% branches
data/: SSA life tables (CSV files for mortality calculations)src/lib/pastes/: Sample SSA paste data for testing
- Privacy First: Never persist, log, or transmit user data (earnings, birthdates)
- Use
Money.from()for dollars,Money.fromCents()for cents - Use
MonthDate.initFromYearsMonths()orMonthDuration.initFromYearsMonths()for dates - Use
<RecipientName r={recipient} />component to display names consistently - When updating SSA constants annually, update all related values in
constants.ts
New guides go in /src/routes/guides/{topic}/+page.svelte:
- Use
date --iso-8601forpublishedandmodifiedfields in metadata - Include schema.org structured data for SEO
- Set
schema.imageAltandschema.tagsfor social media cards - Update the index at
/src/routes/guides/+page.svelte