npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

filepath-comments

v1.0.0

Published

Add file path comments to the top of every source file. Great for LLM context, docs, and code reviews.

Readme

Filepath-Comments

A CLI tool that automatically adds file path comments to the top of every source file in your project. Useful for providing context when sharing code with LLMs, in documentation, or during code reviews.

What it does

Running filepath-comments on your project adds a comment with the relative file path as the first line of each supported file:

// src/utils/helpers.js
export function formatDate(date) { ... }
# lib/parser.py
import json
<!-- templates/index.html -->
<!DOCTYPE html>

It automatically detects the correct comment syntax for 30+ file types including JavaScript, TypeScript, Python, Ruby, Go, Rust, HTML, CSS, SQL, and more.

Install

npm install -g filepath-comments

Or run directly with npx:

npx filepath-comments .

Usage

# Add path comments to all files in current directory
filepath-comments

# Target a specific directory
filepath-comments src/

# Preview changes without writing
filepath-comments --dry-run

# Remove previously added path comments
filepath-comments --remove

# Combine flags
filepath-comments src/ --dry-run --remove

Configuration

The script includes a CONFIG object at the top of the file that you can edit before running. Here's the full reference:

Path Format

| Option | Default | Description | | --------------- | -------- | -------------------------------------------------------------------- | | pathSeparator | "unix" | "unix" for forward slashes always, "os" for OS-native separators | | pathPrefix | "" | Prepended to every path (e.g. "@/"// @/src/index.ts) | | pathSuffix | "" | Appended after the path, before the comment closer |

Existing Path Comment Handling

| Option | Default | Description | | ---------------------- | --------- | --------------------------------------------------------------------------------------------------------- | | replaceWrongPath | true | If a file has a path comment but the path is wrong (e.g. file was moved), replace it with the correct one | | overwriteCorrectPath | false | If the path comment is already correct, rewrite it anyway (true) or skip it (false) | | pathDetectionMode | "exact" | How to detect existing path comments — see Detection Modes |

Blank Line Handling

| Option | Default | Description | | ----------------------- | --------- | ---------------------------------------------------------------------------------------------------------- | | blankLineAfterComment | true | Add an empty line after the path comment for visual separation | | leadingBlankLines | "strip" | When a path comment is found after blank lines: "strip" removes the blank lines, "preserve" keeps them |

File Traversal

| Option | Default | Description | | ------------------- | ------- | ---------------------------------------------------------- | | extraSkipDirs | [] | Additional directories to skip (merged with built-in list) | | extraSkipFiles | [] | Additional files to skip (merged with built-in list) | | onlyExtensions | [] | Only process these extensions (empty = all supported) | | excludeExtensions | [] | Skip files with these extensions | | maxFileSize | 0 | Skip files larger than this (in bytes). 0 = no limit |

Output

| Option | Default | Description | | --------- | ------- | --------------------------------------- | | verbose | false | Show individual skipped files in output |

Example Configurations

Prefix all paths with @/:

pathPrefix: "@/",
// Result: // @/src/components/Button.tsx

Only process TypeScript and JavaScript:

onlyExtensions: ["ts", "tsx", "js", "jsx"],

Strict mode — never touch existing comments:

replaceWrongPath: false,
overwriteCorrectPath: false,

Add blank line after path comment:

blankLineAfterComment: true,
// Result:
// // src/utils/helpers.js
//
// export function formatDate(date) { ... }

Detection Modes

The script can detect whether a file already has a path comment, even if it wasn't added by this tool. The pathDetectionMode config controls how this works:

"exact" (default)

Only considers a line a path comment if it exactly matches the format this tool would generate. Any other comment (even one that looks like a path) is left alone.

This mode is useful when:

  • Your files have first-line comments that happen to look like paths but aren't
  • You want to be conservative and only touch comments you're sure came from this tool

"heuristic"

Matches any first-line comment that looks like a relative file path — it checks if the comment content contains / or \ and ends with a known file extension. Also catches root-level files like // index.js.

This mode is useful when:

  • You've moved files and the old path comments are now wrong
  • Path comments were added manually or by a different tool
  • You want the script to clean up inconsistent path comments

Behavior

  • Shebang-aware — if a file starts with #!, the path comment is inserted on line 2.
  • Blank-line tolerant — detects existing path comments even if there are leading blank lines before them. Configurable to strip or preserve those blank lines.
  • Idempotent — running it multiple times won't add duplicate comments.
  • Smart replacement — detects wrong/outdated path comments and replaces them (e.g. after moving a file). Controlled by replaceWrongPath.
  • Non-destructive removal--remove detects and strips path comments using the same detection logic, including through leading blank lines.
  • Auto-skips common directories (node_modules, .git, .next, dist, build, vendor, __pycache__, .idea, .vscode) and files (package-lock.json, yarn.lock, .DS_Store).

Supported Languages

| Comment Style | Extensions | | --------------- | -------------------------------------------------------------------------------------------------------------- | | // path | js, jsx, ts, tsx, java, kt, kts, swift, go, rs, c, cpp, h, hpp, cs, dart, scala, groovy, php, scss, sass, less | | # path | py, rb, sh, bash, zsh, yml, yaml, toml, pl, r | | <!-- path --> | html, htm, xml, svg, vue | | /* path */ | css | | -- path | sql, lua |

License

MIT