Skip to main content

path-comment-hook

    /·\
   /│·│\    ┌─┐┌─┐┬ ┬
  / │·│ \   ├─┘│  ├─┤
 /  │·│  >  ┴  └─┘┴ ┴
/___│·│___\ path-comment-hook

Python 3.8+ PyPI version License: MIT Pre-commit CI Documentation Coverage

Automatically add file path headers to your source code for better navigation and context.

Never lose track of where you are in large codebases. This pre-commit hook automatically adds file path comments to the top of your source files, making code navigation effortless.

Use pch for quick access - convenient shorthand for all operations.

Documentation • Quick Start • Configuration • API Reference

What It Does

Transform your codebase with automatic path headers that provide instant context:

Before After
python<br/>def calculate_tax(amount, rate):<br/> return amount * rate<br/> python<br/># src/utils/tax_calculator.py<br/><br/>def calculate_tax(amount, rate):<br/> return amount * rate<br/>

Key Benefits:

  • Enhanced Navigation - Know exactly where you are in your codebase
  • Better Code Reviews - Reviewers can quickly identify file locations
  • Improved Search - Context-aware code snippets
  • Self-Documenting - Built-in file references
  • Fast Performance - Parallel processing for large projects

Quick Start

1. Install via pip

pip install path-comment-hook

2. Try it out instantly

# Using the convenient shorthand
pch your_file.py

# Or the full command name
path-comment-hook your_file.py

3. Add to pre-commit

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/Shorzinator/path-comment-hook
    rev: v0.1.0  # Use the latest version
    hooks:
      - id: path-comment

4. Install and run

pre-commit install
pre-commit run path-comment --all-files

That's it! Your files now have path headers for better navigation.

Use pch for quick access to all features!

Supported Languages

Works with 10+ programming languages out of the box:

Language Extensions Comment Style Example
Python .py, .pyx # # src/models/user.py
JavaScript .js // // src/components/Button.js
TypeScript .ts, .tsx // // src/types/api.ts
C/C++ .c, .cpp, .h // // src/core/engine.cpp
Shell .sh, .bash # # scripts/deploy.sh
YAML .yml, .yaml # # config/database.yml
TOML .toml # # pyproject.toml
Makefile Makefile # # Makefile

Smart Detection: Automatically handles shebangs, encoding, and file types using the identify library.

Advanced Features

Performance Optimized

  • Parallel Processing - Utilizes all CPU cores
  • Smart Caching - Avoids unnecessary modifications
  • Memory Efficient - Handles large files safely

Safe & Reliable

  • Atomic Operations - Safe file modifications
  • Encoding Preservation - Maintains UTF-8, Latin-1, etc.
  • Line Ending Preservation - Keeps LF/CRLF intact
  • Comprehensive Testing - 152 tests with 69% coverage

Rich CLI Experience

  • Progress Bars - Visual feedback for large operations
  • Colored Output - Easy-to-read status messages
  • Detailed Reporting - Comprehensive summaries
  • Multiple Modes - Check, fix, and delete operations
  • Convenient Shorthand - Use pch instead of path-comment-hook

Real-World Examples

Django Web Application

# apps/users/models.py

from django.contrib.auth.models import AbstractUser
from django.db import models

class CustomUser(AbstractUser):
    email = models.EmailField(unique=True)
    first_name = models.CharField(max_length=30)

React Component

// src/components/LoginForm.jsx

import React, { useState } from 'react';
import { validateEmail } from '../utils/validation';

export function LoginForm({ onSubmit }) {
    const [email, setEmail] = useState('');
    // Component logic...
}

API Configuration

# config/api.yml

environment: production
database:
  host: localhost
  port: 5432

Configuration

Customize behavior in your pyproject.toml:

[tool.path-comment]
exclude_globs = [
    "*.md",
    "tests/fixtures/**",
    "node_modules/**",
    "build/**"
]

Popular configurations:

CLI Usage

The tool provides both full and shorthand commands for convenience:

# Using full command name
path-comment-hook src/main.py src/utils.py
path-comment-hook --all
path-comment-hook --check --all
path-comment-hook --delete --all
path-comment-hook show-config

# Using convenient shorthand (pch)
pch src/main.py src/utils.py
pch --all
pch --check --all
pch --delete --all
pch show-config

Common workflows:

# Quick project-wide update
pch --all

# Check what would change (dry run)
pch --check --all

# Remove all path headers
pch delete --all

# Process specific file types
pch src/**/*.py tests/**/*.py

# Show current configuration
pch show-config

# View help
pch --help

All options:

pch --help  # or path-comment-hook --help

See the CLI Usage Guide for complete details.

Quality & Testing

  • 152 Test Cases - Comprehensive test coverage
  • Real-time Coverage - Monitored via Codecov integration (69% current)
  • Type Safe - Full type hints with mypy
  • Linted & Formatted - Ruff for code quality
  • Cross-Platform CI - Ubuntu, Windows, macOS testing
  • Professional Standards - Enterprise-grade code quality
# Run tests locally
make test
make test-cov  # With coverage report

Documentation

Complete documentation available at: https://shorzinator.github.io/path-comment-hook

Contributing

We welcome contributions! Check out our Development Guide to get started.

Quick setup:

git clone https://github.com/Shorzinator/path-comment-hook.git
cd path-comment-hook
poetry install
make test

# Try the tool locally with shorthand
pch --help
pch examples/basic_usage.py

Integration Examples

GitHub Actions

- name: Check path headers
  run: pch --check --all

GitLab CI

check-headers:
  script: pch --check --all

Docker

RUN pip install path-comment-hook && \
    pch --all

See CI/CD Integration for more examples.

Requirements

  • Python 3.8+ - Modern Python support
  • Cross-platform - Works on Linux, macOS, and Windows
  • Minimal dependencies - Only essential packages

Troubleshooting

Common issues:

License

MIT License - see LICENSE file for details.

Why Choose path-comment-hook?

Production Ready - Used in real projects with comprehensive testing Zero Configuration - Works immediately with sensible defaults Language Agnostic - Supports 10+ programming languages Performance Focused - Parallel processing for large codebases Developer Friendly - Rich CLI with progress bars and colored output Well Documented - Comprehensive guides and examples Actively Maintained - Regular updates and community support Easy Integration - Works with existing tools and workflows

Star us on GitHub • Read the docs • Report issues

Made with care for developers who value code organization and navigation.

Metadata

Release files for path-comment-hook 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for path-comment-hook 0.1.0
File Size Uploaded
path_comment_hook-0.1.0.tar.gz 24.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for path-comment-hook 0.1.0
File Interpreter ABI Platform
path_comment_hook-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.7 kB

Release files / path_comment_hook-0.1.0.tar.gz

Download URL path_comment_hook-0.1.0.tar.gz
Size 24.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ab227f210ba885fad0586bcf21daef4c8632ed7be6f9186b2652ee0235e2e82a
BLAKE2b-256 checksum
How to use checksums
41b0e3178a7e80a695987ceb270bce8a87a7868c8708e002c427751adaabeeee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2025.

Transparency log

Release files / path_comment_hook-0.1.0-py3-none-any.whl

Download URL path_comment_hook-0.1.0-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aada98679f33a5ed4bc94874a911bbd87b582d9abf95f9948460d96b35a2b4a7
BLAKE2b-256 checksum
How to use checksums
a034fc7eabccaef177642d1d51dffac80d75d02489965539333075084bb31ca9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 22, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page