@anyforge/control 0.2.0 → 0.2.2

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 CHANGED
@@ -32,6 +32,10 @@ Pick whichever suits the moment — the choices aren't mutually exclusive over t
32
32
 
33
33
  > The `.env` written in per-repo mode contains a live `ANYFORGE_API_KEY`. The CLI warns if your repo's `.gitignore` doesn't already exclude `.env`. **Add it before committing.**
34
34
 
35
+ ### Why `ANTHROPIC_AUTH_TOKEN`, not `ANTHROPIC_API_KEY`?
36
+
37
+ Claude Code recognises both, but they behave differently. `ANTHROPIC_API_KEY` is sent as `X-Api-Key` and — when an OAuth Console login is also present — surfaces an "Auth conflict: Using ANTHROPIC_API_KEY instead of Anthropic Console key" warning, and can cascade into a "selected model may not exist" error. `ANTHROPIC_AUTH_TOKEN` is sent as `Authorization: Bearer …`, is documented for "routing through an LLM gateway or proxy", out-ranks the OAuth login cleanly, and matches the bearer-token shape AnyForge expects. We patch the token form, and on every install we explicitly delete any stale `ANTHROPIC_API_KEY` left behind by older versions.
38
+
35
39
  ## Commands
36
40
 
37
41
  | | |
@@ -1,4 +1,5 @@
1
1
  import { promises as fs } from 'fs';
2
+ import { homedir } from 'os';
2
3
  import { join } from 'path';
3
4
  import open from 'open';
4
5
  import prompts from 'prompts';
@@ -65,13 +66,32 @@ export async function runInit(opts) {
65
66
  // eslint-disable-next-line no-console
66
67
  console.log(dim(' Set ANTHROPIC_BASE_URL=' + endpoint + '/v1/anthropic and'));
67
68
  // eslint-disable-next-line no-console
68
- console.log(dim(' ANTHROPIC_API_KEY=<your AnyForge key> manually if needed.'));
69
+ console.log(dim(' ANTHROPIC_AUTH_TOKEN=<your AnyForge key> manually if needed.'));
69
70
  }
70
71
  else {
71
72
  summarisePatches(patches);
72
73
  }
73
74
  // eslint-disable-next-line no-console
74
75
  console.log();
76
+ if (await hasClaudeCodeLogin()) {
77
+ // Claude Code shows an "Auth conflict" warning when both a /login
78
+ // credential and an env-token are set — even though the token wins
79
+ // by precedence (#2 vs #6), the warning is cosmetic-but-loud. The
80
+ // only way to silence it is to stay logged out: /logout once, then
81
+ // skip the login prompt on the next launch.
82
+ // eslint-disable-next-line no-console
83
+ console.log(yellow(' ⚠ Existing Claude Code login detected (~/.claude/.credentials.json).'));
84
+ // eslint-disable-next-line no-console
85
+ console.log(dim(' Claude Code will work, but it will warn that both a token and a'));
86
+ // eslint-disable-next-line no-console
87
+ console.log(dim(' /login key are set. To silence the warning:'));
88
+ // eslint-disable-next-line no-console
89
+ console.log(dim(' 1) run `claude /logout`,'));
90
+ // eslint-disable-next-line no-console
91
+ console.log(dim(' 2) on the next launch, skip the login prompt (Esc / Ctrl+C).'));
92
+ // eslint-disable-next-line no-console
93
+ console.log(dim(' The AnyForge token in settings.local.json is enough on its own.'));
94
+ }
75
95
  if (scope === 'repo') {
76
96
  // eslint-disable-next-line no-console
77
97
  console.log(dim(' Re-run this command in another repo to patch it too,'));
@@ -112,6 +132,20 @@ async function pollForToken(args) {
112
132
  }
113
133
  throw new Error('Authorisation timed out (15 min). Re-run `anyforge init`.');
114
134
  }
135
+ async function hasClaudeCodeLogin() {
136
+ // Claude Code's docs document the credentials file at
137
+ // ~/.claude/.credentials.json (Linux/Windows) or the macOS Keychain.
138
+ // We can only see the file on Linux/Windows. On macOS the keychain
139
+ // is invisible to us, so this check is best-effort — false negatives
140
+ // are fine since the warning is just a hint.
141
+ try {
142
+ await fs.access(join(homedir(), '.claude', '.credentials.json'));
143
+ return true;
144
+ }
145
+ catch {
146
+ return false;
147
+ }
148
+ }
115
149
  async function isGitRepoRoot(cwd) {
116
150
  // git worktrees use a `.git` file pointing at the real gitdir, so
117
151
  // accept either a directory or a regular file.
@@ -65,7 +65,12 @@ async function patchClaudeCode(opts) {
65
65
  }
66
66
  const env = (json.env ?? {});
67
67
  env.ANTHROPIC_BASE_URL = `${opts.endpoint}/v1/anthropic`;
68
- env.ANTHROPIC_API_KEY = opts.apiKey;
68
+ env.ANTHROPIC_AUTH_TOKEN = opts.apiKey;
69
+ // Strip stale ANTHROPIC_API_KEY from prior installs — keeping
70
+ // both set re-triggers the auth-conflict warning even though
71
+ // ANTHROPIC_AUTH_TOKEN is what we actually want Claude Code
72
+ // to use.
73
+ delete env.ANTHROPIC_API_KEY;
69
74
  json.env = env;
70
75
  await fs.writeFile(path, JSON.stringify(json, null, 2) + '\n');
71
76
  // eslint-disable-next-line no-console
@@ -93,7 +98,7 @@ async function patchRepoEnv(opts) {
93
98
  SENTINEL_BEGIN,
94
99
  `ANYFORGE_API_KEY=${opts.apiKey}`,
95
100
  `ANTHROPIC_BASE_URL=${opts.endpoint}/v1/anthropic`,
96
- `ANTHROPIC_API_KEY=${opts.apiKey}`,
101
+ `ANTHROPIC_AUTH_TOKEN=${opts.apiKey}`,
97
102
  `OPENAI_BASE_URL=${opts.endpoint}/v1/openai`,
98
103
  `OPENAI_API_KEY=${opts.apiKey}`,
99
104
  SENTINEL_END,
@@ -177,9 +182,10 @@ async function ensureShellRcExports(opts) {
177
182
  SENTINEL_BEGIN,
178
183
  `export ANYFORGE_API_KEY="${opts.apiKey}"`,
179
184
  `export ANTHROPIC_BASE_URL="${opts.endpoint}/v1/anthropic"`,
180
- `export ANTHROPIC_API_KEY="${opts.apiKey}"`,
185
+ `export ANTHROPIC_AUTH_TOKEN="${opts.apiKey}"`,
181
186
  `export OPENAI_BASE_URL="${opts.endpoint}/v1/openai"`,
182
187
  `export OPENAI_API_KEY="${opts.apiKey}"`,
188
+ `unset ANTHROPIC_API_KEY 2>/dev/null || true`,
183
189
  SENTINEL_END,
184
190
  '',
185
191
  ].join('\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anyforge/control",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "AnyForge Control CLI — governed LLM proxy for Claude Code, Cursor, Cline, and any agent that talks to OpenAI- or Anthropic-shape APIs.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://anyforge.ai",