code-header-annotator
Original:🇺🇸 English
Translated
2 scripts
Add or refresh a fixed 20-line file-header comment that summarizes a source file and indexes key classes/functions with line-number addresses. Use when annotating large codebases for fast navigation, onboarding, refactors, or when you want LLMs/humans to locate relevant symbols quickly without reading entire files.
8installs
Sourcelexwdex/my_lm_skills
Added on
NPX Install
npx skill4agent add lexwdex/my_lm_skills code-header-annotatorTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Code Header Annotator
Maintain a fixed 20-line header region per code file (marked by ) that captures the file's purpose and a compact index of key symbols (with line addresses).
@codex-header: v1Workflow (per file)
- Preserve prolog lines - Keep required first lines (shebang, encoding cookie, build tags, etc.)
- Ensure 20-line header - Insert new or update existing, always keep marker
@codex-header: v1 - Scan file sections - Imports → config → types → functions → entrypoints → side effects
- Populate header - Use precise names + line addresses, write when unsure
TODO - Verify addresses - Ensure every points to correct definition
Name@L123
Navigation
When exploring large repos, read headers first, only open full files when relevant:
- Find annotated files:
rg "@codex-header: v1" - Check ,
Purpose,Key types,Key funcsfor relevanceInheritance - Use to jump "up" (bases) and "sideways" (siblings)
Inheritance - If parent is external (e.g., ), open that file's header first
Base@pkg/base.py#L42
Relationship notation: inherits, implements, mixin
->~>+Upward Reasoning (inheritance / parent objects)
Use the header to "walk upward" from a concrete type to its parents:
- Start at the child's header (e.g.,
Inheritance:).Child@L120->Base@L30 - If the base has an in-file address (), jump there.
Base@L.. - If the base is external, prefer a cross-file pointer when available (e.g., ) and jump to that file's header first.
Base@path/to/base.ts#L30 - If the base is external and has no pointer, use /
Dependencies:hints, then search the repo for the base definition (e.g.,Public API:/rg "class Base\\b"), and annotate the base file too so it becomes indexable.rg "interface Base\\b" - Repeat until you reach the framework root / stable abstract base (or the registry/factory entrypoint).
Verification (required)
After processing all files, always run verification to ensure all auto-populated fields are complete:
bash
python code-header-annotator/scripts/check_incomplete_headers.py <files-or-dirs> --root <repo-root>This script checks for incomplete auto-populated fields (Key types, Key funcs, Entrypoints, Index) that should have been filled by the annotation script but weren't (e.g., due to tool crashes or interruptions).
If incomplete files are found, re-process them:
bash
python code-header-annotator/scripts/annotate_code_headers.py <incomplete-files> --root <repo-root>Then re-run verification until all headers are complete.
What to Capture (priority order)
- Purpose - What this file is responsible for (one sentence)
- Public surface - What other files import/call/instantiate from here
- Key symbols + addresses - Classes/interfaces, factories, handlers, main functions
- Inheritance & extension points - Base classes, subclasses, registries, plugin hooks
- Side effects / I-O - DB/filesystem/network, global state, caches
- Constraints - Important invariants, error modes, performance or security notes
Automation
Use bundled script to insert/update headers:
bash
python code-header-annotator/scripts/annotate_code_headers.py <files-or-dirs> --root <repo-root> --resolve-parentsAlways verify after processing:
bash
python code-header-annotator/scripts/check_incomplete_headers.py <files-or-dirs> --root <repo-root>Or use flag for automatic verification:
--verifybash
python code-header-annotator/scripts/annotate_code_headers.py <files-or-dirs> --root <repo-root> --resolve-parents --verifyKey options:
- - Rebuild header from scratch (resets manual fields to TODO)
--refresh - - Resolve external parents to cross-file references
--resolve-parents - Default is non-destructive: preserves existing non-TODO manual fields
AGENTS.md Integration
For AI-optimized navigation, generate an AGENTS.md file that guides LLMs to read only file headers first:
bash
python code-header-annotator/scripts/annotate_code_headers.py <files> --root <repo-root> --update-agents-mdThis creates/updates in the repo root with:
AGENTS.md- Reading pattern instructions: Read first 20 lines only, then jump to specific lines using syntax
@L<line> - Indexed table: All annotated files with their purposes and key symbols (types, functions)
- Navigation syntax reference: How to use addressing for fast navigation
Name@L<line>
Why AGENTS.md?
- Reduces LLM context bloat by teaching it to read headers first
- Provides a quick overview of all annotated files without reading each one
- Improves output accuracy by focusing on structure before diving into implementation
Combined usage:
bash
python code-header-annotator/scripts/annotate_code_headers.py <files> --root <repo-root> --resolve-parents --verify --update-agents-mdCritical: Update Index on File Changes
MANDATORY: When this skill is active, you MUST maintain the header index every time you modify a file.
Index Maintenance Rules
-
After every file edit - Update the affected file's header:
- Add new symbols with their correct line numbers
- Remove deleted symbols from the header
- Update if file responsibility changed
Purpose - Update if exports changed
Public API - Update if relationships changed
Inheritance
-
After code changes - Adjust line numbers:
- Moving code changes line numbers → update all affected addresses
@L<line> - Insertions/deletions shift subsequent lines → recalculate and update addresses
- Check section anchors and update if sections moved
Index:
- Moving code changes line numbers → update all affected
-
After adding new files - Always add headers:
- Any new source file should get a 20-line header
- Include all concrete symbols with correct line numbers
- Set for fields that need manual completion
TODO
-
Before committing/pushing - Final verification:
- Run to ensure no incomplete fields
check_incomplete_headers.py - Re-run with
annotate_code_headers.pyflag--verify - Fix any line number mismatches or missing symbols
- Run
Anti-Pattern: Stale Indexes
Never do this:
- Modify code without updating the header
- Leave in fields that are now known
TODO - Ignore line number drift after refactoring
- Add new files without headers
Always do this:
- Update header in the same edit as code changes
- Run verification after batch changes
- Treat the header as live documentation, not one-time annotation
Verification Workflow
For any codebase modification task:
bash
# 1. Make your code changes
# 2. Update headers for modified files
python code-header-annotator/scripts/annotate_code_headers.py <modified-files> --root <repo-root> --resolve-parents
# 3. Verify no incomplete fields
python code-header-annotator/scripts/check_incomplete_headers.py <modified-files> --root <repo-root>
# 4. If incomplete, re-process
python code-header-annotator/scripts/annotate_code_headers.py <incomplete-files> --root <repo-root>
# 5. Repeat until cleanKey principle: The header index must always reflect the current state of the file. A stale index is worse than no index because it misleads navigation.
Core Rules
- Fixed size: Always 20 lines per file
- High-signal: One-line fields, compress lists, truncate long text
- Indexing first: Include exported/public API, key types, key functions, entrypoints
- Addresses: Use for all concrete symbols
Name@L<line> - Concrete names only: Never use abstract descriptions like "data models"
References
- Field guidelines: See guidelines.md for detailed requirements per field
- Examples: See examples.md for good vs bad patterns
- Format spec: See header-format.md for canonical field structure