The best way to control Claude Code, Codex and more from any computer or phone
| 1 | const AGENT_EMAILS = new Set([ |
| 2 | "noreply@anthropic.com", |
| 3 | "claude@anthropic.com", |
| 4 | "noreply@openai.com", |
| 5 | "codex@openai.com", |
| 6 | "cursoragent@cursor.com", |
| 7 | "copilot@github.com", |
| 8 | "noreply@github.com", |
| 9 | ]); |
| 10 | |
| 11 | const GENERATED_BY_AGENT = |
| 12 | /^(?:🤖\s*)?generated (?:with|by)\s+(?:claude(?: code)?|codex|cursor|github copilot|copilot|opencode|grok|antigravity)[.!]?$/i; |
| 13 | |
| 14 | const CO_AUTHOR_PREFIX = /^co-authored-by:/i; |
| 15 | |
| 16 | function isAgentAuthor(text: string): boolean { |
| 17 | const prefix = CO_AUTHOR_PREFIX.exec(text); |
| 18 | if (prefix === null || !text.endsWith(">")) return false; |
| 19 | const emailStart = text.lastIndexOf("<"); |
| 20 | if (emailStart < prefix[0].length) return false; |
| 21 | const email = text.slice(emailStart + 1, -1).toLowerCase(); |
| 22 | if (!AGENT_EMAILS.has(email)) return false; |
| 23 | // GitHub's generic noreply address is also used by people; require Copilot's name. |
| 24 | return ( |
| 25 | email !== "noreply@github.com" || |
| 26 | /^(?:github )?copilot$/i.test(text.slice(prefix[0].length, emailStart).trim()) |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | export function removeAgentCredits(message: string): string { |
| 31 | let fence: string | undefined; |
| 32 | let removed = false; |
| 33 | const newline = message.includes("\r\n") ? "\r\n" : "\n"; |
| 34 | const lines = message.split(/\r?\n/).filter((line) => { |
| 35 | if (/^(?: {4}|\t)/.test(line)) return true; |
| 36 | const delimiter = /^ {0,3}(`{3,}|~{3,})(.*)$/.exec(line); |
| 37 | const marker = delimiter?.[1]; |
| 38 | const remainder = delimiter?.[2] ?? ""; |
| 39 | if (marker !== undefined) { |
| 40 | if (fence === undefined) { |
| 41 | if (marker[0] === "~" || !remainder.includes("`")) fence = marker; |
| 42 | } else if ( |
| 43 | marker[0] === fence[0] && |
| 44 | marker.length >= fence.length && |
| 45 | /^[ \t]*$/.test(remainder) |
| 46 | ) { |
| 47 | fence = undefined; |
| 48 | } |
| 49 | return true; |
| 50 | } |
| 51 | if (fence !== undefined) return true; |
| 52 | const text = line.trim().replace(/^(?:[-*]\s+)/, ""); |
| 53 | if (!isAgentAuthor(text)) { |
| 54 | const footer = text.replace( |
| 55 | /\[([^[\]\r\n]+)\]\(https:\/\/(?:claude\.ai|claude\.com|www\.anthropic\.com|chatgpt\.com|openai\.com|cursor\.com|github\.com|opencode\.ai|x\.ai|antigravity\.google)(?:\/[^\s)[\]]*)?\)/gi, |
| 56 | "$1", |
| 57 | ); |
| 58 | if (!GENERATED_BY_AGENT.test(footer)) return true; |
| 59 | } |
| 60 | removed = true; |
| 61 | return false; |
| 62 | }); |
| 63 | if (!removed) return message; |
| 64 | while (lines.length > 1 && /^[ \t]*$/.test(lines.at(-1)!)) { |
| 65 | lines.pop(); |
| 66 | } |
| 67 | return lines.join(newline); |
| 68 | } |