Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: minor
---

### Changed

- `control-claude-code`'s `cli/account.mjs` prints `none: API-key auth has no signed-in account` and exits 0 when `claude auth status` reports API-key auth with no email and no organization, so drive's mask post-check can resolve the `values:` source to no values. Any other auth with no account still exits 1.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Read-only commands drive runs from this control skill. Every other driving comma

| Command | Flags | Prints | Exit codes |
|---|---|---|---|
| `cli/account.mjs` | none | The signed-in email and organization name from `claude auth status --json`, one per line, for the `## Mask` `values:` line. It never writes them to a file | 0 printed; 1 `claude auth status` failed or named neither; 2 an argument was given |
| `cli/account.mjs` | none | The signed-in email and organization name from `claude auth status --json`, one per line, for the `## Mask` `values:` line. It never writes them to a file. Under API-key auth that names neither, it prints `none: API-key auth has no signed-in account` instead | 0 printed; 1 `claude auth status` failed, or named neither outside API-key auth; 2 an argument was given |
10 changes: 6 additions & 4 deletions plugins/harness-ops/skills/control-claude-code/cli/account.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/usr/bin/env node
// Prints the signed-in account's email and organization name, one per line, for
// drive's mask post-check (SKILL.md `## Mask` `values:`). Reads only; see README.md.
import { accountValues } from '../driver/driver.mjs';
import { authStatus, statusValues } from '../driver/driver.mjs';

const args = process.argv.slice(2);
if (args.length) {
console.error(`account takes no arguments: ${args.join(' ')}`);
process.exit(2);
}
try {
const values = accountValues();
if (!values.length) throw new Error('claude auth status names no email or organization');
console.log(values.join('\n'));
const status = authStatus();
const values = statusValues(status);
if (values.length) console.log(values.join('\n'));
else if (status?.authMethod === 'api_key') console.log('none: API-key auth has no signed-in account');
Comment thread
kyle-sexton marked this conversation as resolved.
Resolved
else throw new Error('claude auth status names no email or organization');
} catch (err) {
console.error(`account: ${err.message}`);
process.exit(1);
Expand Down
18 changes: 12 additions & 6 deletions plugins/harness-ops/skills/control-claude-code/driver/driver.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -585,28 +585,34 @@ export function readMasks(text) {
}

/**
* The signed-in account's email and organization name from `claude auth status`, run in
* `env`: the session's launch environment, else an attended launch's. The output is never
* echoed, so no value reaches a log or an error message.
* The parsed `claude auth status --json`, run in `env`: the session's launch environment,
* else an attended launch's. The output is never echoed, so no value reaches a log or an
* error message.
*/
export function accountValues(env = buildLaunch({ pluginDir: '.' }, process.env).env) {
export function authStatus(env = buildLaunch({ pluginDir: '.' }, process.env).env) {
const run = spawnSync('claude', ['auth', 'status', '--json'], {
env,
encoding: 'utf8',
timeout: 30_000,
shell: process.platform === 'win32',
});
if (run.error) throw new Error('claude auth status did not run; cannot read the signed-in account to mask it');
let status;
try {
status = JSON.parse(run.stdout);
return JSON.parse(run.stdout);
} catch {
throw new Error('claude auth status printed no JSON; cannot read the signed-in account to mask it');
}
}

/** The email and organization name an auth status names, without duplicates or blanks. */
export function statusValues(status) {
const values = [status?.email, status?.orgName].filter((v) => typeof v === 'string' && v.trim());
return [...new Set(values)];
}

/** The signed-in account's email and organization name, from `authStatus(env)`. */
export const accountValues = (env) => statusValues(authStatus(env));

const unitsOf = (cell) => cell.char.length;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// prerequisites checker's probe rule (the pattern is a regular expression run
// over the probe's output).
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { delimiter, dirname, join } from 'node:path';
Expand Down Expand Up @@ -991,6 +992,22 @@ test('the startup banner keeps the model and loses the plan tier', () => {
}
});

test('the key-auth status screen has no account to hide and still loses its session id and cwd', () => {
const { text } = driver.maskCells(toCells(fixture('status-key-auth-screen.txt')), MASKS, []);
for (const absent of ['@', 'Email:', 'Organization:', 'Login method:', '00000000-0000', '/home/<user>/project']) {
assert.ok(!text.includes(absent), `${absent} is not on the masked screen`);
}
for (const kept of [
`Session ID: ${'*'.repeat(36)}`,
`cwd: ${'*'.repeat(20)}`,
'Auth token: none',
'API key: ANTHROPIC_API_KEY',
'Opus 5.5 · API Usage Billing',
]) {
assert.ok(text.includes(kept), `${kept} stays`);
}
});

test('a value wrapped across rows and split by a border is masked; the rest of the row is not', () => {
const { text } = driver.maskCells(toCells('│ team: Example\n│ Org │ ok'), MASKS, ['Example Org']);
assert.equal(text, '│ team: *******\n│ *** │ ok');
Expand Down Expand Up @@ -1451,3 +1468,60 @@ test('a relative CCD_RUNTIME_DIR and a session name starting with - are usage er
);
await assert.rejects(main(['stop', '--session=-x']), { code: 2, message: '--session takes 1-32 letters, digits, _ or -, not starting with -' });
});

// ---- cli/account.mjs, run against a stub claude ----
// The stub outputs follow `claude auth status --json` from Claude Code 2.1.319: `authMethod` is
// `api_key` for a key (no email or orgName) and `claude.ai` for a subscription login. account.mjs
// runs under the attended buildLaunch env, which deletes ANTHROPIC_API_KEY as the driven session's
// env does, so key auth reaches it only from settings (apiKeyHelper or settings `env`). The stub
// ignores its environment, so these cases pin the parsing, not where the key comes from.

const ACCOUNT = join(HERE, '..', 'cli', 'account.mjs');

function runAccount(stdout) {
const box = sandbox();
writeFileSync(join(box.bin, 'claude'), `#!/bin/sh\nprintf '%s\\n' '${stdout}'\n`, { mode: 0o755 });
try {
return spawnSync(process.execPath, [ACCOUNT], {
encoding: 'utf8',
env: { ...process.env, PATH: `${box.bin}${delimiter}${process.env.PATH}` },
});
} finally {
rmSync(box.root, { recursive: true, force: true });
}
}

const KEY_AUTH = { loggedIn: true, authMethod: 'api_key', apiProvider: 'firstParty', apiKeySource: 'ANTHROPIC_API_KEY' };

test('account prints the none: line and exits 0 under key auth with no account', posixOnly, () => {
const run = runAccount(JSON.stringify(KEY_AUTH));
assert.equal(run.status, 0, run.stderr);
assert.equal(run.stdout, 'none: API-key auth has no signed-in account\n');
});

test('account exits 1 with nothing on stdout when no account is signed in at all', posixOnly, () => {
// This process may not look where the driven session signs in, so no login is never "nothing to hide".
const run = runAccount(JSON.stringify({ loggedIn: false, authMethod: 'none', apiProvider: 'firstParty' }));
assert.equal(run.status, 1);
assert.equal(run.stdout, '');
});

test('account prints the organization under key auth that names one', posixOnly, () => {
const run = runAccount(JSON.stringify({ ...KEY_AUTH, orgName: 'Example Org' }));
assert.equal(run.status, 0, run.stderr);
assert.equal(run.stdout, 'Example Org\n');
});

test('account exits 1 with nothing on stdout for a subscription login with no account', posixOnly, () => {
const run = runAccount(JSON.stringify({ loggedIn: true, authMethod: 'claude.ai' }));
assert.equal(run.status, 1);
assert.equal(run.stdout, '');
assert.equal(run.stderr, 'account: claude auth status names no email or organization\n');
});

test('account exits 1 with nothing on stdout when claude auth status prints no JSON', posixOnly, () => {
const run = runAccount('not json');
assert.equal(run.status, 1);
assert.equal(run.stdout, '');
assert.equal(run.stderr, 'account: claude auth status printed no JSON; cannot read the signed-in account to mask it\n');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
▐▛███▛█ Claude Code v2.1.319
▝▜██████▀ Opus 5.5 · API Usage Billing
▝▝ ▝▝ ~/project

Settings Status Config Usage Stats

Version: 2.1.319
Session name: /rename to add a name
Session ID: 00000000-0000-4000-8000-000000000000
Session kind: interactive
Peer address: uds:/tmp/cc-socks/12345.sock
cwd: /home/<user>/project
Auth token: none
API key: ANTHROPIC_API_KEY

Model: Default (claude-opus-5-5)
Setting sources: Project local settings
Auto mode server: Enabled

Esc to cancel
Loading