Skip to main content

Claude Development Guide

This guide provides instructions for working with Claude Code on the Hyperscape codebase.
This is a companion to CLAUDE.md in the main repository. See the Hyperscape repository for the complete development guide.

Quick Reference

Essential Commands

Package-Specific Commands


Critical Development Rules

TypeScript Strong Typing

NO any types are allowed — ESLint will reject them.
Rules:
  • Prefer classes over interfaces for type definitions
  • Use type assertions when you know the type
  • Share types from types.ts files - don’t recreate them
  • Use import type for type-only imports
  • Make strong type assumptions based on context

File Management

Don’t create new files unless absolutely necessary.
  • Revise existing files instead of creating _v2.ts variants
  • Delete old files when replacing them
  • Update all imports when moving code
  • Clean up test files immediately after use
  • Don’t create temporary check-*.ts, test-*.mjs, fix-*.js files

Testing Philosophy

NO MOCKS - Use real Hyperscape instances with Playwright. Every feature MUST have tests that:
  1. Start a real Hyperscape server
  2. Open a real browser with Playwright
  3. Execute actual gameplay actions
  4. Verify with screenshots + Three.js scene queries
  5. Save error logs to /logs/ folder

Architecture Overview

Monorepo Structure

Build Dependency Graph

Packages must build in this order:
  1. physx-js-webidl — PhysX WASM (takes longest, ~5-10 min first time)
  2. shared — Depends on physx-js-webidl
  3. All other packages — Depend on shared
The turbo.json configuration handles this automatically.

Recent Features

Ranged Combat (PR #691)

Complete ranged combat system with:
  • Bows and arrows (Bronze → Adamant)
  • Projectile rendering with 3D arrow meshes
  • OSRS-accurate hit delay formulas
  • Ammunition consumption (100% loss rate)
  • Combat styles: Accurate, Rapid, Longrange
Key Files:
  • packages/shared/src/systems/shared/combat/RangedDamageCalculator.ts
  • packages/shared/src/systems/shared/combat/AmmunitionService.ts
  • packages/shared/src/systems/shared/combat/ProjectileService.ts
  • packages/client/src/game/systems/ProjectileRenderer.ts

Magic Combat (PR #691)

Complete magic combat system with:
  • Combat spells (Strike and Bolt tiers)
  • Rune consumption with elemental staff support
  • Autocast spell selection
  • Spell projectile rendering
  • OSRS-accurate magic damage formulas
Key Files:
  • packages/shared/src/systems/shared/combat/MagicDamageCalculator.ts
  • packages/shared/src/systems/shared/combat/RuneService.ts
  • packages/shared/src/systems/shared/combat/SpellService.ts
  • packages/client/src/game/panels/SpellsPanel.tsx
  • packages/shared/src/data/spell-visuals.ts

Persistence Improvements (PR #695)

Robust persistence layer with:
  • Transactional equipment/bank saves
  • Immediate persistence for critical operations
  • Reduced auto-save intervals (30s → 5s)
  • EventBus async handler tracking
  • Write-ahead logging (Phase 2 scaffolding)
Key Files:
  • packages/server/src/persistence/PersistenceService.ts
  • packages/server/src/database/repositories/EquipmentRepository.ts
  • packages/server/src/database/repositories/BankRepository.ts
  • packages/shared/src/systems/shared/infrastructure/EventBus.ts

Security Enhancements (PR #687)

Comprehensive security improvements:
  • URL parameter validation (authToken via postMessage)
  • Configurable auth storage (localStorage/sessionStorage/memory)
  • CSP violation monitoring
  • Timestamp validation for replay attack prevention
  • Type guards for event payloads
Key Files:
  • packages/client/src/auth/PrivyAuthManager.ts
  • packages/client/src/types/embeddedConfig.ts
  • packages/client/src/lib/error-reporting.ts
  • packages/server/src/systems/ServerNetwork/services/InputValidation.ts

UI/UX Improvements (PR #687)

Major UI enhancements:
  • Minimap overhaul with independent width/height resizing
  • Cached projection matrix for pip synchronization
  • Extracted overlay controls (compass, teleport, stamina)
  • Viewport scaling system with design resolution
  • Combat panel 1×3 row layout for better mobile UX
Key Files:
  • packages/client/src/game/hud/Minimap.tsx
  • packages/client/src/game/hud/MinimapOverlayControls.tsx
  • packages/client/src/ui/core/responsive/ViewportScaler.tsx
  • packages/client/src/game/interface/useViewportResize.ts

Port Allocation


Common Patterns

Getting Systems

Entity Queries

Event Handling


Troubleshooting

Build Issues

PhysX Build Fails

PhysX is pre-built and committed. If it needs rebuilding:

Port Conflicts

Tests Failing

  • Ensure server is not running before tests
  • Check /logs/ folder for error details
  • Tests spawn their own Hyperscape instances
  • Visual tests require headless browser support