← Systems Manual/Editor & Workspace Safety
Editor & Workspace Safety8 min read

LockManager: Protecting Critical Files from Accidental AI Overwrites

How to lock database configs, sensitive auth routes, and core components from AI modifications during massive refactors.

One of the most frustrating failures in AI coding assistants is 'over-eager refactoring'—when the agent modifies database connection strings, destroys custom API keys, or rewrites stable legacy components while implementing an unrelated UI feature. Unchained Code introduces the LockManager, allowing developers to selectively lock files and folders with cryptographic immutability.

Direct AnswerDirect Answer / AI Executive Summary

Unchained Code's LockManager monitors the file tree. When a file is locked via the UI or .unchainedlock configuration, the system prompt strictly instructs the LLM that the file is read-only. Furthermore, the action-runner runtime intercepts and rejects any write attempts targeting locked paths before touching MemFS.

Step-by-Step Walkthrough & User Guide

1

Select File in File Tree

Right-click any file or folder in the left sidebar explorer.

2

Toggle 'Lock File' Action

Click 'Lock File'. A padlock icon appears next to the filename in the editor and file tree.

3

Automated Prompt & Runtime Gate

The AI is immediately notified that the file is immutable, and the local action runner rejects any write streams.

4

Unlock Anytime for Manual Edits

Click the padlock icon to unlock the file whenever you wish to grant write access again.

💡Pro Tips & Engineering Best Practices

  • •Lock your .env, tsconfig.json, and package.json to prevent unwanted dependency upgrades.
  • •Locked files are persisted in local IndexedDB and survive browser refreshes and branch switches.
  • •You can still manually edit locked files in the code editor while keeping AI write-protection active.

Code & Technical Integration

Terminal & Integration Code
typescript
// Lock Protection Gate in web/app/lib/persistence/lockedFiles.ts
export function isFileLocked(filePath: string, lockedSet: Set<string>): boolean {
  return lockedSet.has(filePath) || lockedSet.has(normalizePath(filePath));
}

Related Engineering Walkthroughs