← Catalog

pi-hashline-edit

Hashline read/edit tool override for pi-coding-agent

Extension

Install

Install with PiG

pig install npm:pi-hashline-edit

Install with Pi

pi install npm:pi-hashline-edit
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.9.0 (README.md). PiG does not review it.

pi-hashline-edit

pi-hashline-edit

npm version License: MIT

Hash-anchored read and edit tool override for pi-coding-agent — every line carries a content hash, so edits never land on the wrong line, even when the file has changed.

Inspired by oh-my-pi.

This project now lives on GitLab. On August 18, 2026, GitHub banned an account I had been using for about seven years, and with it a large number of my open-source projects. I opened a support ticket the same day and reached out through several other channels; no one has replied yet. I am done waiting on GitHub, so development continues at gitlab.com/Linioi/pi-hashline-edit. I am sorry for the delay this has caused to the project.

If you have a way to reach GitHub Support, or know someone who does, I would be extremely grateful for help getting the account restored. You can also reach me through this project's issues.

Why

LLMs edit code by quoting the text they see on screen. But by the time the edit runs, the file may have changed — a concurrent write, an earlier edit in the same turn, or drift from a stale read. The hashline protocol gives every line a short content hash, so edits carry verifiable references instead of raw text. Stale anchors are caught before they touch the file: no silent corruption, no wrong-line rewrites.

Features

  • 📖 Hashline Read — file content with LINE#HASH: prefixes, providing verifiable line-level anchors
  • ✏️ Anchored Edit — replace / insert_after / insert_before / replace_text, all validated against content hashes before applying
  • 🔍 Grep — ripgrep-backed search returning LINE#HASH: anchors, usable directly in edit without a prior read (opt-in)
  • 🔗 Chained Edits — successful edits return fresh anchors, enabling consecutive edits without re-reading
  • 🛡️ Stale Anchor Recovery & Range Guard — deterministic single-base coordinate translation recovers shifted anchors without cross-block drift; multi-line range replaces verify observed interior lines before writing
  • 🚫 Strict by Design — no silent relocation, no fuzzy matching, no accidental overwrites
  • ⚡ Atomic Writes — temp-file + rename, symlink and hardlink safe

Quick Start

pi install npm:pi-hashline-edit

Once installed, pi's read and edit tools are replaced by hashline versions. Reading a file will look like:

 8#VR:function hello() {
 9#KT:  console.log("world");
10#BH:}

To edit, reference LINE#HASH anchors from the read output:

{
  "path": "src/main.ts",
  "edits": [
    { "op": "replace", "pos": "9#KT", "lines": ["  console.log('hashline');"] }
  ]
}

If the file has changed since the last read, stale anchors are caught with explicit re-read guidance — no silent errors.

How It Works

read: tagged line output

Text files are returned with a LINE#HASH: prefix on every line:

  • LINE — 1-indexed line number, left-padded for column alignment.
  • HASH — content hash from the alphabet ZPMQVRWSNKTXJBYH; 2 characters by default, configurable up to 4 (see Configuration).

Optional parameters: offset (start line), limit (max lines), raw (plain content without prefixes).

Images (JPEG, PNG, GIF, WebP, BMP) are passed through as attachments (and structured image objects in Pi Codemode). Binary and directory paths are rejected with a descriptive error.

edit: hash-anchored modifications

Edits use LINE#HASH anchors to target lines precisely. All edits in a single call validate against the same pre-edit snapshot and apply bottom-up, so line numbers stay consistent.

OpPurposeFields
replaceReplace one line (pos) or an inclusive range (pos + end).pos required, end optional, lines
insert_afterInsert lines after pos.pos required, lines
insert_beforeInsert lines before pos.pos required, lines
replace_textReplace an exact unique substring. Fails if not found or matches more than once.oldText, newText

Ripgrep-backed search returning LINE#HASH:content anchors in the same format as read output. These anchors can be passed directly into edit, closing the grep-to-edit loop without a separate round-trip.

  • Pattern is regex by default; set literal: true for fixed-string search.
  • Results respect .gitignore. Use path to scope and glob to filter by filename pattern.
  • Set context (0–5) for surrounding lines; limit to cap matches (default 50, max 200). Output is capped at 50KB / 2000 whole lines.
  • Passes --no-config to rg so ambient RIPGREP_CONFIG_PATH flags (e.g. --invert-match) cannot alter tool search semantics.
  • Off by default. Registered only when enabled in config ("grep": true) and rg is found on PATH.

Chained edits

After a successful edit, the result includes an --- Anchors A-B --- block with fresh LINE#HASH references for the changed region. These can be used directly in the next edit call without a full re-read, provided the next edit targets the same or nearby lines.

Configuration

Optional. Create ~/.pi/agent/hashline.json:

{
  "hashLength": 2,
  "grep": false,
  "replaceText": true
}
KeyDefaultRangeMeaning
hashLength22–4Characters per line hash. Longer hashes reduce false-accept risk at the cost of extra tokens per line.
grepfalsebooleanRegister the grep tool (also requires ripgrep on PATH).
replaceTexttruebooleanAllow the replace_text op. Set false to enforce anchor-only edits.

The file is read once at session start. A missing file means defaults. Invalid values fall back to defaults with a one-time warning.

Design Decisions

  • No fallback relocation. Mismatched anchors are never silently relocated to a "close enough" line. This trades convenience for correctness.
  • Stale anchors: translate, then re-validate. A hash mismatch first checks the newest qualified read snapshot and translates anchor line numbers across strictly preceding non-overlapping external changes, then re-validates through the same strict edit engine. Overlapping, adjoining, or unverified edits fail loudly ([E_STALE_ANCHOR], [E_RANGE_CHANGED], or [E_UNVERIFIED_RANGE]); content-matched candidates are listed when the anchor included a text hint.
  • Strict patch content. If lines contains display prefixes or diff markers, the edit is rejected with [E_INVALID_PATCH]. The model must send literal file content.
  • Noop loop guard. Three consecutive identical no-op edits throw [E_NOOP_LOOP], preventing the model from silently looping.
  • Atomic writes with pre-write verification. Files are written via temp-file-then-rename after re-verifying that the file on disk still matches the pre-edit snapshot ([E_FILE_CHANGED] on concurrent external modification). Symlink chains are resolved; hard-linked files preserve the shared inode; permissions are preserved.
  • Single-line hashing with snapshot neighbor guard. Each line's hash depends only on that line's content — untouched lines never change hash, even adjacent to an edit. When the file changed externally (or during concurrent edits in the same turn), the snapshot guard verifies exact [pos-1, pos+1] neighbors against the pre-edit snapshot and translates non-overlapping shifts deterministically.

For more details, see the FAQ.

Development

git clone https://gitlab.com/Linioi/pi-hashline-edit.git
cd pi-hashline-edit
npm install
npm test          # Run tests (vitest)
npm run typecheck # Type checking
npm run lint      # Biome linter
npm run check     # All checks (typecheck + lint + knip + test)

Set PI_HASHLINE_DEBUG=1 to show an "active" notification at session start.

Contributing

Contributions are welcome! Feel free to open an Issue or submit a Pull Request.

Please run npm run check before submitting to ensure all checks pass.

Have questions? See the FAQ.

Author's Note

When I first came across the hashline edit idea, I thought it was genuinely interesting and put together a rough demo in an afternoon. More than half a year later, a whole wave of hashline extensions has appeared across the community. To be honest, most of them are fairly rough (this one included) — too many grew out of piling AI-generated patches onto a simple idea until it became overcomplicated and drifted further down the wrong path.

I am still not convinced hashline editing gives modern models a decisive edge over plain text edits, and I welcome any benchmarks, counterexamples, or discussion. Either way, the one thing a low-level file editing tool cannot afford to compromise on is reliability.

Credits

Thanks to can1357 for the original oh-my-pi implementation and the hashline technique.

License

MIT