earendil-works/pi · error

Missing code or state parameter.

Error message

Missing code or state parameter.

What it means

Not an exception: body of the HTTP 400 page the local callback server returns when the redirect is missing the `code` or `state` query parameter required to exchange for tokens. Without both values the OAuth handshake cannot continue, so the server answers the browser with an error page and leaves the flow unresolved.

Solutions

  1. The callback missed the code or state parameter; restart the OAuth flow from the beginning.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at packages/ai/src/auth/oauth/anthropic.ts:133 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/e9b675ffaeb14563. Report an issue: GitHub.

Appendix: source

Thrown at packages/ai/src/auth/oauth/anthropic.ts:133

				const url = new URL(req.url || "", "http://localhost");
				if (url.pathname !== CALLBACK_PATH) {
					res.writeHead(404, { "Content-Type": "text/html; charset=utf-8" });
					res.end(oauthErrorHtml("Callback route not found."));
					return;
				}

				const code = url.searchParams.get("code");
				const state = url.searchParams.get("state");
				const error = url.searchParams.get("error");

				if (error) {
					res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
					res.end(oauthErrorHtml("Anthropic authentication did not complete.", `Error: ${error}`));
					return;
				}

				if (!code || !state) {
					res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
					res.end(oauthErrorHtml("Missing code or state parameter."));
					return;
				}

				if (state !== expectedState) {
					res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
					res.end(oauthErrorHtml("State mismatch."));
					return;
				}

				res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
				res.end(oauthSuccessHtml("Anthropic authentication completed. You can close this window."));
				settleWait?.({ code, state });
			} catch {
				res.writeHead(500, { "Content-Type": "text/plain; charset=utf-8" });
				res.end("Internal error");
			}
		});

View on GitHub (pinned to 4af9d21d3b)