Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>locknessNew to Visual Studio Code? Get it now.
lockness

lockness

Alexandre Radicchi

|
5 installs
| (0) | Free
File locking tool to avoid concurrent editing
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

VS Code File Locker

A Visual Studio Code extension that implements file locking to prevent concurrent editing of files by multiple users.

Features

  • Lock files to prevent other users from editing them
  • Visual indicators showing locked/unlocked status in the status bar
  • Read-only mode for locked files
  • Lock expiration mechanism
  • Context menu commands for locking/unlocking files
  • Instance ID tracking to handle multiple VS Code windows per user

How It Works

The extension tracks when files are opened and maintains a lock registry. When a user locks a file:

  1. A lock entry is created with the user's identifier and VS Code instance ID
  2. The status bar updates to show the locked status
  3. Other users trying to edit the file will be notified it's locked
  4. The original user can unlock the file when done editing

Currently, the extension supports two lock storage modes:

  • In-memory locks: Only effective within the same VS Code window
  • File system-based locks: Stored as files in a .locks directory, effective across all instances

Instance ID Tracking

Each VS Code window gets a unique instance ID when the extension is activated. This allows:

  • The same user to have multiple VS Code windows open without conflicting locks
  • Clear identification of which window has locked a file
  • Better handling of lock management when multiple instances are involved

For example, if you lock a file in one window, then try to edit it in another window, you'll see a message indicating that you (not just another user) have locked the file in a different VS Code instance.

Installation

From VS Code Marketplace

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X)
  3. Search for "VS Code File Locker"
  4. Click Install

Manual Installation

  1. Download the .vsix file from the releases page
  2. In VS Code, open Extensions (Ctrl+Shift+X)
  3. Click on the "..." menu at the top right of the Extensions panel
  4. Select "Install from VSIX..."
  5. Choose the downloaded .vsix file

Usage

  1. Open a file you want to edit
  2. Lock the file using:
    • The "Lock Current File" command from the command palette (Ctrl+Shift+P)
    • The context menu option (right-click in editor)
    • The status bar indicator
  3. Edit your file as normal
  4. When finished, unlock the file using similar methods

Lock Management

  • Locks automatically expire after a configurable time period
  • Files can only be unlocked by the same user and VS Code instance that created the lock
  • Administrators can use the "Force Unlock" command for emergency situations
  • The "List All Locked Files" command shows all locks, including which instance created them

Extension Settings

  • fileLocker.lockExpirationTime: Time in seconds before a lock expires automatically (default: 3600)
  • fileLocker.showNotifications: Enable/disable notifications when files are locked or unlocked
  • fileLocker.lockStorageType: Type of lock storage to use (memory or fileSystem)
  • fileLocker.autoLockOnOpen: Automatically lock files when opened (default: true)
  • fileLocker.autoLockOnEdit: Automatically lock files when edited (default: false)
  • fileLocker.autoUnlockOnClose: Automatically unlock files when closed (default: false)
  • fileLocker.showInstanceIds: Show instance IDs in lock information (default: true)
  • fileLocker.fileFilter: Array of glob patterns to determine which files should be lockable (default: ["**/*"])

File Filtering

You can control which files the File Locker extension applies to by configuring the fileLocker.fileFilter setting. This setting accepts an array of glob patterns:

  • Include patterns are specified as regular glob patterns (e.g., "**/*.js")
  • Exclude patterns are specified with a leading ! character (e.g., "!**/node_modules/**")

Examples

// Lock only JavaScript and TypeScript files
"fileLocker.fileFilter": [
  "**/*.js", 
  "**/*.ts"
]

// Lock all files except those in node_modules
"fileLocker.fileFilter": [
  "**/*", 
  "!**/node_modules/**"
]

// Lock only files in the src directory
"fileLocker.fileFilter": [
  "**/src/**"
]

The file filtering happens at the point of locking, so files that don't match the filter:

  • Won't be auto-locked on opening or editing
  • Can't be locked manually
  • Won't show any lock-related UI

This feature is useful for excluding generated files, dependencies, or other files that don't need locking.

Commands

  • File Locker: Lock Current File: Lock the currently active file
  • File Locker: Unlock Current File: Unlock the currently active file
  • File Locker: List All Locked Files: View all files that are currently locked
  • File Locker: Force Unlock File: Administrative command to force unlock a file locked by another user or instance

Shared Lock Storage

To make locks work across different machines and users, you can use the file system storage option:

  1. Set fileLocker.lockStorageType to fileSystem in your workspace settings
  2. Ensure all team members have access to the shared repository
  3. Add .locks/ to your .gitignore file (automatically done by the extension)

Network Share Considerations

For teams using a network share:

  • Ensure all users have read/write access to the .locks directory
  • Lock files are stored as JSON and include the username, hostname, and VS Code instance ID
  • The lock expiration mechanism ensures that "orphaned" locks don't persist

Force Unlocking

In some cases, locks might need to be removed by administrators:

  1. A user may have closed VS Code without unlocking files
  2. A system crash may have prevented proper cleanup
  3. Multiple VS Code instances from the same user might be confusing

For these situations, use the "Force Unlock File" command. This should be used with caution and only when necessary.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This extension is licensed under the MIT License.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft