AutoPathComment is a Visual Studio Code extension that automatically inserts a comment at the top of your file with its workspace-relative path whenever you save. The path always lands immediately after any required shebangs or language directives so scripts keep working, while still giving you a quick breadcrumb to the file’s location.
- 
Auto-insertion of file path on Save Whenever you save, AutoPathComment detects the file’s workspace-relative path and inserts it as a top-of-file comment.
 - 
Supports Popular Languages Ships with defaults for common extensions (.js, .ts, .py, .php, .java, .go, .rb, etc.) and uses the correct single-line comment token for each. You can extend or override this map in settings.
 - 
Directive-aware insertion Shebangs, Ruby magic comments (
# frozen_string_literal,# encoding), Pythoncodingdeclarations, and PHP opening tags are detected automatically. The comment is inserted right after that preamble so executables keep their required header. - 
No Duplicate Comments The extension checks the insertion location before writing anything, so repeated saves keep the file tidy.
 
- Visual Studio Code 1.105.0 or higher
 - Node.js (for extension development, if building from source)
 
- 
From a VSIX file (current distribution):
- Download the latest 
autopathcomment-<version>.vsixfrom the Releases tab or build one locally withnpm run package. - In VS Code, press 
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(macOS) and select Extensions: Install from VSIX.... - Select the downloaded 
.vsixfile to install. 
 - Download the latest 
 - 
From Source:
- Clone the repository or download it.
 - Run 
npm install. - Run 
npm run packageorvsce packageto create a.vsix. - Install the 
.vsixin VS Code as above. 
 
- 
Open a file within a folder or workspace in VS Code.
 - 
Edit and Save (
Ctrl+S/Cmd+S).- AutoPathComment will detect the file’s relative path and insert a comment at the top if it isn’t already present.
 
 - 
That’s it! You should now see something like:
# src/utils/parser.py # (rest of your file)
or
// src/components/MyComponent.ts // (rest of your file)
 
You can customize the comment prefix per file extension via Settings:
- Setting: 
autopathcomment.commentSyntaxMap - Keys are file extensions (include the dot), values are single-line comment prefixes.
 
Examples:
- Multi-root Workspaces: The file path is determined relative to the first workspace folder whose filesystem path prefixes the document. Nested or overlapping folders may require custom settings.
 - Binary / Generated Files: The extension does not discriminate between text and non-text files. Exclude generated artifacts via VS Code settings if needed.
 - Comment Syntax: Only single-line comment prefixes are supported. Add a custom mapping in settings if your language uses a different single-line token.
 
- Install dependencies: 
npm install(also configures the localcommit-msghook for Conventional Commits). - Build once: 
npm run compile - Continuous build: 
npm run watch - Run tests (VS Code integration via 
@vscode/test-cli):npm test - Full check (types + lint + tests): 
npm run check 
- Fork and clone the repo.
 - Run 
npm install(sets up commit hooks locally). - Create a new branch for your feature or bugfix.
 - Open a pull request describing your changes.
 
This project is licensed under the MIT License.