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
NOany types are allowed — ESLint will reject them.
- Prefer classes over interfaces for type definitions
- Use type assertions when you know the type
- Share types from
types.tsfiles - don’t recreate them - Use
import typefor 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.tsvariants - 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-*.jsfiles
Testing Philosophy
NO MOCKS - Use real Hyperscape instances with Playwright. Every feature MUST have tests that:- Start a real Hyperscape server
- Open a real browser with Playwright
- Execute actual gameplay actions
- Verify with screenshots + Three.js scene queries
- Save error logs to
/logs/folder
Architecture Overview
Monorepo Structure
Build Dependency Graph
Packages must build in this order:- physx-js-webidl — PhysX WASM (takes longest, ~5-10 min first time)
- shared — Depends on physx-js-webidl
- All other packages — Depend on shared
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
packages/shared/src/systems/shared/combat/RangedDamageCalculator.tspackages/shared/src/systems/shared/combat/AmmunitionService.tspackages/shared/src/systems/shared/combat/ProjectileService.tspackages/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
packages/shared/src/systems/shared/combat/MagicDamageCalculator.tspackages/shared/src/systems/shared/combat/RuneService.tspackages/shared/src/systems/shared/combat/SpellService.tspackages/client/src/game/panels/SpellsPanel.tsxpackages/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)
packages/server/src/persistence/PersistenceService.tspackages/server/src/database/repositories/EquipmentRepository.tspackages/server/src/database/repositories/BankRepository.tspackages/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
packages/client/src/auth/PrivyAuthManager.tspackages/client/src/types/embeddedConfig.tspackages/client/src/lib/error-reporting.tspackages/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
packages/client/src/game/hud/Minimap.tsxpackages/client/src/game/hud/MinimapOverlayControls.tsxpackages/client/src/ui/core/responsive/ViewportScaler.tsxpackages/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