See Ash Code logo See Ash Code

Which comments should my new hook preserve?

Ashlynn Antrobus
• • 3 min read

My new hook can identify a Python comment and remove it. That doesn’t answer whether removing it was a good idea.

The immediate target is redundant narration beside code: a comment saying a value is being assigned, a loop is starting, or a function is about to be called. Those comments are easy to accumulate when working with coding agents.

But a comment can also be part of a tool’s instructions or the only explanation of a constraint. I need a policy that goes beyond recognizing the comment marker.

A dragon examines a paper note with a magnifying glass beside several piles of notes.

Illustration: considering which notes to keep.

What the January tool keeps

The initial implementation uses Python tokens for Python files and separate regular-expression paths for other language families. Its preservation rules differ between those paths.

ExampleJanuary behaviorPolicy question
A hash inside a Python stringKeep the string token.Removing it would change data.
A Python docstringKeep the string token.Documentation remains outside the comment filter.
A Python shebang on line oneKeep it explicitly.It can determine how the file starts.
A Python coding: comment in the first two linesKeep it explicitly.Encoding declarations need an intentional rule.
An ordinary Python commentRemove it.Does it merely narrate code, or explain a reason?
A Python # noqa or # type: ignore directiveRemove it under the ordinary comment rule.That can change another tool’s behavior.
A shell shebangThe hash-language path removes it.This path needs its own preservation decision.
A C-style documentation blockThe C-style path is intended to keep it.Language-specific forms need representative fixtures.

The Python encoding exception specifically looks for coding:. It doesn’t establish complete handling of every valid coding declaration just because that example is preserved.

The marker doesn’t tell me the purpose

In the tokenizer post, distinguishing strings from comments prevented the hook from damaging a URL. A token-aware transformation still can’t decide that an explanation of a surprising business rule is redundant.

An ordinary comment might explain why a seemingly simpler implementation is wrong. Removing that explanation doesn’t necessarily make the code easier to maintain. The hook currently has no understanding of that distinction.

Tool directives are more concrete. They use comment syntax, but another program reads them as instructions. Treating them as disposable prose can change linting or type-checking results even when Python runs the same way.

Installation doesn’t settle the policy

The console entry point makes the hook usable from a consumer repository. It doesn’t broaden the preservation rules.

Before applying it to a project, I need examples of the comments that project relies on and a decision about what the hook should do with each. Some belong in automatic keep rules. Some need a human review because their value is in the explanation.

AA

Written by Ashlynn Antrobus

Software developer, author, and builder. Sharing technical lessons learned from building tools like Ebook2Text, IndexedDict, and rag-mcp, and navigating life as a programmer with dyslexia.