3ceb0e4884fb78a3156909a3a983994c8d5369a1
AnchorCli
An AI-powered coding assistant built as a .NET 10.0 console application, featuring the Hashline technique for safe, precise file editing.
What is Hashline?
AnchorCli's unique approach to file editing. Every line returned by file tools is prefixed with a content-derived hash anchor:
1:a3| function hello() {
2:f1| return "world";
3:0e| }
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.
This eliminates:
- Whitespace/indentation reproduction errors
- Silent edits to the wrong line in large files
- Entire-file rewrites just to change one line
Features
- Interactive REPL: Chat with an AI model to edit files, manage directories, and execute commands
- Comprehensive Toolset: 12+ tools for file operations, editing, directory management, and command execution
- AOT-Ready: Native AOT compilation for ~12 MB binaries with no .NET runtime dependency
- Rich CLI: Beautiful terminal output using Spectre.Console with tables, rules, and colored text
- Streaming Responses: Real-time AI response streaming in the terminal
- OpenAI-Compatible: Works with any OpenAI-compatible API (OpenAI, Ollama, Cerebras, Groq, OpenRouter, etc.)
Requirements
- .NET 10 SDK
clang(for native AOT publish on Linux)
Quick Start
export ANCHOR_API_KEY=your_key_here
export ANCHOR_MODEL=qwen3.5-27b # optional, default: gpt-4o
export ANCHOR_ENDPOINT=https://api.openai.com/v1 # optional
dotnet run --project AnchorCli
Native AOT Build
dotnet publish AnchorCli -r linux-x64 -c Release
./AnchorCli/bin/Release/net10.0/linux-x64/publish/anchor
The resulting binary is ~12 MB, has no .NET runtime dependency, and starts instantly.
Environment Variables
| Variable | Default | Description |
|---|---|---|
ANCHOR_API_KEY |
(required) | API key for the LLM provider |
ANCHOR_ENDPOINT |
https://api.openai.com/v1 |
Any OpenAI-compatible endpoint |
ANCHOR_MODEL |
gpt-4o |
Model name |
ANCHOR_MAX_TOKENS |
4096 |
Max response tokens |
Available Tools
File Operations:
read_file- Read a file (or a window) with Hashline-tagged linesgrep_file- Search a file by regex — results are pre-tagged for immediate editingfind_files- Search for files matching glob patternsget_file_info- Get detailed file information (size, permissions, etc.)
Edit Operations:
replace_lines- Replace a range identified byline:hashanchorsinsert_after- Insert lines after an anchordelete_range- Delete a range between two anchorscreate_file- Create a new file with optional initial contentdelete_file- Delete a file permanentlyrename_file- Rename or move a filecopy_file- Copy a file to a new locationappend_to_file- Append lines to the end of a file
Directory Operations:
list_dir- List directory contentscreate_dir- Create a new directory (with parent directories)rename_dir- Rename or move a directorydelete_dir- Delete a directory and all its contents
Command Execution:
execute_command- Run shell commands (with user approval)
Project Structure
AnchorCli/
├── Program.cs # Entry point + REPL loop + AI client setup
├── Config/AppConfig.cs # Environment variable configuration
├── Hashline/
│ ├── HashlineEncoder.cs # Adler-8 + position-seed hashing
│ └── HashlineValidator.cs # Anchor resolution + validation
├── Tools/
│ ├── FileTools.cs # read_file, grep_file, find_files, get_file_info
│ ├── EditTools.cs # replace_lines, insert_after, delete_range, create/delete/rename/copy/append
│ ├── DirTools.cs # list_dir, create_dir, rename_dir, delete_dir
│ └── CommandTool.cs # execute_command
└── Json/AppJsonContext.cs # Source-generated JSON context (AOT)
How It Works
- Setup: The AI client is configured with your API credentials and model preferences
- REPL Loop: You interact with the AI through a conversational interface
- Tool Calling: The AI can call any of the available tools to read/edit files, manage directories, or execute commands
- Hashline Validation: All file edits are validated using the Hashline technique to ensure precision
- Safe Execution: Commands require explicit user approval before running
Supported Models
AnchorCli works with any OpenAI-compatible API endpoint, including:
- OpenAI (gpt-4o, gpt-4.1, etc.)
- Ollama (local models)
- Cerebras
- Groq
- OpenRouter (qwen3.5-27b, etc.)
- Any custom OpenAI-compatible server
License
MIT License - See LICENSE file for details.
Languages
C#
98.6%
PowerShell
1.1%
Shell
0.3%