1.8 KiB
1.8 KiB
The Hashline Technique
Hashline is AnchorCli's unique approach to safe, precise file editing.
How It Works
Every line returned by file tools is prefixed with a content-derived hash anchor:
function hello() {
return "world";
}
The format is lineNumber:hash|content where:
lineNumberis the current line number in the filehashis an Adler-8 checksum derived from the line content and positioncontentis the actual line text
Editing with Anchors
When editing, you reference these line:hash anchors instead of reproducing old content. Before any mutation, both the line number and hash are validated — stale anchors are rejected immediately.
Example
To replace lines 2-3 from the example above:
{
"tool": "replace_lines",
"path": "example.js",
"startAnchor": "2:f1",
"endAnchor": "3:0e",
"newLines": [" return \"hello world\";"]
}
Benefits
This eliminates:
- Whitespace/indentation reproduction errors — No need to match exact spacing
- Silent edits to the wrong line — Hash validation ensures you're editing the right content
- Entire-file rewrites — Change just one line without touching the rest
- Line drift in batch operations — BatchEdit validates all anchors upfront and applies changes bottom-to-top
Key Principles
- Never include anchors in your content — When using
replace_lines,insert_after, or similar tools, thenewLinesparameter should contain raw source code only, WITHOUT thelineNumber:hash|prefix - Always validate before editing — Re-read files to get fresh anchors if your previous anchors fail validation
- Use BatchEdit for multiple changes — This validates all anchors upfront and applies operations atomically