node-vfs-polyfill
CLAUDE.md40 starsChanged 10 months agoMITView on GitHub
User-land implementation of the Node.js Virtual File System (VFS) based on nodejs/node#61478. This library allows mounting an in-memory filesystem that intercepts standard fs module calls through monkey-patching. Run a single test: We do not modify vendor/vfs-upstream/. The vendor directory contains code based on the upstream Node.js VFS PR. All extensions are layered on top via src/ and index.js. See UPSTREAM.md for details on our extensions.
- Installs packages
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 20
Run a single test:
- Very specific: line 48
Mount-based Interception: When vfs.mount('/prefix') is called:
- Very specific: line 54
Overlay Mode: When overlay: true, the VFS only handles paths that exist in the virtual filesystem, allowing real files to show through.
- Distinctive: line 56
VFS File Descriptors: Start at 10000 to avoid conflicts with real OS file descriptors.
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
User-land implementation of the Node.js Virtual File System (VFS) based on nodejs/node#61478. This library allows mounting an in-memory filesystem that intercepts standard fs module calls through monkey-patching.
Commands
pnpm install # Install dependencies
pnpm test # Run test suite
pnpm lint # Check linting with Biome
pnpm lint:fix # Fix linting issues
pnpm format # Format code with Biome
pnpm knip # Check for unused exports/dependenciesRun a single test:
node vendor/vfs-upstream/run-tests.js test-vfs-basic.jsArchitecture
Design Principle
We do not modify vendor/vfs-upstream/. The vendor directory contains code based on the upstream Node.js VFS PR. All extensions are layered on top via src/ and index.js. See UPSTREAM.md for details on our extensions.
Core Components
index.js- Entry point that loads vendor classes and layers on extensionsvendor/vfs-upstream/lib/internal/vfs/file_system.js-VirtualFileSystemclass (upstream)vendor/vfs-upstream/lib/internal/vfs/provider.js-VirtualProviderbase class (upstream)vendor/vfs-upstream/lib/internal/vfs/providers/memory.js-MemoryProvider(upstream)vendor/vfs-upstream/lib/internal/vfs/module_hooks.js- fs monkey-patching (upstream)src/write-stream.js-VirtualWriteStreamextension (our addition)src/loader.js- Loads vendor modules with injected primordials/internalBindingsrc/primordials.js- Shims for Node.js internal frozen built-inssrc/internal-binding.js- Shims for native bindings (UV errors, fs constants)src/internal-modules.js- Shims for internal modules (errors, Stats, Dirent)
Key Design Patterns
- Provider Pattern:
VirtualFileSystemdelegates storage operations to aVirtualProvider. TheMemoryProvideris the default, but custom providers (e.g., NFS, WebDAV) can be implemented. - Mount-based Interception: When
vfs.mount('/prefix')is called:- The VFS registers with
module_hooks.js - All
fs.*calls are intercepted - Paths under the mount point are routed to the VFS provider
- Other paths fall through to the real filesystem
- The VFS registers with
- Overlay Mode: When
overlay: true, the VFS only handles paths that exist in the virtual filesystem, allowing real files to show through. - VFS File Descriptors: Start at 10000 to avoid conflicts with real OS file descriptors.
- Layered Extensions: Extensions like
WriteStreamare added via prototype patching inindex.js, keeping vendor code untouched.
File Structure
index.js # Entry point, wires extensions to upstream
src/
loader.js # Module loader for vendor code
primordials.js # Node.js primordials shims
internal-binding.js # Native binding shims
internal-modules.js # Internal module shims (errors, Stats, etc.)
write-stream.js # VirtualWriteStream extension
vendor/vfs-upstream/
lib/internal/vfs/ # Core VFS implementation (upstream)
file_system.js # VirtualFileSystem class
provider.js # VirtualProvider base class
providers/memory.js # MemoryProvider
providers/real.js # RealFSProvider
module_hooks.js # fs module interception
file_handle.js # File handle classes
stats.js # Stats creation
errors.js # Error factories
streams.js # VirtualReadStream
watcher.js # File watching
router.js # Path utilities
fd.js # File descriptor management
test/parallel/ # Tests
run-tests.js # Test runnerDocumentation
UPSTREAM.md- Documents our extensions to upstream (WriteStream, etc.)REVIEW.md- Code review with recommendations
Code Style
- Biome for linting and formatting
- Single quotes, semicolons, ES5 trailing commas
- 2-space indentation
- CommonJS modules (not ESM)
- Requires Node.js >= 22.0.0
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

