# Secrets and API keys in Aider: keep credentials out of the agent's reach

Source: https://botpassword.com/agents/aider
Last checked: 2026-10-25

Aider is an open-source terminal pair-programming tool that edits files in a git repository. The documentation reviewed does not describe MCP support. Aider loads API keys and `AIDER_` options from `.env` files in your home directory, git root and current directory, and `.aiderignore` excludes parts of the repository.

## MCP support

Not documented.


## Environment variables and .env files

Aider loads `.env` files in this order, later files taking priority: your home directory, the root of the git repo, the current directory, then the file given by `--env-file` (or `AIDER_ENV_FILE`). Options can be set with an `AIDER_` prefix (for example `AIDER_MODEL`), and provider keys use their standard names such as `OPENAI_API_KEY` or `ANTHROPIC_API_KEY`. `--api-key provider=<key>` sets `PROVIDER_API_KEY`, and `--set-env` sets other variables.

## File access

Aider works on the files you add to the chat and automatically gives the model a compact map of the rest of the git repository. It re-reads the latest copy of each file from disk for every message. A `.aiderignore` file (gitignore syntax, or `--aiderignore <file>`) tells aider to ignore parts of the repo.

Deny or ignore files with: .aiderignore.

## Credential risks

- **API keys in layered `.env` files.** Aider reads `.env` files from the home directory, git root and current directory, so a key set in a committed or shared project `.env` is picked up and later files override earlier ones.
- **Repository content is sent to the LLM provider.** Aider sends the files in the chat plus a repository map to the configured model, so secrets present in those files leave the machine; `.aiderignore` is the documented way to exclude paths.

## FAQ

### How do I set an API key for aider?

Export the provider's standard variable (for example `OPENAI_API_KEY`), put it in a `.env` file, or pass `--api-key provider=<key>`.

### Which .env files does aider read?

Your home directory, the git repo root and the current directory, in that order with later files winning, then any file given with `--env-file`.

### Does aider support MCP?

The aider documentation reviewed does not describe MCP support, so check the current release notes before relying on it.

### How do I give Aider an API key without it seeing the key?

Don't put the key in the prompt, in a file Aider can read, or in an environment variable it can print. Give it a tool that performs the authenticated step instead: a credential broker exposed over MCP or a CLI that injects the key into the command or HTTP request and returns only the result. BotPassword is that broker, through `bpw mcp` and the `bpw` CLI.

## Sources

- https://aider.chat/docs/config/dotenv.html
- https://aider.chat/docs/faq.html
- https://aider.chat/docs/usage/conventions.html
