CodeLock — Protect Files from AI Edits
Password-protect files and folders from accidental or AI-driven changes in VS Code and Cursor.
Offline-first. No cloud account. No telemetry. Passwords and protected content stay on your machine.
Source: github.com/zama9729/codelock
Features
- Password protect files and folders with per-resource or grouped passwords
- Block and Warn modes for non-password policies
- Unlock sessions (manual, timed, once, until IDE close)
- Locks panel — browse workspace, protect, unlock, refresh
- Advanced Rules — optional YAML glob automation
- Audit history — local log of protection events
- CLI —
protect, unlock, read, check, status, restore-stubs
- Optional encrypt-at-rest — opt-in only; uninstall auto-restores stubs from backups
- AI edit blocking in the IDE for protected resources (where the host exposes edit APIs)
Why CodeLock
AI coding agents can change files quickly — including sensitive areas like auth, payroll, or migrations. CodeLock makes protection explicit: you choose what is locked, how (password / block / warn), and when to unlock.
Installation
From a marketplace
- VS Code: Extensions → search
CodeLock → install codelock.codelock
- Cursor / Open VSX: install
codelock-protect.codelock from Open VSX
From VSIX (local)
cd extension
npm run package:vscode # → codelock-<version>-vscode.vsix
# or
npm run package:openvsx # → codelock-protect-<version>.vsix
Then: Extensions → ⋯ → Install from VSIX…
Requirements
- Python 3.11+ on PATH (or set
codelock.pythonPath)
- VS Code 1.85+ or compatible Cursor build
Getting started
- Open a project folder (File → Open Folder).
- Press Ctrl+Alt+L (Mac: Cmd+Alt+L) or run CodeLock: Open CodeLock.
- On Locks, select files → Protect selected.
- Choose Password or Block, set permissions, confirm.
Default protection does not replace files on disk. Only optional encrypt-at-rest changes on-disk content (and restores on uninstall).
Protecting a file
- Right-click a file → CodeLock → Protect File, or use the Locks panel.
- Pick Password protect or Block completely.
- For password mode: set password, group name, and permissions (View / Edit / Rename / Delete).
- Click Protect.
Protecting a folder
Select a folder in the Locks tree or Explorer → Protect Folder. Child files inherit the rule.
Unlocking
- Unlock in the Locks panel, or CodeLock: Unlock File
- Enter the password for that resource or group
- Default duration is manual (stays unlocked until you lock again)
Locking again
CodeLock: Lock Again or Lock CodeLock clears the active unlock session.
Policies
- Advanced Rules tab — add glob rules (password / block / warn / allow)
- Policy file:
.codelock/policy.yaml (no secrets stored in YAML)
Audit / history
History tab or CodeLock: Show Audit Log — local events only.
Configuration
| Setting |
Description |
codelock.pythonPath |
Python interpreter for the local engine |
codelock.defaultUnlockDuration |
Default unlock duration (manual, 5m, once, …) |
codelock.lockSessionsOnIdeClose |
Clear sessions when the IDE closes |
codelock.diagnosticMode |
Extra engine logging |
CLI
codelock protect src/secrets/api.ts --password '***' --action read --action edit
codelock unlock --path src/secrets/api.ts
codelock read src/secrets/api.ts
codelock check
codelock status
codelock restore-stubs # restore encrypted stubs without password (if backups exist)
codelock restore --password '***' # decrypt all vault entries with password
Encrypt-at-rest (optional, off by default):
codelock protect src/secret.ts --password '***' --encrypt --action read --action edit
Security model
| Layer |
Strength |
| IDE integration |
Blocks save/edit/rename/delete for protected paths in VS Code/Cursor |
| Policy engine |
Central authorize() in local Python — password, block, warn, allow |
| Optional vault |
AES-256-GCM encrypt-at-rest when explicitly enabled |
| Passwords |
Argon2id hashes in local app data — never in policy.yaml |
CodeLock refuses to protect README.md, .gitignore, .env*, extension/, tests/, and other metadata paths.
Limitations
CodeLock cannot guarantee protection against every possible access path:
- Other editors, Git, terminals, or malware outside the IDE integration
- Arbitrary shell
cat/Get-Content on non-encrypted protected files (IDE policy only)
- Kernel-level or admin access to the machine
When encrypt-at-rest is enabled, the on-disk file is a stub; plaintext lives in .codelock/vault/. Uninstalling the extension restores originals from backups (0.7.3+).
Read the repo THREAT_MODEL.md and docs/limitations.md for details.
Troubleshooting
| Issue |
Fix |
| Engine unavailable |
CodeLock: Retry Engine — ensure Python 3.11+ is installed |
| Empty Locks tree |
Open the project folder (not a single file) → Refresh |
| Policy integrity warning |
Settings → Restore trusted policy |
Files show ---CODELOCK-PROTECTED--- |
CodeLock: Restore Encrypted Files or codelock restore-stubs |
| After uninstall, stubs remain (old versions) |
git restore . or codelock restore --password |
Development
git clone https://github.com/zama9729/codelock.git
cd codelock
python -m pytest
npm run compile
Extension development: open extension/ and press F5.
Testing
python -m pytest
npm run lint
npm run compile
Packaging
From extension/:
npm run package:vscode # VS Marketplace → codelock-<ver>-vscode.vsix
npm run package:openvsx # Open VSX → codelock-protect-<ver>.vsix
npm run package:all # both + validate
Publish (credentials via CLI login / env — never commit tokens):
npx @vscode/vsce publish -i codelock-0.7.3-vscode.vsix
npx ovsx publish codelock-protect-0.7.3.vsix -p $OVSX_PAT
License
MIT — see LICENSE.