A powerful command-line AI agent built with Go that enables Claude to interact with your file system through a comprehensive set of tools. This agent can read, list, and edit files, making it perfect for code editing and file management tasks.
- Interactive chat interface with Claude 3.5 Sonnet
- Colored output for better readability
- Conversation memory across multiple exchanges
- Read Files: Read contents of any file in the working directory
- List Files: Browse directories and list files recursively
- Edit Files: Search and replace text in files with validation
- Create Files: Automatically create new files and directories
- Type-safe tool definitions with automatic JSON schema generation
- Robust error handling and input validation
- Cross-platform file path handling
- Extensible tool system for adding new capabilities
- Go 1.25.1 or later
- Anthropic API key
-
Clone this repository:
git clone <your-repo-url> cd code-editing-agent
-
Install dependencies:
go mod tidy
-
Set your Anthropic API key:
export ANTHROPIC_API_KEY="your-api-key-here"
-
Run the agent:
go run main.go
Once running, you can interact with the agent using natural language:
You: Read the contents of main.go
Claude: [Reads and displays the file contents]
You: List all Go files in this project
Claude: [Shows a list of .go files]
You: Replace 'fmt.Println' with 'log.Println' in main.go
Claude: [Makes the replacement and confirms success]
Reads the contents of a file at the specified path.
- Parameters:
path
(string) - Relative path to the file
Lists files and directories at a given path.
- Parameters:
path
(string, optional) - Path to list (defaults to current directory)
Makes text replacements in files using search and replace.
- Parameters:
path
(string) - Path to the fileold_str
(string) - Text to search fornew_str
(string) - Text to replace with
The agent is built with a clean, modular architecture:
- Agent: Main chat loop and tool orchestration
- Tool System: Extensible framework for adding new capabilities
- Schema Generation: Automatic JSON schema generation using reflection
- Error Handling: Comprehensive error handling and user feedback
To add a new tool, create a new ToolDefinition
:
var MyToolDefinition = ToolDefinition{
Name: "my_tool",
Description: "Description of what the tool does",
InputSchema: MyToolInputSchema,
Function: MyToolFunction,
}
type MyToolInput struct {
Param1 string `json:"param1" jsonschema_description:"Description of param1"`
}
var MyToolInputSchema = GenerateSchema[MyToolInput]()
func MyToolFunction(input json.RawMessage) (string, error) {
// Tool implementation
}
This project was inspired by the excellent work on AI agents and tool systems. Special thanks to:
- Agents for the Agent for inspiration on AI agent architecture and tool integration patterns
- Anthropic for the Claude API and Go SDK
- The Go community for excellent libraries and patterns
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
If you encounter any issues or have questions, please open an issue on GitHub.