Configure an Open Source Coding Agent for Your Repo
In this article
Open source coding agents (like Aider, Continue, or OpenHands) can automate code changes, run tests, and even fix bugs directly in your repository. This guide walks you through configuring one for your project, from initial setup to troubleshooting common issues.
What You'll Need
- A Git repository (local or remote) with a clear branch structure.
- A supported LLM API key (e.g., OpenAI, Anthropic, or a local model via Ollama).
- Python 3.9+ and pip installed (most agents are Python-based).
- Basic familiarity with the command line.
Step-by-Step
- Choose your agent. Popular options include Aider (pair programming in terminal), Continue (IDE extension), and OpenHands (autonomous agent). Pick one that matches your workflow—Aider is great for quick edits, Continue for IDE integration, OpenHands for complex multi-step tasks.
- Install the agent. For Aider:
pip install aider-chat. For Continue: install the extension from your IDE's marketplace. For OpenHands:pip install openhands(or use Docker). - Set up API credentials. Export your API key as an environment variable, e.g.,
export OPENAI_API_KEY='your-key'for OpenAI. For local models, point the agent to your Ollama server (e.g.,--model ollama/codellama). - Initialize the agent in your repo. Navigate to your project root and run the agent's init command. For Aider:
aider --init. This creates a configuration file (usually.aider.conf.ymlorcontinue.config.json) in your home or project directory. - Configure repository context. Tell the agent which files to focus on. In Aider, you can add files to the chat session with
/add src/main.py. For Continue, use the @-mention to reference files. OpenHands automatically scans the repo but you can set ignore patterns in its config. - Set model and parameters. Edit the config file to specify the model (e.g.,
model: gpt-4o), temperature, and max tokens. Keep temperature low (0.2-0.5) for code tasks to reduce randomness. - Define project rules. Most agents support a
AGENTS.mdorCONTINUE.mdfile. Add instructions like "Use type hints", "Run tests after changes", or "Never modify generated files". This guides the agent's behavior. - Test with a simple task. Ask the agent to make a trivial change, e.g., "Add a docstring to the main function". Verify the diff and run your tests to ensure nothing breaks.
- Integrate with Git. Configure the agent to create branches for each change. In Aider, use
--auto-commitsto automatically commit after each edit. For OpenHands, setworkspaceto a subdirectory to avoid clutter. - Run the agent in your CI/CD (optional). Some agents support headless mode for automated PRs. For example, Aider can be run in a GitHub Action to review PRs. Set up a workflow that triggers on pull requests and runs the agent with specific instructions.
Common Mistakes
- Not setting a low temperature—high temperature leads to unpredictable code.
- Ignoring the repo's build system—the agent may not know how to run tests unless you tell it.
- Allowing the agent to modify sensitive files—always set ignore patterns for secrets, lock files, or generated code.
- Forgetting to review the diff before merging—agents can introduce subtle bugs.
- Using a model that's too small for complex tasks—small models often produce broken code.
Tips
- Start with a small, well-scoped task to test your configuration.
- Use a separate branch for agent changes to keep your main branch clean.
- Provide context in your prompts: reference specific files, functions, or error messages.
- Leverage the agent's undo/redo features (e.g.,
/undoin Aider) to revert bad changes. - Keep your
AGENTS.mdfile concise—agents have limited context windows. - Regularly update the agent and its dependencies to get the latest improvements.
Troubleshooting
Agent doesn't respond or times out. Check your API key and network connection. If using a local model, ensure the server is running. Increase the timeout in the config.
Agent makes changes to wrong files. Review your ignore patterns and ensure you've added the correct files to the session. Use /clear to reset context.
Tests fail after agent changes. Ask the agent to run the tests itself (if supported) or manually run them. Provide the error output in a follow-up prompt.
Agent ignores your AGENTS.md rules. Make sure the file is in the root directory and named correctly. Some agents require the file to be added to the session explicitly.
Rate limit exceeded. Reduce the number of requests by batching changes or using a smaller model. Consider upgrading your API plan.
Configuration file not found. Run the init command again or manually create the config file in the correct location (check the agent's docs).
Frequently Asked Questions
Can I use a local LLM with these agents?
Yes, most agents support local models via Ollama or LM Studio. Set the model to something like ollama/codellama and ensure your local server is running.
How do I keep the agent from touching my secrets?
Add files like .env, *.pem, and config/secrets.yml to your ignore list in the agent's config. Also, never include secrets in your prompts.
What if the agent makes a mess of my code?
Use Git to revert. If you have auto-commit enabled, you can reset to the previous commit. Most agents also have an undo command for the last change.
Can I run the agent on a CI server?
Yes, but you'll need to set up a headless mode. Aider and OpenHands have CLI options that work in CI. You'll need to store your API key as a CI secret.
Do I need to pay for an API?
Not necessarily. You can use free tiers (like OpenAI's trial) or local models. However, for production use, a paid API gives better reliability and speed.
How do I update the agent to a new version?
For pip-installed agents, run pip install --upgrade aider-chat. For IDE extensions, check your IDE's update mechanism. Always check the changelog for breaking config changes.