Manage configuration profiles for LLM agent tools via direnv
npm install agentprofile-cliManage per-project configuration profiles for LLM agent tools via direnv.
Currently supports Claude Code and OpenCode.
---
You use an AI coding assistant. Maybe Claude Code, maybe OpenCode. You have multiple contexts where you work—personal projects, work repos, client codebases—and you want different settings, histories, or API keys for each.
The tools support this. Both Claude Code and OpenCode read their configuration from a directory specified by an environment variable (CLAUDE_CONFIG_DIR, OPENCODE_CONFIG_DIR). Point the variable at a different directory, and you get a completely isolated profile.
But managing this manually is tedious:
- You can't just set the variable in your shell config—that's global, one profile for everything.
- You can't add it to each project's dotfiles—that's not portable across projects with similar needs.
- You don't want to remember to export variables before launching your editor every time.
agentprofile-cli solves this. It gives you named profiles, stores them centrally, and uses direnv to automatically activate the right profile when you enter a project directory.
``shCreate profiles once
agentprofile add claude work
agentprofile add claude personal
cd ~/personal/side-project
agentprofile set claude personal --allow
---
FAQ
$3
The problem: There's only one global config. If you work across multiple contexts (personal/work/clients), you're constantly mixing histories, API keys, and settings that shouldn't mix.
Some people create separate user accounts on their machine for this. That works, but it's heavy-handed for what should be a simple configuration switch.
$3
The problem: Project-local configs aren't portable. If you have 10 work repos that should all use your "work" profile, you'd need to copy the same configuration into all 10. When you update it, you update it in 10 places.
A profile should be defined once and _applied_ to projects, not duplicated into each one.
$3
The problem: This works for one-off commands, but breaks down for real workflows:
- Interactive sessions that spawn subprocesses inherit the environment—but only if you remembered to set it.
- Multiple terminals need the same treatment.
- You have to remember which profile goes with which project, every time.
Humans are bad at remembering things. Computers are good at it. Let the computer remember.
$3
direnv is a mature, widely-used tool for per-directory environment management. It:
- Automatically loads/unloads environment variables when you
cd in and out
- Has a security model (direnv allow) so you explicitly trust changes
- Works with any shell (zsh, bash, fish, etc.)
- Is already installed on many developer machinesWe didn't want to reinvent this. direnv does one job well; agentprofile-cli just makes it easy to use for agent tool profiles.
$3
Fair question. You could manage this yourself with handwritten
.envrc files. agentprofile-cli is worth it if you value:- Named profiles you can list, create, and remove
- Consistent file structure without thinking about it
- Clean
.envrc files that only contain a small bootstrap block
- Guardrails like profile name validation and direnv hook detectionIf you're comfortable managing raw env vars yourself, you don't need this. But if you want the convenience of
agentprofile set claude work, this is for you.---
Requirements
$3
This is a Node.js CLI tool.
$3
agentprofile-cli generates direnv-compatible files. Without direnv installed and hooked into your shell, those files won't do anything.
Install direnv:
`sh
macOS
brew install direnvUbuntu/Debian
sudo apt install direnvOr see https://direnv.net/docs/installation.html
`Hook it into your shell (add to your shell's rc file):
`sh
~/.zshrc
eval "$(direnv hook zsh)"~/.bashrc
eval "$(direnv hook bash)"~/.config/fish/config.fish
direnv hook fish | source
`After adding the hook, restart your shell or source the rc file.
Verify it works:
`sh
direnv --version
`When you
cd into a directory with an .envrc, you should see direnv print a message about loading or blocking the file.---
Installation
`sh
npm install -g agentprofile-cli
`---
Getting Started
$3
`sh
agentprofile setup
`This creates the config directory (
~/.config/agentprofile/ by default) and sets up subdirectories for each supported agent tool.$3
`sh
agentprofile add claude work
agentprofile add claude personal
agentprofile add opencode work
`Or let it prompt you for a name:
`sh
agentprofile add claude
Suggests a random name like "jolly-curie", or enter your own
`$3
`sh
cd /path/to/your/project
agentprofile set claude work --allow
`This writes two files:
-
.envrc — with a small bootstrap block
- .envrc.agentprofile — with the actual export statementsThe
--allow flag runs direnv allow automatically. Without it, you'll need to run direnv allow manually.$3
Now every time you
cd into that project, direnv automatically exports CLAUDE_CONFIG_DIR pointing to your "work" profile. When you cd out, it unloads.$3
`sh
Switch to a different profile
agentprofile set claude personal --allowRemove a profile from this project (keeps the profile itself)
agentprofile unset claude --allow
`---
Commands
| Command | Description |
| ----------------------- | -------------------------------------------------- |
|
setup | Initialize the agentprofile system (alias: init) |
| list [agent] | List profiles, optionally filtered by agent |
| add | Create a new profile |
| edit | Open a profile's directory in your editor |
| remove | Delete a profile (alias: rm) |
| set | Activate a profile for the current directory |
| unset | Deactivate a profile for the current directory |$3
-
--allow / -y — Auto-run direnv allow after modifying files (for set and unset)
- --quiet / -q — Suppress the banner---
How It Works
$3
When you run
agentprofile set claude work, it creates/updates:
.envrc — Contains a small bootstrap block:`sh
$3
watch_file .envrc.agentprofile
source_env_if_exists .envrc.agentprofile
$3
`
.envrc.agentprofile — Contains the actual exports:`sh
tool-generated; do not edit
$3
export CLAUDE_CONFIG_DIR="$HOME/.config/agentprofile/claude/work"
$3
`Only the block between
### agentprofile:begin and ### agentprofile:end in .envrc is managed by this tool. Your other environment variables are left alone.$3
Profiles are stored in your config directory:
`
~/.config/agentprofile/
├── config.json
├── claude/
│ ├── .gitignore # Ignores runtime artifacts
│ ├── work/
│ │ └── meta.json # Profile metadata
│ └── personal/
│ └── meta.json
└── opencode/
├── .gitignore
└── work/
└── meta.json
`Each profile directory _is_ the config directory for that tool. When
CLAUDE_CONFIG_DIR points to ~/.config/agentprofile/claude/work, Claude Code reads its settings, history, and cache from there.---
Troubleshooting
$3
direnv isn't hooked into your shell.
1. Verify direnv is installed:
direnv --version
2. Add the hook to your shell rc file (see Requirements)
3. Restart your shell or source the rc file
4. Re-enter the directory or run direnv reload$3
This is direnv's security model. Run:
`sh
direnv allow
`Or use
--allow when running agentprofile set or agentprofile unset.$3
Debug checklist:
1. Check the files exist:
cat .envrc and cat .envrc.agentprofile
2. Verify direnv loaded: direnv status
3. Check the variable: echo $CLAUDE_CONFIG_DIR
4. Look for conflicts: Are you exporting the same variable elsewhere?Force direnv to reload:
`sh
direnv reload
`$3
That's fine. agentprofile only manages the section between its markers. Keep your existing content outside that block.
If you export the same variable elsewhere in the file, the last assignment wins.
---
What to Commit
This depends on your team, but common approaches:
| File | Recommendation |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
.envrc | Commit it. The bootstrap block is generic and portable. |
| .envrc.agentprofile | Usually gitignore. It contains paths that may differ per machine. Have each developer run agentprofile set locally. |If your team uses identical paths (e.g., everyone uses defaults), committing
.envrc.agentprofile is fine.---
Configuration
$3
- Config directory:
~/.config/agentprofile/ (or $XDG_CONFIG_HOME/agentprofile/)
- Content directory: Same as config directory by default$3
| Variable | Purpose |
| -------------------------- | --------------------------------------- |
|
AGENTPROFILE_CONFIG_DIR | Override where config.json lives |
| AGENTPROFILE_CONTENT_DIR | Override where profile directories live |You can also set
contentDir in config.json to point to a different location.---
Removing agentprofile from a project
To stop using agentprofile in a specific project:
`sh
Remove all agent blocks
agentprofile unset claude --allow
agentprofile unset opencode --allowThen manually remove the bootstrap block from .envrc
and delete .envrc.agentprofile if it's now empty
`Or manually:
1. Delete the
### agentprofile:begin / ### agentprofile:end block from .envrc
2. Delete .envrc.agentprofile
3. Run direnv allow---
Development
`sh
Install dependencies
npm installRun in development
npm run start -- --helpBuild
npm run buildRun all checks (matches CI)
npm run format:check && npm run lint && npm run typecheck && npm run test
`| Script | Description |
| ------------------- | ----------------------------- |
|
npm run build | Compile TypeScript to dist/ |
| npm run typecheck | Type-check without emitting |
| npm run start | Run via tsx (no build needed) |
| npm run test | Run tests |
| npm run lint | Lint with ESLint |
| npm run format` | Format with Prettier |---
MIT