When you open a file in VS Code that is marked as read-only or locked by another process, GitHub Copilot may appear dimmed, unresponsive, or refuse to generate code suggestions. This happens because Copilot needs write access to the file to insert completions, and a read-only state blocks that interaction. The editor itself may also prevent you from typing, which makes Copilot suggestions irrelevant. This article explains why Copilot behaves this way on locked files and provides the exact steps to regain full editing and Copilot functionality.
Key Takeaways: Understanding Copilot on Read-Only Files in VS Code
- VS Code status bar lock icon: Indicates the file is read-only; Copilot completions are disabled until you unlock it.
- File permissions on disk: If the file system attribute is read-only, Copilot cannot write inline suggestions; you must change the attribute first.
- GitHub Copilot extension > Settings > Editor > Read-Only Mode: Controls how Copilot behaves when the editor is in read-only state; set to “warn” or “block” to see clear messages.
Why Copilot Stops Working on Read-Only Files in VS Code
Copilot generates code suggestions that appear as ghost text in the editor. To insert a suggestion, you press Tab or click Accept. This action requires the editor to have write permission on the file. When the file is read-only, VS Code locks the buffer, and the editor disables all insert operations, including Copilot accept events.
The root cause is usually one of three situations:
- The file system attribute is set to read-only on the operating system level, common for configuration files or protected system files.
- Another process, such as a version control tool like Git, has locked the file during a merge conflict or checkout operation.
- The VS Code editor itself has the file open in a read-only mode due to a remote extension or a workspace setting that restricts editing.
In all cases, Copilot detects the locked state and either shows no suggestions or displays a grayed-out icon in the status bar. The extension does not generate completions because it cannot guarantee that the user can accept them.
How Copilot Communicates the Read-Only State
When you open a read-only file, the Copilot icon in the VS Code status bar may show a lock overlay or remain inactive. Hovering over the icon sometimes displays a tooltip like “Copilot is disabled because the file is read-only.” The inline ghost text will not appear at all. This is not a bug; it is the intended design to prevent data loss and inconsistent file states.
Steps to Enable Copilot on a Read-Only File in VS Code
Follow these steps to unlock the file and restore Copilot completions. The method depends on why the file is locked.
Method 1: Unlock the File from the VS Code Status Bar
- Locate the lock icon in the status bar
Look at the bottom-right corner of the VS Code window. If the file is read-only, you will see a small lock icon next to the file encoding or line ending indicator. - Click the lock icon
A dropdown menu appears. Select “Toggle Read-Only” or “Make Writable.” This changes the editor buffer permission for the current session only. - Verify Copilot is active
Start typing in the file. Copilot ghost text should appear within a few seconds. If not, press Ctrl+Space to manually trigger completions.
Method 2: Change File System Permissions on Windows or macOS
- Close the file in VS Code
Save any changes and close the tab to release any locks held by the editor. - Open File Explorer or Finder
Navigate to the folder containing the locked file. - Check the file properties
Right-click the file and select Properties on Windows or Get Info on macOS. Look for the Read-only checkbox. If it is checked, uncheck it and click Apply or OK. - Reopen the file in VS Code
Open the file again. The lock icon should be gone. Copilot will now generate suggestions normally.
Method 3: Resolve a Git Merge Conflict or Locked Branch
- Check the Git status in the terminal
Open the integrated terminal in VS Code with Ctrl+` and rungit status. Look for files marked as “both modified” or “unmerged.” These are locked during a merge conflict. - Resolve the conflict
Open the conflicted file. VS Code shows inline merge conflict markers. Edit the file to resolve the conflict, then save it. - Mark the file as resolved
Rungit add <filename>to stage the resolved file. The lock is released, and Copilot will begin working again.
Method 4: Disable Read-Only Mode in VS Code Settings
- Open VS Code Settings
Press Ctrl+, to open the Settings editor. - Search for read-only
Type “read-only” in the search bar. Look for the settingfiles.readonlyandfiles.readonlyInclude. - Adjust the read-only scope
Iffiles.readonlyis set to “true” or a specific pattern, change it to “false” or remove the pattern that matches your file fromfiles.readonlyInclude. - Reload the window
Press Ctrl+Shift+P, type “Reload Window,” and press Enter. Copilot should now function on previously locked files.
If Copilot Still Has Issues After Unlocking the File
Even after you unlock the file, Copilot may not immediately resume suggestions. Here are the most common reasons and their fixes.
Copilot Ghost Text Appears but You Cannot Accept It
This usually means the editor buffer is still in a read-only state despite the file system being writable. Close the file tab and reopen it using File > Open File. This forces VS Code to re-evaluate the file permissions.
Copilot Icon Shows a Warning Triangle
A yellow warning triangle on the Copilot icon indicates a network or authentication issue, not a file lock. Check your internet connection and sign out and sign back into GitHub Copilot in VS Code. Open the Command Palette with Ctrl+Shift+P, type “GitHub Copilot: Sign Out,” then sign in again.
Copilot Is Disabled in Workspace Settings
Your workspace may have a .vscode/settings.json file that disables Copilot for specific file types. Open that file and look for github.copilot.enable. If it is set to false for the language you are using, change it to true or remove the line.
GitHub Copilot Behavior: Read-Only File vs Unlocked File
| Item | Read-Only File | Unlocked File |
|---|---|---|
| Copilot ghost text | Not displayed | Displayed as gray inline text |
| Copilot status bar icon | Dimmed or shows lock overlay | Active with Copilot logo |
| Ability to accept suggestions | Tab or click does nothing | Tab inserts the suggestion |
| Editor cursor | Cursor is visible but cannot type | Cursor is editable |
| File system attribute | Read-only flag is set | Read-only flag is cleared |
You can now identify why Copilot is not responding on a locked file and apply the correct fix. After unlocking the file, test Copilot by typing a comment or a function signature. If you frequently work with protected files, consider adding an exception in the VS Code settings under files.readonlyExclude to keep them writable while using Copilot. For advanced control, you can bind a keyboard shortcut to toggle read-only mode by editing keybindings.json and adding a command for workbench.action.files.toggleReadonly.