Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Relay: tag Claude Desktop sessions and Claude Code in Cursor (Mac #191, #120)

Claude7262361cfe14
diff --git a/windows/hook/src/main.rs b/windows/hook/src/main.rs
index 4cd62465..7ceac101 100644
--- a/windows/hook/src/main.rs
+++ b/windows/hook/src/main.rs
@@ -174,8 +174,15 @@ fn read_event() -> Option<(String, String, Option<serde_json::Value>)> {
}
// Which agent this hook was installed for. Absent means Claude Code,
// so existing hook commands keep working unchanged.
- if !agent.is_empty() {
- map.insert("coucou_agent".into(), serde_json::Value::String(agent));
+ let env = |name: &str| std::env::var(name).ok();
+ if let Some(tag) = agent_tag(&agent, &env) {
+ map.insert("coucou_agent".into(), serde_json::Value::String(tag));
+ }
+ // Claude Code in Cursor's terminal goes on the Cursor pill (Mac #120).
+ if !map.contains_key("term_editor") {
+ if let Some(editor) = term_editor(&env) {
+ map.insert("term_editor".into(), serde_json::Value::String(editor.into()));
+ }
}
let event = map
.get("hook_event_name")
@@ -231,6 +238,30 @@ fn read_event() -> Option<(String, String, Option<serde_json::Value>)> {
Some((line, event, question))
}
+/// The `coucou_agent` tag: `--agent` when given, otherwise `claude-desktop` for
+/// a Claude Code session started from the Claude desktop app, which says so in
+/// CLAUDE_CODE_ENTRYPOINT — the same rule as the Mac's relay (#191). Nothing
+/// for a plain Claude Code session.
+fn agent_tag(arg: &str, env: &dyn Fn(&str) -> Option<String>) -> Option<String> {
+ if !arg.is_empty() {
+ return Some(arg.to_string());
+ }
+ (env("CLAUDE_CODE_ENTRYPOINT").as_deref() == Some("claude-desktop"))
+ .then(|| "claude-desktop".to_string())
+}
+
+/// `cursor` when the session runs in Cursor's integrated terminal. Cursor sets
+/// TERM_PROGRAM=vscode like VS Code does, so it is told apart by its own trace
+/// variable, or by its executable behind VS Code's git helper.
+fn term_editor(env: &dyn Fn(&str) -> Option<String>) -> Option<&'static str> {
+ if env("CURSOR_TRACE_ID").is_some_and(|v| !v.is_empty()) {
+ return Some("cursor");
+ }
+ let helper = env("VSCODE_GIT_ASKPASS_NODE").unwrap_or_default();
+ let exe = helper.rsplit(['/', '\\']).next().unwrap_or_default().to_ascii_lowercase();
+ exe.starts_with("cursor").then_some("cursor")
+}
+
/// Caps every string in the payload. A single Write can carry a whole file.
fn truncate_strings(value: &mut serde_json::Value) {
match value {
@@ -352,6 +383,40 @@ mod tests {
assert!(!ok(r#"{"answers":{"Which one?":"A","Extras?":["Tests","Tests"]}}"#));
}
+ fn env_of(vars: &'static [(&'static str, &'static str)]) -> impl Fn(&str) -> Option<String> {
+ move |name| vars.iter().find(|(k, _)| *k == name).map(|(_, v)| v.to_string())
+ }
+
+ #[test]
+ fn claude_desktop_sessions_are_tagged_and_an_explicit_agent_wins() {
+ let desktop = env_of(&[("CLAUDE_CODE_ENTRYPOINT", "claude-desktop")]);
+ assert_eq!(agent_tag("", &desktop).as_deref(), Some("claude-desktop"));
+ assert_eq!(agent_tag("gemini", &desktop).as_deref(), Some("gemini"));
+ assert_eq!(agent_tag("", &env_of(&[("CLAUDE_CODE_ENTRYPOINT", "cli")])), None);
+ assert_eq!(agent_tag("", &env_of(&[])), None);
+ }
+
+ #[test]
+ fn cursor_is_told_apart_from_vs_code() {
+ assert_eq!(term_editor(&env_of(&[("CURSOR_TRACE_ID", "abc")])), Some("cursor"));
+ assert_eq!(
+ term_editor(&env_of(&[(
+ "VSCODE_GIT_ASKPASS_NODE",
+ r"C:\Users\me\AppData\Local\Programs\cursor\Cursor.exe"
+ )])),
+ Some("cursor")
+ );
+ assert_eq!(
+ term_editor(&env_of(&[(
+ "VSCODE_GIT_ASKPASS_NODE",
+ r"C:\Users\me\AppData\Local\Programs\Microsoft VS Code\Code.exe"
+ )])),
+ None
+ );
+ assert_eq!(term_editor(&env_of(&[("CURSOR_TRACE_ID", "")])), None);
+ assert_eq!(term_editor(&env_of(&[("TERM_PROGRAM", "vscode")])), None);
+ }
+
#[test]
fn long_strings_are_cut_on_a_char_boundary() {
let mut v = serde_json::json!({ "tool_input": { "content": "é".repeat(4000) } });
diff --git a/windows/tests/hooks.test.mjs b/windows/tests/hooks.test.mjs
index b5e2f7b5..a3bd45ff 100644
--- a/windows/tests/hooks.test.mjs
+++ b/windows/tests/hooks.test.mjs
@@ -248,6 +248,17 @@ test("an agent's permission request is declined, never shown as Claude Code's",
assert.equal(State.pendingApproval, null);
});
+test("a Claude Desktop session gets the Claude Desktop pill, in its colour (Mac #191)", () => {
+ hook({ hook_event_name: "SessionStart", cwd: "C:\\p\\proj", session_id: "d1", coucou_agent: "claude-desktop" });
+ const desktop = task("agent_claude-desktop");
+ assert.equal(desktop.color, "#D97757");
+ assert.equal(desktop.sessionId, "d1");
+ assert.equal(task().state, "idle");
+ // Its permission requests are answered in the app, as on macOS.
+ hook({ hook_event_name: "PermissionRequest", request_id: "r1", coucou_agent: "claude-desktop", tool_name: "Bash" });
+ assert.deepEqual(sent("approval_decline"), [{ requestId: "r1" }]);
+});
+
// ── Main tool and Cursor ──────────────────────────────────────────────────────
test("Claude Code in Cursor's terminal works on the Cursor pill, made for the session", () => {