Load `init.js` files as VS Code workspace context — automatically, on creation or change.
InitJS watches your workspace for files matching configurable glob patterns (default: /.vscode/*init.js) and loads them with require, following the same activate / deactivate lifecycle as VS Code extensions. Perfect for bootstrapping workspace-local tooling, keybindings helpers, or any setup code you want to keep inside your project's .vscode folder.
Features
🚀 Automatic loading — existing matching files are loaded on activation.
👁️ Live reload — when a matching file is created or changed, it is (re)loaded immediately. No window reload needed.
🔄 Proper teardown — before re-requiring a changed file, the previous instance's deactivate() is called and its returned Disposable is disposed.
🎛️ Configurable patterns — match init.js anywhere, only in .vscode, anchored to the root, or with custom * / ** globs.
📁 Multi-root workspace support — patterns apply per workspace folder.
How it works
Each loaded file follows the familiar VS Code extension contract:
// .vscode/init.js
const vscode = require('vscode');
function activate() {
const watcher = vscode.workspace.createFileSystemWatcher(
new vscode.RelativePattern(vscode.workspace.workspaceFolders[0], '**/foo.txt')
);
watcher.onDidChange(() => console.log('foo.txt changed'));
return watcher; // returned Disposable is disposed on reload
}
function deactivate() {
// cleanup logic (optional)
}
module.exports = { activate, deactivate };
Configuration
Setting
Type
Default
Description
initjs.patterns
string[]
["/.vscode/*init.js"]
Glob patterns of files to load when created or changed.
Pattern syntax
A pattern without a directory part (e.g. *.init.js) matches that file name in any directory.
A pattern with a directory part (e.g. .hede/hodo.js) matches that file name recursively inside any matching directory tree, at any depth.
A leading / anchors the pattern to the workspace root (e.g. /.vscode/*init.js matches only the root .vscode folder).
Supports * (single path segment) and ** (crosses path separators), plus ? (single character).
Examples
Setting value
Matches
["/.vscode/*init.js"] (default)
init.js, setup.init.js, … in the root.vscode folder only