0a1b1c771447638baf26281e381717efdcec0a81
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
- Slash Commands:
/setup,/help,/exit,/clear,/status,/compact - Token Tracking: Real-time token usage and cost per response, plus session totals
- Context Compaction: Automatic conversation history compression when approaching context limits
- Comprehensive Toolset: 15 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.)
- Ctrl+C Support: Cancel in-progress responses without exiting
Requirements
- .NET 10 SDK
clang(for native AOT publish on Linux)
Quick Start
# Option 1: Set environment variables
export ANCHOR_API_KEY=your_key_here
export ANCHOR_MODEL=qwen3.5-27b # optional, default: gpt-4o
dotnet run --project AnchorCli
# Option 2: Use interactive setup
dotnet run --project AnchorCli
/setup
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://openrouter.ai/api/v1 |
Any OpenAI-compatible endpoint |
ANCHOR_MODEL |
gpt-4o |
Model name |
ANCHOR_MAX_TOKENS |
4096 |
Max response tokens |
Slash Commands
| Command | Description |
|---|---|
/setup |
Run interactive TUI to configure API key, model, endpoint |
/help |
Show available tools and commands |
/exit |
Exit the application |
/clear |
Clear the conversation history |
/status |
Show session token usage and cost |
/compact |
Manually trigger context compaction |
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 editinggrep_recursive- Search for a regex pattern across all files in a directory treefind_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
├── AnchorConfig.cs # Environment variable configuration
├── ContextCompactor.cs # Conversation history compression
├── AppJsonContext.cs # Source-generated JSON context (AOT)
├── Hashline/
│ ├── HashlineEncoder.cs # Adler-8 + position-seed hashing
│ └── HashlineValidator.cs # Anchor resolution + validation
├── Tools/
│ ├── FileTools.cs # read_file, grep_file, grep_recursive, 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
├── Commands/
│ ├── ExitCommand.cs # /exit command
│ ├── HelpCommand.cs # /help command
│ ├── ClearCommand.cs # /clear command
│ ├── StatusCommand.cs # /status command
│ └── CompactCommand.cs # /compact command
├── OpenRouter/
│ └── PricingProvider.cs # Fetch model pricing from OpenRouter
└── SetupTui.cs # Interactive setup TUI
How It Works
- Setup: Configure API credentials via environment variables or
/setupcommand - 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
- Token Tracking: Responses show token usage and cost; session totals are maintained
- Context Compaction: When approaching context limits, conversation history is automatically compressed
- 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%