From 4c58f95548317f7f79ef18654f8ddd0dcce28f53 Mon Sep 17 00:00:00 2001 From: WhiteMind Date: Fri, 6 Mar 2026 15:49:04 +0800 Subject: [PATCH] fix: strip stray characters from pasted API key on Windows Cliffy's Secret.prompt injects tilde (~) characters at the start and end of pasted text on Windows terminals (bracket paste mode side-effect). This causes `auth login` to always fail with "Invalid API key" when the key is pasted interactively. Trim whitespace and strip non-key characters from both ends of the input. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/commands/auth/auth-login.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/commands/auth/auth-login.ts b/src/commands/auth/auth-login.ts index 81714104..b3fb1cca 100644 --- a/src/commands/auth/auth-login.ts +++ b/src/commands/auth/auth-login.ts @@ -34,13 +34,13 @@ export const loginCommand = new Command() .option("-k, --key ", "API key (prompted if not provided)") .action(async (options) => { try { - let apiKey = options.key + let apiKey = options.key?.trim() if (!apiKey) { - apiKey = await Secret.prompt({ + apiKey = (await Secret.prompt({ message: "Enter your Linear API key", hint: "Create one at https://linear.app/settings/account/security", - }) + }))?.trim() } if (!apiKey) { @@ -50,6 +50,9 @@ export const loginCommand = new Command() }) } + // Strip stray characters that some terminals (e.g. Windows) inject around pasted text + apiKey = apiKey.replace(/^[^a-zA-Z0-9_]+|[^a-zA-Z0-9_]+$/g, "") + // Validate the API key by querying the API const client = createGraphQLClient(apiKey)