From acc9bbcd9301e58e7b70e7315fb3af6c971cd74b Mon Sep 17 00:00:00 2001 From: Valentin Fedoskin Date: Sun, 1 Nov 2026 15:01:18 +0000 Subject: [PATCH] fix(plugin): label custom providers that extend Claude The hook matched the provider ID "claude" only, so agents on custom providers declared with `extends: "claude"` (e.g. "claude-work") never got the entrypoint label. Resolve the provider type by following the configured `extends` chain through `paseo.config.get()`. The built-in provider keeps its fast path, cycles end the walk, and a config read failure leaves the session unchanged instead of failing the open. Co-Authored-By: Claude Opus 5.5 --- OVERVIEW.md | 2 +- README.md | 2 +- index.server.ts | 33 ++++++++++-- server/entrypoint.test.ts | 106 ++++++++++++++++++++++++++++++-------- 4 files changed, 116 insertions(+), 27 deletions(-) diff --git a/OVERVIEW.md b/OVERVIEW.md index 0ad3a93..1c5c12a 100644 --- a/OVERVIEW.md +++ b/OVERVIEW.md @@ -1,4 +1,4 @@ -When installed and enabled, this plugin adds `CLAUDE_CODE_ENTRYPOINT=Paseo` to Claude agents each time a session opens. Other providers are unchanged. There are no additional settings. +When installed and enabled, this plugin adds `CLAUDE_CODE_ENTRYPOINT=Paseo` to Claude agents each time a session opens, including agents on custom providers that extend `claude`. Other providers are unchanged. There are no additional settings. This is an optional community workaround for [Claude Code issue #97074](https://github.com/anthropics/claude-code/issues/97074). diff --git a/README.md b/README.md index 7c2a6a3..b9c0946 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Claude Code entrypoint environment -When installed and enabled, this plugin adds `CLAUDE_CODE_ENTRYPOINT=Paseo` to Claude agents each time a session opens. Other providers are unchanged. +When installed and enabled, this plugin adds `CLAUDE_CODE_ENTRYPOINT=Paseo` to Claude agents each time a session opens, including agents on custom providers that extend `claude`. Other providers are unchanged. This is an optional community workaround for [Claude Code issue #97074](https://github.com/anthropics/claude-code/issues/97074). diff --git a/index.server.ts b/index.server.ts index 417cccb..9bc9c9d 100644 --- a/index.server.ts +++ b/index.server.ts @@ -1,8 +1,35 @@ -import type { PluginServerContext } from "@getpaseo/plugin/server"; +import type { PluginHookContext, PluginServerContext } from "@getpaseo/plugin/server"; + +const CLAUDE_PROVIDER = "claude"; + +type ProviderEntries = Record; + +// Custom providers may extend Claude under any ID (e.g. "claude-work"), so +// follow the configured `extends` chain to the built-in provider type. +async function isClaudeProvider(provider: string, paseo: PluginHookContext["paseo"]) { + if (provider === CLAUDE_PROVIDER) return true; + let providers: ProviderEntries; + try { + providers = ((await paseo.config.get()).config.providers ?? {}) as ProviderEntries; + } catch { + // Never block a session open because the label could not be resolved. + return false; + } + const seen = new Set(); + let id = provider; + while (!seen.has(id)) { + seen.add(id); + const base = providers[id]?.extends; + if (typeof base !== "string") return false; + if (base === CLAUDE_PROVIDER) return true; + id = base; + } + return false; +} export default function contribute(server: PluginServerContext) { - return server.before("agent.session_open", ({ request }) => { - if (request.provider !== "claude") return; + return server.before("agent.session_open", async ({ request }, { paseo }) => { + if (!(await isClaudeProvider(request.provider, paseo))) return; return { ...request, env: { ...request.env, CLAUDE_CODE_ENTRYPOINT: "Paseo" }, diff --git a/server/entrypoint.test.ts b/server/entrypoint.test.ts index 9b77f22..28549cb 100644 --- a/server/entrypoint.test.ts +++ b/server/entrypoint.test.ts @@ -1,15 +1,22 @@ import assert from "node:assert/strict"; import { test } from "node:test"; -import type { PluginServerContext, PluginSessionOpenRequest } from "@getpaseo/plugin/server"; +import type { + PluginHookContext, + PluginServerContext, + PluginSessionOpenRequest, +} from "@getpaseo/plugin/server"; import contribute from "../index.server.ts"; -test("labels every Claude opening, preserves other fields and unregisters on cleanup", async () => { - let handler: - | ((input: { request: PluginSessionOpenRequest }) => PluginSessionOpenRequest | void) - | undefined; +type Handler = ( + input: { request: PluginSessionOpenRequest }, + context: PluginHookContext, +) => Promise; + +function register() { + let handler: Handler | undefined; let removed = false; const server = { - before(name: string, callback: typeof handler) { + before(name: string, callback: Handler) { assert.equal(name, "agent.session_open"); handler = callback; return () => { @@ -19,23 +26,78 @@ test("labels every Claude opening, preserves other fields and unregisters on cle } as unknown as PluginServerContext; const cleanup = contribute(server); assert.ok(handler); + return { handler, cleanup: () => (cleanup(), removed) }; +} + +function contextWith(providers: Record | Error) { + let calls = 0; + const context = { + signal: new AbortController().signal, + paseo: { + config: { + async get() { + calls += 1; + if (providers instanceof Error) throw providers; + return { requestId: "r", config: { providers } }; + }, + }, + }, + } as unknown as PluginHookContext; + return { context, calls: () => calls }; +} + +function opening(provider: string, reason: PluginSessionOpenRequest["reason"] = "create") { + return { + agentId: "agent", + workspaceId: null, + provider, + cwd: "/project", + reason, + purpose: "interactive", + env: { UNRELATED: "keep", CLAUDE_CODE_ENTRYPOINT: "sdk-cli" }, + } satisfies PluginSessionOpenRequest; +} + +const labelled = { UNRELATED: "keep", CLAUDE_CODE_ENTRYPOINT: "Paseo" }; + +test("labels every built-in Claude opening without reading config, and unregisters on cleanup", async () => { + const { handler, cleanup } = register(); + const { context, calls } = contextWith({}); for (const reason of ["create", "resume", "refresh", "import"] as const) { - const request: PluginSessionOpenRequest = { - agentId: "agent", - workspaceId: null, - provider: "claude", - cwd: "/project", - reason, - purpose: "interactive", - env: { UNRELATED: "keep", CLAUDE_CODE_ENTRYPOINT: "sdk-cli" }, - }; - assert.deepEqual(handler({ request }), { - ...request, - env: { UNRELATED: "keep", CLAUDE_CODE_ENTRYPOINT: "Paseo" }, - }); + const request = opening("claude", reason); + assert.deepEqual(await handler({ request }, context), { ...request, env: labelled }); assert.equal(request.env.CLAUDE_CODE_ENTRYPOINT, "sdk-cli"); - assert.equal(handler({ request: { ...request, provider: "codex" } }), undefined); } - cleanup(); - assert.equal(removed, true); + assert.equal(calls(), 0); + assert.equal(cleanup(), true); +}); + +test("labels custom providers that extend Claude, directly or through a chain", async () => { + const { handler } = register(); + const { context } = contextWith({ + "claude-work": { extends: "claude" }, + "claude-team": { extends: "claude-work" }, + }); + for (const provider of ["claude-work", "claude-team"]) { + const request = opening(provider); + assert.deepEqual(await handler({ request }, context), { ...request, env: labelled }); + } +}); + +test("leaves other provider types unchanged, whatever their ID", async () => { + const { handler } = register(); + const { context } = contextWith({ + "claude-like-codex": { extends: "codex" }, + "loop-a": { extends: "loop-b" }, + "loop-b": { extends: "loop-a" }, + }); + for (const provider of ["codex", "claude-like-codex", "unknown", "loop-a"]) { + assert.equal(await handler({ request: opening(provider) }, context), undefined); + } +}); + +test("never blocks a session open when the config cannot be read", async () => { + const { handler } = register(); + const { context } = contextWith(new Error("daemon unavailable")); + assert.equal(await handler({ request: opening("claude-work") }, context), undefined); });