:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(agent-prompt): add claude desktop, vs code and web destinations (#112270)
Rafael Audibert2591e4d05775
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 88bc8ea9ad40..36e1756d4fe8 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -361,9 +361,9 @@ snapshots:components-agentpromptbutton--intent-variants--light:hash: v1.k794b7964.7cd72aa990fbec4e992fc96aeadda200d3b32aef07768a55be60d66d32b1ab2d.DIfXIxT6_90a_nXyccDqRznEfJNj_79S1Ra7N18TRcscomponents-agentpromptbutton--open-dropdown--dark:- hash: v1.k794b7964.430122253ebce8f26fb0c985b208af119844d7812b375b66d0ba1214a40f9e8e.2bx2pRTjmtJV3PhH8da0aY5Ev_Ds_g9HI8SnDuYmIyE+ hash: v1.k794b7964.153b46a95233b47e0b202af8b19dad387880dbd4f6ade10c0293d6365fdf5f3a.J7L2y9eU4XjaedCiObUsV-PfGCr_tVxzTIozY8NwOSgcomponents-agentpromptbutton--open-dropdown--light:- hash: v1.k794b7964.13385923161772db465f5cd21766bb635e54c133689ee17033ada29f4a16c759.0FhOldA4lZzZy1hC15fvJnDZB_WIcv9MjGJeLlhefSY+ hash: v1.k794b7964.84e96578c87d3761f88c39ab7f835fb27ffc76061993fdb646ed7d2948a1acf6.NuOhZpTJwfsCYGR80joDQN_VV-ReuEjfqQE0feLJsHwcomponents-agentpromptbutton--single-action--dark:hash: v1.k794b7964.3de62fe39a555b2a1394e49e6fb9e3624d593eebf8d903c72f41c3aabf08a4d2.AZAyf_1_T7udzak-JMOobLpzT0Xyjhz2lvlnL3A3sxgcomponents-agentpromptbutton--single-action--light:diff --git a/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.test.ts b/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.test.tsindex f542aaf9e481..eb4cf63e0251 100644--- a/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.test.ts+++ b/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.test.ts@@ -1,10 +1,50 @@-import { buildPostHogCodeDeepLink } from './AgentPromptButton'+import {+ buildClaudeCodeDeepLink,+ buildClaudeCodeWebLink,+ buildClaudeDesktopDeepLink,+ buildCodexDeepLink,+ buildCursorDeepLink,+ buildPostHogCodeDeepLink,+} from './AgentPromptButton'describe('AgentPromptButton', () => {it.each([- ['with a repository', 'posthog/posthog', 'posthog-code://new?prompt=fix%20this&repo=posthog%2Fposthog'],- ['without a repository', undefined, 'posthog-code://new?prompt=fix%20this'],- ])('builds a PostHog Code deep link %s', (_, repository, expected) => {- expect(buildPostHogCodeDeepLink('fix this', repository)).toBe(expected)+ [+ 'PostHog Desktop with a repository',+ buildPostHogCodeDeepLink('fix this', 'posthog/posthog'),+ 'posthog-code://new?prompt=fix%20this&repo=posthog%2Fposthog',+ ],+ [+ 'PostHog Desktop without a repository',+ buildPostHogCodeDeepLink('fix this'),+ 'posthog-code://new?prompt=fix%20this',+ ],+ [+ 'Codex with a repository',+ buildCodexDeepLink('fix this', 'posthog/posthog'),+ 'codex://new?prompt=fix%20this&originUrl=https%3A%2F%2Fgithub.com%2Fposthog%2Fposthog',+ ],+ ['Codex without a repository', buildCodexDeepLink('fix this'), 'codex://new?prompt=fix%20this'],+ ['Claude Desktop', buildClaudeDesktopDeepLink('fix this'), 'claude://code/new?q=fix%20this'],+ [+ 'Claude Code on the web with a repository',+ buildClaudeCodeWebLink('fix this', 'posthog/posthog'),+ 'https://claude.ai/code?prompt=fix%20this&repositories=posthog%2Fposthog',+ ],+ ])('builds a %s link', (_, link, expected) => {+ expect(link).toBe(expected)+ })++ it.each([+ ['Cursor', (prompt: string) => buildCursorDeepLink(prompt), 10_000],+ ['Claude Code on the web', (prompt: string) => buildClaudeCodeWebLink(prompt, 'posthog/posthog'), 8_000],+ ])('keeps the whole %s URL within its length cap when encoding inflates the prompt', (_, build, maxLength) => {+ const link = build('a b/c?'.repeat(5_000))+ expect(link.length).toBeLessThanOrEqual(maxLength)+ expect(link.length).toBeGreaterThan(maxLength - 30)+ })++ it('does not split an emoji when it truncates a prompt at the cap', () => {+ expect(() => buildClaudeCodeDeepLink('a'.repeat(4_999) + '😀')).not.toThrow()})})diff --git a/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx b/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsxindex 3f933d5b0efe..8339b76c08d5 100644--- a/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx+++ b/frontend/src/lib/components/AgentPromptButton/AgentPromptButton.tsx@@ -39,7 +39,16 @@ export interface AgentPromptAction {buildPrompt: () => string}-export type AgentPromptDestination = 'posthog-ai' | 'posthog-code' | 'claude-code' | 'cursor' | 'codex' | 'clipboard'+export type AgentPromptDestination =+ | 'posthog-ai'+ | 'posthog-code'+ | 'claude-code'+ | 'claude-desktop'+ | 'claude-code-vscode'+ | 'claude-code-web'+ | 'cursor'+ | 'codex'+ | 'clipboard'/** Quill button sizes, minus the icon-only variants (the dropdown trigger derives those automatically). */type AgentPromptButtonSize = Exclude<NonNullable<QuillButtonProps['size']>, 'icon' | 'icon-xs' | 'icon-sm' | 'icon-lg'>@@ -66,7 +75,7 @@ export interface AgentPromptButtonProps {defaultOpen?: boolean/** Fired whenever a combo runs (agent deeplink opened or clipboard copied). Useful for analytics. */onRun?: (params: { actionKey: string; agentKey: string }) => void- /** GitHub `owner/repo` slug passed to agents that can open a specific repository (e.g. Claude Code). */+ /** GitHub `owner/repo` slug passed to agents that can open a specific repository (e.g. Claude Code, Codex). */repository?: string'data-attr'?: string}@@ -95,17 +104,46 @@ interface AgentOpenContext {repository?: string}-/** Max prompt chars before truncation for agents that have strict URL length limits. */-const LIMIT_LONG = 8_000-const LIMIT_CLAUDE = 5_000-const LIMIT_SHORT = 4_000+const CLAUDE_CODE_CLI_MAX_PROMPT_CHARS = 5_000+const CLAUDE_DESKTOP_MAX_PROMPT_CHARS = 14_000+/** Cap for apps that document no limit, sized to stay well inside OS URL handler limits. */+const UNDOCUMENTED_MAX_PROMPT_CHARS = 4_000-function withLimit(prompt: string, maxChars: number, build: (p: string) => string): string {- return build(prompt.slice(0, maxChars))+const CURSOR_MAX_URL_LENGTH = 10_000+/** Many web servers reject request lines over about 8 KB with a 414, so the claude.ai link stays under that. */+const CLAUDE_CODE_WEB_MAX_URL_LENGTH = 8_000++function truncatePrompt(prompt: string, maxChars: number): string {+ if (prompt.length <= maxChars) {+ return prompt+ }+ // A cut between the two halves of a surrogate pair (an emoji, for example) leaves a lone+ // surrogate, and encodeURIComponent throws a URIError on it.+ const lastCode = prompt.charCodeAt(maxChars - 1)+ const end = lastCode >= 0xd800 && lastCode <= 0xdbff ? maxChars - 1 : maxChars+ return prompt.slice(0, end)+}++function buildWithinUrlLength(prompt: string, maxUrlLength: number, build: (prompt: string) => string): string {+ const full = build(prompt)+ if (full.length <= maxUrlLength) {+ return full+ }+ let low = 0+ let high = prompt.length+ while (low < high) {+ const mid = Math.ceil((low + high) / 2)+ if (build(truncatePrompt(prompt, mid)).length <= maxUrlLength) {+ low = mid+ } else {+ high = mid - 1+ }+ }+ return build(truncatePrompt(prompt, low))}-function openDeepLink(buildDeepLink: (prompt: string) => string): (prompt: string) => void {- return (prompt: string) => window.open(buildDeepLink(prompt), '_blank')+function openDeepLink(buildDeepLink: (prompt: string, repository?: string) => string): AgentDef['open'] {+ return (prompt, { repository }) => window.open(buildDeepLink(prompt, repository), '_blank')}export function buildPostHogCodeDeepLink(prompt: string, repository?: string): string {@@ -114,23 +152,45 @@ export function buildPostHogCodeDeepLink(prompt: string, repository?: string): s}export function buildClaudeCodeDeepLink(prompt: string, repository?: string): string {- const query = withLimit(prompt, LIMIT_CLAUDE, (text) => encodeURIComponent(text))+ const query = encodeURIComponent(truncatePrompt(prompt, CLAUDE_CODE_CLI_MAX_PROMPT_CHARS))const repoParam = repository ? `repo=${encodeURIComponent(repository)}&` : ''return `claude-cli://open?${repoParam}q=${query}`}+/** The Desktop link takes only an absolute folder path, so it cannot select the repository. */+export function buildClaudeDesktopDeepLink(prompt: string): string {+ return `claude://code/new?q=${encodeURIComponent(truncatePrompt(prompt, CLAUDE_DESKTOP_MAX_PROMPT_CHARS))}`+}++export function buildClaudeCodeVSCodeDeepLink(prompt: string): string {+ return `vscode://anthropic.claude-code/open?prompt=${encodeURIComponent(truncatePrompt(prompt, UNDOCUMENTED_MAX_PROMPT_CHARS))}`+}++export function buildClaudeCodeWebLink(prompt: string, repository?: string): string {+ const repoParam = repository ? `&repositories=${encodeURIComponent(repository)}` : ''+ return buildWithinUrlLength(+ prompt,+ CLAUDE_CODE_WEB_MAX_URL_LENGTH,+ (text) => `https://claude.ai/code?prompt=${encodeURIComponent(text)}${repoParam}`+ )+}+export function buildCursorDeepLink(prompt: string): string {- return withLimit(+ // Cursor decodes the full deeplink before parsing query params, so reserved chars need an extra escape layer.+ return buildWithinUrlLength(prompt,- LIMIT_LONG,+ CURSOR_MAX_URL_LENGTH,(text) => `cursor://anysphere.cursor-deeplink/prompt?text=${encodeURIComponent(encodeURIComponent(text))}`)}-export function buildCodexDeepLink(prompt: string): string {- return withLimit(prompt, LIMIT_SHORT, (text) => `codex://new?prompt=${encodeURIComponent(text)}`)+export function buildCodexDeepLink(prompt: string, repository?: string): string {+ const originParam = repository ? `&originUrl=${encodeURIComponent(`https://github.com/${repository}`)}` : ''+ return `codex://new?prompt=${encodeURIComponent(truncatePrompt(prompt, UNDOCUMENTED_MAX_PROMPT_CHARS))}${originParam}`}+// pinned: each `key` is stored in localStorage and sent as the `agent` analytics property, so renaming one resets+// remembered choices and splits the analytics. Change `name` instead.const AGENTS: AgentDef[] = [{key: 'posthog-ai',@@ -144,14 +204,36 @@ const AGENTS: AgentDef[] = [name: 'PostHog Desktop',logo: <IconLogomark className="size-4 shrink-0" />,verb: 'Open',- open: (prompt, { repository }) => window.open(buildPostHogCodeDeepLink(prompt, repository), '_blank'),+ open: openDeepLink(buildPostHogCodeDeepLink),},{key: 'claude-code',- name: 'Claude Code',+ name: 'Claude Code CLI',+ logo: claudeLogo,+ verb: 'Open',+ open: openDeepLink(buildClaudeCodeDeepLink),+ },+ {+ key: 'claude-desktop',+ name: 'Claude Desktop',+ logo: claudeLogo,+ verb: 'Open',+ open: openDeepLink(buildClaudeDesktopDeepLink),+ },+ {+ key: 'claude-code-vscode',+ name: 'Claude Code in VS Code',+ logo: claudeLogo,+ verb: 'Open',+ open: openDeepLink(buildClaudeCodeVSCodeDeepLink),+ },+ {+ key: 'claude-code-web',+ name: 'Claude Code on the web',logo: claudeLogo,verb: 'Open',- open: (prompt, { repository }) => window.open(buildClaudeCodeDeepLink(prompt, repository), '_blank'),+ open: (prompt, { repository }) =>+ window.open(buildClaudeCodeWebLink(prompt, repository), '_blank', 'noopener,noreferrer'),},{key: 'cursor',@@ -160,7 +242,6 @@ const AGENTS: AgentDef[] = [// Cursor wordmark is solid black; invert in dark mode so it stays visiblelogoClassName: 'dark:invert',verb: 'Open',- // Cursor decodes the full deeplink before parsing query params, so reserved chars need an extra escape layer.open: openDeepLink(buildCursorDeepLink),},{@@ -284,7 +365,7 @@ export function AgentPromptButton({</DropdownMenuTrigger></QuillButtonGroup>- <DropdownMenuContent align="end" className="w-56">+ <DropdownMenuContent align="end" className="w-60 max-w-none">{actions.length > 1 && (<><DropdownMenuLabel>Content</DropdownMenuLabel>diff --git a/frontend/src/lib/components/AgentPromptButton/index.ts b/frontend/src/lib/components/AgentPromptButton/index.tsindex 2304e0faf611..765d125692e8 100644--- a/frontend/src/lib/components/AgentPromptButton/index.ts+++ b/frontend/src/lib/components/AgentPromptButton/index.ts@@ -2,6 +2,9 @@ export type { AgentPromptAction, AgentPromptButtonProps, AgentPromptDestinationexport {AgentPromptButton,buildClaudeCodeDeepLink,+ buildClaudeCodeVSCodeDeepLink,+ buildClaudeCodeWebLink,+ buildClaudeDesktopDeepLink,buildCodexDeepLink,buildCursorDeepLink,buildPostHogCodeDeepLink,diff --git a/frontend/src/lib/components/Git/gitMetadataParser.spec.ts b/frontend/src/lib/components/Git/gitMetadataParser.spec.tsindex 63c15a9209fa..0ff93905ac42 100644--- a/frontend/src/lib/components/Git/gitMetadataParser.spec.ts+++ b/frontend/src/lib/components/Git/gitMetadataParser.spec.ts@@ -56,4 +56,28 @@ describe('GitMetadataParser', () => {expect(result).toBe(expected)})})++ describe('getGitHubRepositorySlug', () => {+ it.each([+ {+ description: 'SSH GitHub remote',+ remote_url: '[email protected]:PostHog/posthog.git',+ expected: 'PostHog/posthog',+ },+ {+ description: 'HTTPS GitHub remote',+ remote_url: 'https://github.com/PostHog/posthog.git',+ expected: 'PostHog/posthog',+ },+ { description: 'GitLab remote', remote_url: '[email protected]:group/project.git', expected: undefined },+ {+ description: 'remote with a credential',+ remote_url: 'https://x-access-token:[email protected]/PostHog/posthog.git',+ expected: undefined,+ },+ { description: 'missing remote', remote_url: undefined, expected: undefined },+ ])('returns the slug for a $description', ({ remote_url, expected }) => {+ expect(GitMetadataParser.getGitHubRepositorySlug(remote_url)).toBe(expected)+ })+ })})diff --git a/frontend/src/lib/components/Git/gitMetadataParser.ts b/frontend/src/lib/components/Git/gitMetadataParser.tsindex 08375095c49b..6c6f198438c9 100644--- a/frontend/src/lib/components/Git/gitMetadataParser.ts+++ b/frontend/src/lib/components/Git/gitMetadataParser.ts@@ -8,6 +8,8 @@ export type ParsedRemoteUrl = {providerUrl: string | undefined}+const GITHUB_SLUG_PATTERN = /^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/+export class GitMetadataParser {static getCommitLink(remote_url?: string, commit_id?: string): string | undefined {if (!commit_id || !remote_url) {@@ -42,6 +44,18 @@ export class GitMetadataParser {return this.buildRemoteLink(parsedRemoteUrl)}+ static getGitHubRepositorySlug(remote_url?: string): string | undefined {+ if (!remote_url) {+ return undefined+ }+ const parsedRemoteUrl = this.parseRemoteUrl(remote_url)+ if (parsedRemoteUrl?.provider !== 'github') {+ return undefined+ }+ const slug = `${parsedRemoteUrl.owner}/${parsedRemoteUrl.repository}`+ return GITHUB_SLUG_PATTERN.test(slug) ? slug : undefined+ }+static parseRemoteUrl(remoteUrl: string): ParsedRemoteUrl | undefined {return this.parseSshRemoteUrl(remoteUrl) || this.parseHttpsRemoteUrl(remoteUrl)}diff --git a/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.tsx b/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.tsxindex af4554c904ba..b9a675afd889 100644--- a/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.tsx+++ b/products/error_tracking/frontend/components/ExceptionCard/Tabs/StackTraceTab/StackTraceActions.tsx@@ -5,7 +5,6 @@ import { IconCode, IconInfo, IconWrench } from '@posthog/icons'import { AgentPromptButton } from 'lib/components/AgentPromptButton'import { errorPropertiesLogic } from 'lib/components/Errors/errorPropertiesLogic'-import { ErrorTrackingRelease } from 'lib/components/Errors/types'import { GitMetadataParser } from 'lib/components/Git/gitMetadataParser'import { ErrorTrackingRelationalIssue } from '~/queries/schema/schema-general'@@ -17,18 +16,6 @@ export interface StackTraceActionsProps {issue: ErrorTrackingRelationalIssue}-function getReleaseRepository(release?: ErrorTrackingRelease | null): string | undefined {- const git = release?.metadata?.git- if (!git) {- return undefined- }- if (git.repo_name) {- return git.repo_name- }- const parsedRemoteUrl = git.remote_url ? GitMetadataParser.parseRemoteUrl(git.remote_url) : undefined- return parsedRemoteUrl ? `${parsedRemoteUrl.owner}/${parsedRemoteUrl.repository}` : undefined-}-export function StackTraceActions({ issue }: StackTraceActionsProps): JSX.Element {const { exceptionList, release } = useValues(errorPropertiesLogic)const { copyableStacktraceText, ready, stacktraceText } = useStacktraceDisplay()@@ -42,7 +29,7 @@ export function StackTraceActions({ issue }: StackTraceActionsProps): JSX.ElemendefaultAgentKey="clipboard"size="sm"data-attr="error-tracking-fix-with-ai"- repository={getReleaseRepository(release)}+ repository={GitMetadataParser.getGitHubRepositorySlug(release?.metadata?.git?.remote_url)}actions={[{key: 'fix',diff --git a/products/signals/frontend/inbox/components/detail/ImplementButton.test.tsx b/products/signals/frontend/inbox/components/detail/ImplementButton.test.tsxindex fc6526490831..280d0c1c09b9 100644--- a/products/signals/frontend/inbox/components/detail/ImplementButton.test.tsx+++ b/products/signals/frontend/inbox/components/detail/ImplementButton.test.tsx@@ -163,7 +163,7 @@ describe('ImplementButton', () => {await user.click(screen.getByLabelText('Open prompt in an agent'))expect(screen.queryByText('PostHog AI')).not.toBeInTheDocument()- await user.click(screen.getByText('Claude Code'))+ await user.click(screen.getByText('Claude Code CLI'))expect(open).toHaveBeenCalledWith(expect.stringMatching(/^claude-cli:\/\/open\?q=/), '_blank')expect(captureInboxReportAction).toHaveBeenCalledWith(diff --git a/products/signals/frontend/inbox/components/detail/ImplementButton.tsx b/products/signals/frontend/inbox/components/detail/ImplementButton.tsxindex 108f4ffafd46..48bcafc37e83 100644--- a/products/signals/frontend/inbox/components/detail/ImplementButton.tsx+++ b/products/signals/frontend/inbox/components/detail/ImplementButton.tsx@@ -6,6 +6,9 @@ import { LemonButton, LemonMenuOverlay, lemonToast } from '@posthog/lemon-ui'import {buildClaudeCodeDeepLink,+ buildClaudeCodeVSCodeDeepLink,+ buildClaudeCodeWebLink,+ buildClaudeDesktopDeepLink,buildCodexDeepLink,buildCursorDeepLink,buildPostHogCodeDeepLink,@@ -28,35 +31,57 @@ const SLOT_CLAIM_DISABLED_REASON: Record<ImplementationSlotClaim, string> = {shipped_pr: 'This report already has a pull request. Open it in the task log to continue it.',}+function openDeepLink(buildDeepLink: (prompt: string) => string): (prompt: string) => void {+ return (prompt) => window.open(buildDeepLink(prompt), '_blank')+}+const IMPLEMENTATION_AGENTS: {key: AgentPromptDestinationname: stringicon: JSX.Element- buildDeepLink: (prompt: string) => string+ open: (prompt: string) => void}[] = [{key: 'posthog-code',name: 'PostHog Desktop',icon: <IconLogomark />,- buildDeepLink: buildPostHogCodeDeepLink,+ open: openDeepLink(buildPostHogCodeDeepLink),},{key: 'claude-code',- name: 'Claude Code',+ name: 'Claude Code CLI',+ icon: <AgentLogo logo={claudeLogo} />,+ open: openDeepLink(buildClaudeCodeDeepLink),+ },+ {+ key: 'claude-desktop',+ name: 'Claude Desktop',+ icon: <AgentLogo logo={claudeLogo} />,+ open: openDeepLink(buildClaudeDesktopDeepLink),+ },+ {+ key: 'claude-code-vscode',+ name: 'Claude Code in VS Code',+ icon: <AgentLogo logo={claudeLogo} />,+ open: openDeepLink(buildClaudeCodeVSCodeDeepLink),+ },+ {+ key: 'claude-code-web',+ name: 'Claude Code on the web',icon: <AgentLogo logo={claudeLogo} />,- buildDeepLink: buildClaudeCodeDeepLink,+ open: (prompt) => window.open(buildClaudeCodeWebLink(prompt), '_blank', 'noopener,noreferrer'),},{key: 'cursor',name: 'Cursor',icon: <AgentLogo logo={cursorLogo} logoClassName="dark:invert" />,- buildDeepLink: buildCursorDeepLink,+ open: openDeepLink(buildCursorDeepLink),},{key: 'codex',name: 'Codex',icon: <AgentLogo logo={openaiLogo} />,- buildDeepLink: buildCodexDeepLink,+ open: openDeepLink(buildCodexDeepLink),},]@@ -182,10 +207,7 @@ export function ImplementButton({ report }: { report: SignalReport }): JSX.Elemekey: agent.key,label: agent.name,icon: agent.icon,- onClick: () =>- runImplementationPrompt(agent.key, (prompt) => {- window.open(agent.buildDeepLink(prompt), '_blank')- }),+ onClick: () => runImplementationPrompt(agent.key, agent.open),}))}/>),