Development Guide
Building from Source
Prerequisites
- Node.js satisfying
^20.19.0 || >=22.12.0(seepackage.json) - npm (comes with Node.js)
- Bun 1.1.31 or higher (required to run tests)
- Git
Clone and Build
Build Process
The build process uses esbuild to compile TypeScript:- Compiles TypeScript to JavaScript
- Creates standalone executables for each hook in
plugin/scripts/ - Bundles MCP search server to
plugin/scripts/mcp-server.cjs - Bundles worker service to
plugin/scripts/worker-service.cjs - Bundles web viewer UI to
plugin/ui/viewer.html
- Hook executables:
*-hook.js(ESM format) - Setup version-check:
version-check.js(ESM format, hand-written; installs missing plugin dependencies and records the install marker) - Worker service:
worker-service.cjs(CJS format) - MCP server:
mcp-server.cjs(CJS format) - Viewer UI:
viewer.html(self-contained HTML bundle)
Committed release bundles
Marketplace installs run the committed files inplugin/scripts/. When changing
release versions or worker lifecycle code, regenerate and commit the affected
runtime bundles with npm run build. A newer manifest paired with an older
worker bundle can trigger repeated version-mismatch restarts.
CI checks committed bundle versions before rebuilding:
Build Scripts
Development Workflow
1. Make Changes
Edit TypeScript source files insrc/:
2. Build
3. Test
4. Manual Testing
5. Iterate
Repeat steps 1-4 until your changes work as expected.Viewer UI Development
Working with the React Viewer
The web viewer UI is a React application built into a self-contained HTML bundle. Location:src/ui/viewer/
Structure:
Building Viewer UI
Testing Viewer Changes
- Make changes to React components in
src/ui/viewer/ - Build:
npm run build - Sync to installed plugin:
npm run sync-marketplace - Restart worker:
npm run worker:restart - Refresh the worker URL printed by
npm run worker:status
Adding New Viewer Features
Example: Adding a new card type- Create component in
src/ui/viewer/components/cards/YourCard.tsx:
- Import and use in
Feed.tsx:
-
Update types if needed in
src/ui/viewer/types.ts - Rebuild and test
Viewer UI Architecture
Data Flow:- Worker service exposes HTTP + SSE endpoints
- React app fetches initial data via HTTP (paginated)
- SSE connection provides real-time updates
- Custom hooks handle state management and data merging
- Components render cards based on item type
- Infinite Scroll:
usePaginationhook with Intersection Observer - Real-Time Updates:
useSSEhook with auto-reconnection - Deduplication:
merge.tsutilities prevent duplicate items - Settings Persistence:
useSettingshook with localStorage - Theme Support: CSS variables with light/dark/system themes
Adding New Features
Adding a New Hook
- Create hook implementation in
src/hooks/your-hook.ts:
- Add to
plugin/hooks/hooks.json:
- Rebuild:
Modifying Database Schema
- Add migration to
src/services/sqlite/migrations.ts:
- Update types in
src/services/sqlite/types.ts:
- Update database methods in
src/services/sqlite/SessionStore.ts:
- Test migration:
Extending SDK Prompts
- Modify prompts in
src/sdk/prompts.ts:
- Update parser in
src/sdk/parser.ts:
- Test:
Adding MCP Search Tools
- Add tool definition in
src/servers/mcp-server.ts:
- Add search method in
src/services/sqlite/SessionSearch.ts:
- Rebuild and test:
Testing
Testing Philosophy
Claude-mem uses automated tests alongside manual verification in real host sessions. The automated suite runs with Bun.scripts/test-lanes.ts divides discovered tests
into two lanes: the fast lane is the default for npm test; the integration lane
includes browser tests, tests under tests/integration/, and smart-file-read
service tests. Use npm run test:all to run both lanes, and
npm run test:lanes:check to check that the lanes are disjoint and cover every
discovered test file.
Run tests relevant to your change during development. Manual verification can
then check host integration, database state, logs, and worker health in a real
session. It complements automated regression coverage; a manual check does not
establish that the automated suite passes.
Manual Testing Workflow
When developing new features:-
Build and sync:
-
Test in real session:
- Start Claude Code
- Trigger the feature you’re testing
- Verify expected behavior
-
Check database state:
-
Monitor worker logs:
-
Verify queue health (for recovery features):
Testing Tools
Health Checks:Recovery Feature Testing
For manual recovery features specifically:-
Simulate stuck messages:
-
Test recovery:
-
Verify results:
Regression Testing
Before releasing:-
Test all hook triggers:
- SessionStart: Start new Claude Code session
- UserPromptSubmit: Submit a prompt
- PostToolUse: Use a tool like Read
- Summary: Let session complete
- SessionEnd: Close Claude Code
-
Test core features:
- Context injection (recent sessions appear)
- Observation processing (summaries generated)
- MCP search tools (search returns results)
- Viewer UI (loads at the worker URL)
- Manual recovery (stuck messages recovered)
-
Test edge cases:
- Worker crash recovery
- Database locks
- Port conflicts
- Large databases
-
Cross-platform (if applicable):
- macOS
- Linux
- Windows
Code Style
TypeScript Guidelines
- Use TypeScript strict mode
- Define interfaces for all data structures
- Use async/await for asynchronous code
- Handle errors explicitly
- Add JSDoc comments for public APIs
Formatting
- Follow existing code formatting
- Use 2-space indentation
- Use single quotes for strings
- Add trailing commas in objects/arrays
Example
Debugging
Enable Debug Logging
Inspect Database
Trace Observations
Use correlation IDs to trace observations through the pipeline:Debug Hooks
Run hooks manually with test input:Publishing
Releases ship frommain only, and pull requests target main.
Version Bump
Update every manifest that carries the package version:package.jsonplugin/package.json.claude-plugin/marketplace.json.claude-plugin/plugin.jsonplugin/.claude-plugin/plugin.json.codex-plugin/plugin.jsonplugin/.codex-plugin/plugin.jsonopenclaw/openclaw.plugin.json
Build, Tag, and Publish
docs/CHANGELOG.md; it is generated from GitHub releases.
Contributing
Contribution Workflow
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Write tests
- Update documentation
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Pull Request Guidelines
- Clear title: Describe what the PR does
- Description: Explain why the change is needed
- Tests: Include tests for new features
- Documentation: Update docs as needed
- Changelog: Do not hand-edit
docs/CHANGELOG.md; it is generated during release - Commits: Use clear, descriptive commit messages
Code Review Process
- Automated tests must pass
- Code review by maintainer
- Address feedback
- Final approval
- Merge to main
Development Tools
Recommended VSCode Extensions
- TypeScript
- ESLint
- Prettier
- SQLite Viewer
Useful Commands
Troubleshooting Development
Build Fails
-
Clean node_modules:
-
Check Node.js version:
-
Check for syntax errors:
Tests Fail
-
Check database:
-
Check worker status:
-
View logs:
Worker Won’t Start
-
Kill existing process:
-
Check port:
-
Try custom port:
Next Steps
- Architecture Overview - Understand the system
- Configuration - Customize Claude-Mem
- Troubleshooting - Common issues

