This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
NodeDaemon is a zero-dependency Node.js process manager similar to PM2. It's built entirely using Node.js built-in modules and provides advanced process management capabilities including clustering, file watching, resource monitoring, and log management.
# Build TypeScript
npm run build # One-time build
npm run build:watch # Watch mode for development
# Run tests (100% pass rate guaranteed)
npm test # Run working tests only
npm run test:working # Same as above
# Development
npm run dev # TypeScript watch mode
# Clean build artifacts
npm run clean
# Direct execution (after build)
npm run start:daemon # Run daemon process
npm run start # Run CLI
# Web UI commands
nodedaemon webui start -p 3000 # Start Web UI on port 3000
nodedaemon webui stop # Stop Web UI
nodedaemon webui status # Check Web UI statusThe codebase follows a modular architecture with clear separation of concerns:
-
CLI Layer (
src/cli/)index.ts: Main CLI entry point - handles all user commandsCommandParser.ts: Parses and validates CLI argumentsIPCClient.ts: Manages communication with daemon via Unix sockets/named pipesFormatter.ts: Formats output for terminal display
-
Daemon Core (
src/daemon/)NodeDaemonCore.ts: Main daemon class - orchestrates all subsystemsindex.ts: Daemon launcher with graceful shutdown handling
-
Process Management (
src/core/)ProcessOrchestrator.ts: Manages child processes, handles fork/spawn/cluster modesFileWatcher.ts: Implements file watching using native fs.watchLogManager.ts: Handles log rotation and compressionStateManager.ts: Persists process state to diskHealthMonitor.ts: Monitors CPU/memory and triggers auto-restartsWebUIServer.ts: HTTP server with zero-dependency WebSocket for live monitoringWebSocketServer.ts: Custom WebSocket implementation without external dependencies
- IPC Communication: Uses platform-specific IPC (Unix sockets on Linux/macOS, named pipes on Windows)
- Event-Driven: Components communicate via EventEmitters
- State Persistence: JSON-based state storage in
~/.nodedaemon/ - Zero Dependencies: All functionality implemented using Node.js built-ins only
The project uses a custom test framework (tests/framework.js) with zero dependencies. Tests are categorized into:
- Unit tests (
tests/unit/) - Integration tests (
tests/integration/) - E2E tests (
tests/e2e/)
The run-working-tests.js script runs only tests that are guaranteed to pass, ensuring 100% success rate.
-
Process Modes:
fork: Uses child_process.fork() for Node.js scriptsspawn: Uses child_process.spawn() for any executablecluster: Uses Node.js cluster module for load balancing
-
Configuration Priority:
- Command line arguments override everything
- Environment files (
.env,.env.local, etc.) are loaded in order - Default values in
utils/constants.ts
-
Resource Monitoring:
- CPU threshold triggers restart if exceeded for duration
- Memory threshold triggers restart if exceeded
- Minimum uptime prevents restart loops
-
Graceful Reload (cluster mode):
- Spawns new workers before killing old ones
- Zero-downtime deployment for HTTP servers
-
Build System:
- Custom bundler (
build.js) creates standalone executables - Inlines all local dependencies
- Generates installer scripts
- Custom bundler (
-
Web UI:
- Zero-dependency HTTP server with WebSocket support
- Real-time process monitoring and control
- Basic authentication support
- Live logs and metrics streaming
- Add command definition to
src/cli/CommandParser.ts - Implement handler in
src/cli/index.ts - Add corresponding daemon method if needed in
src/daemon/NodeDaemonCore.ts
- Create component in
src/core/ - Add interface in
src/types/index.ts - Initialize in
NodeDaemonCoreconstructor - Add tests in appropriate test directory
- Set
NODE_ENV=developmentfor verbose logging - Check logs in
~/.nodedaemon/logs/ - Use
nodedaemon logs <app-name>to view logs - Daemon logs are in
~/.nodedaemon/daemon.log
Always prefix commands with rtk. If RTK has a dedicated filter, it uses it. If not, it passes through unchanged. This means RTK is always safe to use.
Important: Even in command chains with &&, use rtk:
# ❌ Wrong
git add . && git commit -m "msg" && git push
# ✅ Correct
rtk git add . && rtk git commit -m "msg" && rtk git pushrtk cargo build # Cargo build output
rtk cargo check # Cargo check output
rtk cargo clippy # Clippy warnings grouped by file (80%)
rtk tsc # TypeScript errors grouped by file/code (83%)
rtk lint # ESLint/Biome violations grouped (84%)
rtk prettier --check # Files needing format only (70%)
rtk next build # Next.js build with route metrics (87%)rtk cargo test # Cargo test failures only (90%)
rtk vitest run # Vitest failures only (99.5%)
rtk playwright test # Playwright failures only (94%)
rtk test <cmd> # Generic test wrapper - failures onlyrtk git status # Compact status
rtk git log # Compact log (works with all git flags)
rtk git diff # Compact diff (80%)
rtk git show # Compact show (80%)
rtk git add # Ultra-compact confirmations (59%)
rtk git commit # Ultra-compact confirmations (59%)
rtk git push # Ultra-compact confirmations
rtk git pull # Ultra-compact confirmations
rtk git branch # Compact branch list
rtk git fetch # Compact fetch
rtk git stash # Compact stash
rtk git worktree # Compact worktreeNote: Git passthrough works for ALL subcommands, even those not explicitly listed.
rtk gh pr view <num> # Compact PR view (87%)
rtk gh pr checks # Compact PR checks (79%)
rtk gh run list # Compact workflow runs (82%)
rtk gh issue list # Compact issue list (80%)
rtk gh api # Compact API responses (26%)rtk pnpm list # Compact dependency tree (70%)
rtk pnpm outdated # Compact outdated packages (80%)
rtk pnpm install # Compact install output (90%)
rtk npm run <script> # Compact npm script output
rtk npx <cmd> # Compact npx command output
rtk prisma # Prisma without ASCII art (88%)rtk ls <path> # Tree format, compact (65%)
rtk read <file> # Code reading with filtering (60%)
rtk grep <pattern> # Search grouped by file (75%)
rtk find <pattern> # Find grouped by directory (70%)rtk err <cmd> # Filter errors only from any command
rtk log <file> # Deduplicated logs with counts
rtk json <file> # JSON structure without values
rtk deps # Dependency overview
rtk env # Environment variables compact
rtk summary <cmd> # Smart summary of command output
rtk diff # Ultra-compact diffsrtk docker ps # Compact container list
rtk docker images # Compact image list
rtk docker logs <c> # Deduplicated logs
rtk kubectl get # Compact resource list
rtk kubectl logs # Deduplicated pod logsrtk curl <url> # Compact HTTP responses (70%)
rtk wget <url> # Compact download output (65%)rtk gain # View token savings statistics
rtk gain --history # View command history with savings
rtk discover # Analyze Claude Code sessions for missed RTK usage
rtk proxy <cmd> # Run command without filtering (for debugging)
rtk init # Add RTK instructions to CLAUDE.md
rtk init --global # Add RTK to ~/.claude/CLAUDE.mdOverall average: 60-90% token reduction on common development operations.
This project uses DFMT to keep tool output from flooding the context window and to preserve session state across compactions. When working in this project, follow these rules.
Prefer DFMT's MCP tools over native ones:
Every dfmt_* call MUST pass an intent parameter — a short phrase
describing what you need from the output (e.g. "failing tests",
"error message", "imports"). Without intent the tool returns raw
bytes and the token savings are lost.
On DFMT failure, report it to the user (one short line — which call,
what error) and then fall back to the native tool so the session is
not blocked. The ban is on silent fallback — every switch must be
announced. After a fallback, drop a brief dfmt_remember note tagged
gap when practical, so the journal records that a call was bypassed.
If the native tool is also denied (permission rule, sandbox refusal),
stop and ask the user; do not retry blindly.
DFMT tracks tool calls automatically. After substantive decisions or
findings, call dfmt_remember with descriptive tags (decision,
finding, summary) so future sessions can recall the context after
compaction.
Native Bash and Read are acceptable for outputs you know are small
(< 2 KB) and will not be referenced again. For everything else, DFMT
tools are preferred.
