agentprofiles-cli 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +392 -0
- package/dist/index.js +3461 -0
- package/dist/index.js.map +1 -0
- package/package.json +71 -0
package/README.md
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
# agentprofiles-cli
|
|
2
|
+
|
|
3
|
+
**Manage per-project configuration profiles for LLM agent tools via `direnv`.**
|
|
4
|
+
|
|
5
|
+
Currently supports [Claude Code](https://claude.ai/code) and [OpenCode](https://opencode.ai/).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## The Problem
|
|
10
|
+
|
|
11
|
+
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.
|
|
12
|
+
|
|
13
|
+
**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.
|
|
14
|
+
|
|
15
|
+
**But managing this manually is tedious:**
|
|
16
|
+
|
|
17
|
+
- You can't just set the variable in your shell config—that's global, one profile for everything.
|
|
18
|
+
- You can't add it to each project's dotfiles—that's not portable across projects with similar needs.
|
|
19
|
+
- You don't want to remember to export variables before launching your editor every time.
|
|
20
|
+
|
|
21
|
+
**agentprofiles-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.
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
# Create profiles once
|
|
25
|
+
agentprofiles add claude work
|
|
26
|
+
agentprofiles add claude personal
|
|
27
|
+
|
|
28
|
+
# Activate per-project
|
|
29
|
+
cd ~/work/client-project
|
|
30
|
+
agentprofiles set claude work --allow
|
|
31
|
+
|
|
32
|
+
cd ~/personal/side-project
|
|
33
|
+
agentprofiles set claude personal --allow
|
|
34
|
+
|
|
35
|
+
# Now "cd" handles everything. Enter a directory, get the right profile.
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## FAQ
|
|
41
|
+
|
|
42
|
+
### "Just use your global config"
|
|
43
|
+
|
|
44
|
+
**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.
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
### "Just use project-local config"
|
|
49
|
+
|
|
50
|
+
**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.
|
|
51
|
+
|
|
52
|
+
A profile should be defined once and _applied_ to projects, not duplicated into each one.
|
|
53
|
+
|
|
54
|
+
### "Just set the env var before launching"
|
|
55
|
+
|
|
56
|
+
**The problem:** This works for one-off commands, but breaks down for real workflows:
|
|
57
|
+
|
|
58
|
+
- Interactive sessions that spawn subprocesses inherit the environment—but only if you remembered to set it.
|
|
59
|
+
- Multiple terminals need the same treatment.
|
|
60
|
+
- You have to remember which profile goes with which project, every time.
|
|
61
|
+
|
|
62
|
+
Humans are bad at remembering things. Computers are good at it. Let the computer remember.
|
|
63
|
+
|
|
64
|
+
### "Why direnv specifically?"
|
|
65
|
+
|
|
66
|
+
[direnv](https://direnv.net/) is a mature, widely-used tool for per-directory environment management. It:
|
|
67
|
+
|
|
68
|
+
- Automatically loads/unloads environment variables when you `cd` in and out
|
|
69
|
+
- Has a security model (`direnv allow`) so you explicitly trust changes
|
|
70
|
+
- Works with any shell (zsh, bash, fish, etc.)
|
|
71
|
+
- Is already installed on many developer machines
|
|
72
|
+
|
|
73
|
+
We didn't want to reinvent this. direnv does one job well; agentprofiles-cli just makes it easy to use for agent tool profiles.
|
|
74
|
+
|
|
75
|
+
### "Do I really need another CLI tool?"
|
|
76
|
+
|
|
77
|
+
Fair question. You could manage this yourself with handwritten `.envrc` files. agentprofiles-cli is worth it if you value:
|
|
78
|
+
|
|
79
|
+
- **Named profiles** you can list, create, and remove
|
|
80
|
+
- **Consistent file structure** without thinking about it
|
|
81
|
+
- **Clean `.envrc` files** that only contain a small bootstrap block
|
|
82
|
+
- **Guardrails** like profile name validation and direnv hook detection
|
|
83
|
+
|
|
84
|
+
If you're comfortable managing raw env vars yourself, you don't need this. But if you want the convenience of `agentprofiles set claude work`, this is for you.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Requirements
|
|
89
|
+
|
|
90
|
+
### Node.js 20+
|
|
91
|
+
|
|
92
|
+
This is a Node.js CLI tool.
|
|
93
|
+
|
|
94
|
+
### direnv (required)
|
|
95
|
+
|
|
96
|
+
agentprofiles-cli generates direnv-compatible files. Without direnv installed and hooked into your shell, those files won't do anything.
|
|
97
|
+
|
|
98
|
+
**Install direnv:**
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
# macOS
|
|
102
|
+
brew install direnv
|
|
103
|
+
|
|
104
|
+
# Ubuntu/Debian
|
|
105
|
+
sudo apt install direnv
|
|
106
|
+
|
|
107
|
+
# Or see https://direnv.net/docs/installation.html
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Hook it into your shell** (add to your shell's rc file):
|
|
111
|
+
|
|
112
|
+
```sh
|
|
113
|
+
# ~/.zshrc
|
|
114
|
+
eval "$(direnv hook zsh)"
|
|
115
|
+
|
|
116
|
+
# ~/.bashrc
|
|
117
|
+
eval "$(direnv hook bash)"
|
|
118
|
+
|
|
119
|
+
# ~/.config/fish/config.fish
|
|
120
|
+
direnv hook fish | source
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
After adding the hook, restart your shell or source the rc file.
|
|
124
|
+
|
|
125
|
+
**Verify it works:**
|
|
126
|
+
|
|
127
|
+
```sh
|
|
128
|
+
direnv --version
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
When you `cd` into a directory with an `.envrc`, you should see direnv print a message about loading or blocking the file.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Installation
|
|
136
|
+
|
|
137
|
+
```sh
|
|
138
|
+
npm install -g agentprofiles-cli
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Getting Started
|
|
144
|
+
|
|
145
|
+
### 1. Initialize
|
|
146
|
+
|
|
147
|
+
```sh
|
|
148
|
+
agentprofiles setup
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
This creates the config directory (`~/.config/agentprofiles/` by default) and sets up subdirectories for each supported agent tool.
|
|
152
|
+
|
|
153
|
+
### 2. Create profiles
|
|
154
|
+
|
|
155
|
+
```sh
|
|
156
|
+
agentprofiles add claude work
|
|
157
|
+
agentprofiles add claude personal
|
|
158
|
+
agentprofiles add opencode work
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Or let it prompt you for a name:
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
agentprofiles add claude
|
|
165
|
+
# Suggests a random name like "jolly-curie", or enter your own
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### 3. Activate a profile in a project
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
cd /path/to/your/project
|
|
172
|
+
agentprofiles set claude work --allow
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
This writes two files:
|
|
176
|
+
|
|
177
|
+
- `.envrc` — with a small bootstrap block
|
|
178
|
+
- `.envrc.agentprofiles` — with the actual export statements
|
|
179
|
+
|
|
180
|
+
The `--allow` flag runs `direnv allow` automatically. Without it, you'll need to run `direnv allow` manually.
|
|
181
|
+
|
|
182
|
+
### 4. Work normally
|
|
183
|
+
|
|
184
|
+
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.
|
|
185
|
+
|
|
186
|
+
### 5. Switch or remove profiles
|
|
187
|
+
|
|
188
|
+
```sh
|
|
189
|
+
# Switch to a different profile
|
|
190
|
+
agentprofiles set claude personal --allow
|
|
191
|
+
|
|
192
|
+
# Remove a profile from this project (keeps the profile itself)
|
|
193
|
+
agentprofiles unset claude --allow
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Commands
|
|
199
|
+
|
|
200
|
+
| Command | Description |
|
|
201
|
+
| ----------------------- | --------------------------------------------------- |
|
|
202
|
+
| `setup` | Initialize the agentprofiles system (alias: `init`) |
|
|
203
|
+
| `list [agent]` | List profiles, optionally filtered by agent |
|
|
204
|
+
| `add <agent> [name]` | Create a new profile |
|
|
205
|
+
| `edit <agent> <name>` | Open a profile's directory in your editor |
|
|
206
|
+
| `remove <agent> [name]` | Delete a profile (alias: `rm`) |
|
|
207
|
+
| `set <agent> [name]` | Activate a profile for the current directory |
|
|
208
|
+
| `unset <agent>` | Deactivate a profile for the current directory |
|
|
209
|
+
|
|
210
|
+
### Common flags
|
|
211
|
+
|
|
212
|
+
- `--allow` / `-y` — Auto-run `direnv allow` after modifying files (for `set` and `unset`)
|
|
213
|
+
- `--quiet` / `-q` — Suppress the banner
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## How It Works
|
|
218
|
+
|
|
219
|
+
### Files in your project
|
|
220
|
+
|
|
221
|
+
When you run `agentprofiles set claude work`, it creates/updates:
|
|
222
|
+
|
|
223
|
+
**`.envrc`** — Contains a small bootstrap block:
|
|
224
|
+
|
|
225
|
+
```sh
|
|
226
|
+
### agentprofiles:begin
|
|
227
|
+
watch_file .envrc.agentprofiles
|
|
228
|
+
source_env_if_exists .envrc.agentprofiles
|
|
229
|
+
### agentprofiles:end
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**`.envrc.agentprofiles`** — Contains the actual exports:
|
|
233
|
+
|
|
234
|
+
```sh
|
|
235
|
+
# tool-generated; do not edit
|
|
236
|
+
|
|
237
|
+
### agentprofiles:begin claude
|
|
238
|
+
export CLAUDE_CONFIG_DIR="$HOME/.config/agentprofiles/claude/work"
|
|
239
|
+
### agentprofiles:end claude
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Only the block between `### agentprofiles:begin` and `### agentprofiles:end` in `.envrc` is managed by this tool. Your other environment variables are left alone.
|
|
243
|
+
|
|
244
|
+
### Profile storage
|
|
245
|
+
|
|
246
|
+
Profiles are stored in your config directory:
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
~/.config/agentprofiles/
|
|
250
|
+
├── config.json
|
|
251
|
+
├── claude/
|
|
252
|
+
│ ├── .gitignore # Ignores runtime artifacts
|
|
253
|
+
│ ├── work/
|
|
254
|
+
│ │ └── meta.json # Profile metadata
|
|
255
|
+
│ └── personal/
|
|
256
|
+
│ └── meta.json
|
|
257
|
+
└── opencode/
|
|
258
|
+
├── .gitignore
|
|
259
|
+
└── work/
|
|
260
|
+
└── meta.json
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Each profile directory _is_ the config directory for that tool. When `CLAUDE_CONFIG_DIR` points to `~/.config/agentprofiles/claude/work`, Claude Code reads its settings, history, and cache from there.
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Troubleshooting
|
|
268
|
+
|
|
269
|
+
### "Nothing happens when I cd into the project"
|
|
270
|
+
|
|
271
|
+
direnv isn't hooked into your shell.
|
|
272
|
+
|
|
273
|
+
1. Verify direnv is installed: `direnv --version`
|
|
274
|
+
2. Add the hook to your shell rc file (see [Requirements](#direnv-required))
|
|
275
|
+
3. Restart your shell or source the rc file
|
|
276
|
+
4. Re-enter the directory or run `direnv reload`
|
|
277
|
+
|
|
278
|
+
### "direnv says the .envrc is blocked"
|
|
279
|
+
|
|
280
|
+
This is direnv's security model. Run:
|
|
281
|
+
|
|
282
|
+
```sh
|
|
283
|
+
direnv allow
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Or use `--allow` when running `agentprofiles set` or `agentprofiles unset`.
|
|
287
|
+
|
|
288
|
+
### "The env var isn't set correctly"
|
|
289
|
+
|
|
290
|
+
Debug checklist:
|
|
291
|
+
|
|
292
|
+
1. Check the files exist: `cat .envrc` and `cat .envrc.agentprofiles`
|
|
293
|
+
2. Verify direnv loaded: `direnv status`
|
|
294
|
+
3. Check the variable: `echo $CLAUDE_CONFIG_DIR`
|
|
295
|
+
4. Look for conflicts: Are you exporting the same variable elsewhere?
|
|
296
|
+
|
|
297
|
+
Force direnv to reload:
|
|
298
|
+
|
|
299
|
+
```sh
|
|
300
|
+
direnv reload
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### I already have a `.envrc`
|
|
304
|
+
|
|
305
|
+
That's fine. agentprofiles only manages the section between its markers. Keep your existing content outside that block.
|
|
306
|
+
|
|
307
|
+
If you export the same variable elsewhere in the file, the last assignment wins.
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## What to Commit
|
|
312
|
+
|
|
313
|
+
This depends on your team, but common approaches:
|
|
314
|
+
|
|
315
|
+
| File | Recommendation |
|
|
316
|
+
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
317
|
+
| `.envrc` | **Commit it.** The bootstrap block is generic and portable. |
|
|
318
|
+
| `.envrc.agentprofiles` | **Usually gitignore.** It contains paths that may differ per machine. Have each developer run `agentprofiles set` locally. |
|
|
319
|
+
|
|
320
|
+
If your team uses identical paths (e.g., everyone uses defaults), committing `.envrc.agentprofiles` is fine.
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## Configuration
|
|
325
|
+
|
|
326
|
+
### Default locations
|
|
327
|
+
|
|
328
|
+
- **Config directory:** `~/.config/agentprofiles/` (or `$XDG_CONFIG_HOME/agentprofiles/`)
|
|
329
|
+
- **Content directory:** Same as config directory by default
|
|
330
|
+
|
|
331
|
+
### Environment variable overrides
|
|
332
|
+
|
|
333
|
+
| Variable | Purpose |
|
|
334
|
+
| --------------------------- | --------------------------------------- |
|
|
335
|
+
| `AGENTPROFILES_CONFIG_DIR` | Override where `config.json` lives |
|
|
336
|
+
| `AGENTPROFILES_CONTENT_DIR` | Override where profile directories live |
|
|
337
|
+
|
|
338
|
+
You can also set `contentDir` in `config.json` to point to a different location.
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## Removing agentprofiles from a project
|
|
343
|
+
|
|
344
|
+
To stop using agentprofiles in a specific project:
|
|
345
|
+
|
|
346
|
+
```sh
|
|
347
|
+
# Remove all agent blocks
|
|
348
|
+
agentprofiles unset claude --allow
|
|
349
|
+
agentprofiles unset opencode --allow
|
|
350
|
+
|
|
351
|
+
# Then manually remove the bootstrap block from .envrc
|
|
352
|
+
# and delete .envrc.agentprofiles if it's now empty
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Or manually:
|
|
356
|
+
|
|
357
|
+
1. Delete the `### agentprofiles:begin` / `### agentprofiles:end` block from `.envrc`
|
|
358
|
+
2. Delete `.envrc.agentprofiles`
|
|
359
|
+
3. Run `direnv allow`
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## Development
|
|
364
|
+
|
|
365
|
+
```sh
|
|
366
|
+
# Install dependencies
|
|
367
|
+
npm install
|
|
368
|
+
|
|
369
|
+
# Run in development
|
|
370
|
+
npm run start -- --help
|
|
371
|
+
|
|
372
|
+
# Build
|
|
373
|
+
npm run build
|
|
374
|
+
|
|
375
|
+
# Run all checks (matches CI)
|
|
376
|
+
npm run format:check && npm run lint && npm run typecheck && npm run test
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
| Script | Description |
|
|
380
|
+
| ------------------- | ----------------------------- |
|
|
381
|
+
| `npm run build` | Compile TypeScript to `dist/` |
|
|
382
|
+
| `npm run typecheck` | Type-check without emitting |
|
|
383
|
+
| `npm run start` | Run via tsx (no build needed) |
|
|
384
|
+
| `npm run test` | Run tests |
|
|
385
|
+
| `npm run lint` | Lint with ESLint |
|
|
386
|
+
| `npm run format` | Format with Prettier |
|
|
387
|
+
|
|
388
|
+
---
|
|
389
|
+
|
|
390
|
+
## License
|
|
391
|
+
|
|
392
|
+
MIT
|