Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/vscode-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- **Import a chat from claude.ai** in the AI Agents section: paste the claude.ai/code link and Code-XR brings the session into the folder with `claude --teleport`, branch included.
- Right-click a Claude Code session of the workspace: **Continue on claude.ai** (Remote Control, after you confirm) or **Continue in the terminal**.
- Remote Control needs a claude.ai sign-in, not an API key. Nothing is shared until you confirm.
- **Continue sessions on claude.ai automatically** in the AI Agents section: one switch, after one confirmation, turns on Claude Code's own `remoteControlAtStartup`, so every Claude Code session (VS Code, terminal, Claude Desktop, Code-XR IDE) is reachable from claude.ai/code and the mobile app without any extra step. Off by default.
- **Agent Flow, the fifth analysis type.** Watch an AI coding agent work on the XR analysis table.
- The project is a city: folders are plates, files are buildings.
- Every agent is a worker. Sub-agents get their own worker and work in parallel.
Expand Down
4 changes: 4 additions & 0 deletions apps/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@
"command": "codeXR.claudeSessions.continueOnClaudeAi",
"title": "Code-XR: Continue a Claude Code Chat on claude.ai (Remote Control)"
},
{
"command": "codeXR.claudeSessions.toggleAutoRemoteControl",
"title": "Code-XR: Continue Claude Code Sessions on claude.ai Automatically (On/Off)"
},
{
"command": "codeXR.claudeSessions.continueInTerminal",
"title": "Code-XR: Continue a Claude Code Chat in the Terminal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,75 @@ export const REMOTE_CONTROL_CONSENT =
export const TELEPORT_HINT =
'Claude Code copies the claude.ai/code session into this folder (its conversation and its branch). It needs the same repository, a clean git tree and the branch pushed. '
+ 'When it is done, quit Claude Code in the terminal; the chat is then in this folder\'s Claude Code history.';

// ---- #456: automatic continuity (Remote Control at startup) -----------------

/** How a host treats Remote Control for its Claude Code chats: ask once, always on, or never. */
export const AUTO_REMOTE_CONTROL_MODES = ['ask', 'always', 'never'] as const;
export type AutoRemoteControlMode = (typeof AUTO_REMOTE_CONTROL_MODES)[number];

export function isAutoRemoteControlMode(value: unknown): value is AutoRemoteControlMode {
return typeof value === 'string' && (AUTO_REMOTE_CONTROL_MODES as readonly string[]).includes(value);
}

/** Claude Code's own setting: start Remote Control with every session. */
export const REMOTE_CONTROL_AT_STARTUP = 'remoteControlAtStartup';

/**
* The ACP `_meta` that makes Claude Code's adapter start Remote Control with
* this session only (`session/new` and `session/load`), as the setting would
* for all of them. The adapter then sends a `Remote Control connected` notice
* with the claude.ai link. Null when Remote Control is not wanted.
*/
export function remoteControlSessionMeta(on: boolean): { claudeCode: { options: { settings: Record<string, boolean> } } } | null {
return on ? { claudeCode: { options: { settings: { [REMOTE_CONTROL_AT_STARTUP]: true } } } } : null;
}

/** The one-time question a host asks before it shares chats automatically. */
export const AUTO_REMOTE_CONTROL_QUESTION = 'Continue your Claude Code chats on claude.ai automatically?';

export const AUTO_REMOTE_CONTROL_CONSENT =
'Every Claude Code chat will start with Remote Control, so you can open it from claude.ai/code or the Claude mobile app, signed in with the same Claude account, without pressing anything. '
+ 'The code keeps running on this computer; messages and tool results travel through Anthropic\'s servers. It needs a claude.ai sign-in (Pro, Max, Team or Enterprise), not an API key. '
+ 'You can change it at any time in the settings, and stop sharing any single chat.';

/**
* #456: Claude Code's `settings.json` with `remoteControlAtStartup` set (`on`)
* or removed, every other key kept. `text` is the file's content, or null when
* it does not exist. Throws on a file that is not a JSON object, so a host
* never overwrites settings it could not read.
*/
export function withRemoteControlAtStartup(text: string | null, on: boolean): string {
let settings: Record<string, unknown> = {};
if (text !== null && text.trim() !== '') {
let parsed: unknown;
try {
parsed = JSON.parse(text);
} catch {
throw new Error('Claude Code\'s settings.json is not valid JSON; fix it first.');
}
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new Error('Claude Code\'s settings.json is not a JSON object; fix it first.');
}
settings = { ...(parsed as Record<string, unknown>) };
}
if (on) {
settings[REMOTE_CONTROL_AT_STARTUP] = true;
} else {
delete settings[REMOTE_CONTROL_AT_STARTUP];
}
return `${JSON.stringify(settings, null, 2)}\n`;
}

/** Whether Claude Code's `settings.json` text turns Remote Control on for every session. */
export function remoteControlAtStartupIn(text: string | null): boolean {
if (!text) {
return false;
}
try {
const parsed: unknown = JSON.parse(text);
return !!parsed && typeof parsed === 'object' && (parsed as Record<string, unknown>)[REMOTE_CONTROL_AT_STARTUP] === true;
} catch {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as vscode from 'vscode';
import { ExtensionCommandRegistration } from '../../../platform/commands/commandRegistry';
import {
AUTO_REMOTE_CONTROL_CONSENT,
AUTO_REMOTE_CONTROL_QUESTION,
REMOTE_CONTROL_CONSENT,
remoteControlAtStartupIn,
withRemoteControlAtStartup,
TELEPORT_HINT,
commandLine,
isLocalSessionId,
Expand All @@ -23,6 +30,52 @@ import { agentFlowWorkspaceRoot, describeAge, listWorkspaceAgentSessions } from
export const IMPORT_FROM_WEB_COMMAND = 'codeXR.claudeSessions.importFromWeb';
export const CONTINUE_ON_CLAUDE_AI_COMMAND = 'codeXR.claudeSessions.continueOnClaudeAi';
export const CONTINUE_IN_TERMINAL_COMMAND = 'codeXR.claudeSessions.continueInTerminal';
export const TOGGLE_AUTO_REMOTE_CONTROL_COMMAND = 'codeXR.claudeSessions.toggleAutoRemoteControl';

/**
* #456: Claude Code's user settings file. Its `remoteControlAtStartup` is the
* single source of truth for "every Claude Code session continues on
* claude.ai": the extension does not host chats, so it turns Claude Code's own
* switch on or off rather than keeping a setting of its own.
*/
export function claudeSettingsFile(env: NodeJS.ProcessEnv = process.env, home = os.homedir()): string {
return path.join(env['CLAUDE_CONFIG_DIR'] || path.join(home, '.claude'), 'settings.json');
}

function readClaudeSettings(file: string): string | null {
try {
return fs.readFileSync(file, 'utf8');
} catch {
return null;
}
}

/** Whether every Claude Code session starts with Remote Control (Claude Code's own setting). */
export function autoRemoteControlEnabled(file = claudeSettingsFile()): boolean {
return remoteControlAtStartupIn(readClaudeSettings(file));
}

/** Turns Claude Code's `remoteControlAtStartup` on (after consent) or off, keeping every other setting. */
export async function toggleAutoRemoteControl(file = claudeSettingsFile()): Promise<void> {
const on = !autoRemoteControlEnabled(file);
if (on) {
const go = await vscode.window.showWarningMessage(
AUTO_REMOTE_CONTROL_QUESTION,
{ modal: true, detail: `${AUTO_REMOTE_CONTROL_CONSENT}\n\nCode-XR turns on Claude Code's own "remoteControlAtStartup" in ${file}, so it applies to every Claude Code session: in this editor, the terminal, Claude Desktop and the Code-XR IDE.` },
'Turn on',
);
if (go !== 'Turn on') {
return;
}
}
const next = withRemoteControlAtStartup(readClaudeSettings(file), on);
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, next, 'utf8');
void vscode.commands.executeCommand('codeXR.modularTree.refresh');
void vscode.window.showInformationMessage(on
? 'Claude Code sessions now start with Remote Control: open them from claude.ai/code or the Claude mobile app. Sessions already running pick it up when they start again.'
: 'Claude Code sessions no longer start with Remote Control.');
}

const CLAUDE_SOURCE_PREFIX = 'claude-code:';

Expand Down Expand Up @@ -162,6 +215,13 @@ export function getClaudeSessionCommandRegistrations(): ExtensionCommandRegistra
handler: (arg?: unknown) => continueOnClaudeAi(arg),
errorMessage: 'The chat could not be shared with claude.ai',
},
{
id: TOGGLE_AUTO_REMOTE_CONTROL_COMMAND,
module: 'AI_AGENTS',
description: 'Turn Claude Code\'s Remote Control at startup on or off, so every session continues on claude.ai automatically',
handler: () => toggleAutoRemoteControl(),
errorMessage: 'Remote Control at startup could not be changed',
},
{
id: CONTINUE_IN_TERMINAL_COMMAND,
module: 'AI_AGENTS',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
AiAgentsTreeItem,
createAgentSessionItem,
createComingSoonItem,
createAutoRemoteControlItem,
createImportFromWebItem,
createNoAgentSessionsItem,
createWatchAgentFlowItem,
} from './aiAgentsItems';
import { describeAge, listWorkspaceAgentSessions } from '../commands/agentFlowCommands';
import { autoRemoteControlEnabled } from '../commands/claudeSessionCommands';

/** Recent sessions listed under the entry point; the quick pick offers all of them. */
const RECENT_SESSIONS = 5;
Expand Down Expand Up @@ -50,6 +52,7 @@ export class AiAgentsSectionProvider extends BaseSectionProvider<AiAgentsTreeIte
? sessions.slice(0, RECENT_SESSIONS).map((session) => createAgentSessionItem(session, describeAge(session.updatedAt, now)))
: [createNoAgentSessionsItem()]),
createImportFromWebItem(),
createAutoRemoteControlItem(autoRemoteControlEnabled()),
createComingSoonItem(),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
* (epic #189, stories #214-#216). No row makes a network call: the sessions
* are read from the local agents' own history files.
*/
export type AiAgentsItemType = 'coming-soon' | 'agent-flow-watch' | 'agent-flow-session' | 'agent-flow-empty' | 'claude-import';
export type AiAgentsItemType = 'coming-soon' | 'agent-flow-watch' | 'agent-flow-session' | 'agent-flow-empty' | 'claude-import' | 'claude-auto-remote';

/** The positional arguments ModularTreeDataProvider's section adapter passes. */
type AiAgentsItemArgs = [
Expand Down Expand Up @@ -82,6 +82,22 @@ export function createImportFromWebItem(): AiAgentsTreeItem {
);
}

/** #456: whether every Claude Code session continues on claude.ai on its own; a click toggles it. */
export function createAutoRemoteControlItem(enabled: boolean): AiAgentsTreeItem {
return new AiAgentsTreeItem(
enabled ? 'Sessions continue on claude.ai' : 'Continue sessions on claude.ai automatically',
vscode.TreeItemCollapsibleState.None,
'claude-auto-remote',
{ command: 'codeXR.claudeSessions.toggleAutoRemoteControl', title: 'Continue sessions on claude.ai automatically' },
new vscode.ThemeIcon(enabled ? 'broadcast' : 'circle-slash'),
enabled
? 'Every Claude Code session starts with Remote Control (Claude Code\'s own remoteControlAtStartup), so you can open it from claude.ai/code or the Claude mobile app. Click to turn it off.'
: 'Turn on Claude Code\'s Remote Control at startup, so every Claude Code session can be opened from claude.ai/code or the Claude mobile app without any action. Asks first.',
enabled ? 'On' : 'Off',
'codeXR.aiAgents.claude.autoRemote',
);
}

/** Shown when the workspace has no agent session yet. */
export function createNoAgentSessionsItem(): AiAgentsTreeItem {
return new AiAgentsTreeItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,19 @@ test('CLI arguments are validated', () => {
assert.throws(() => resumeArgs('x; y'));
assert.equal(commandLine(resumeArgs(UUID, { remoteControl: true })), `claude --resume ${UUID} --remote-control`);
});

test('#456: automatic Remote Control (session _meta and Claude Code settings.json)', () => {
const core = require(path.join(projectRoot, 'out', 'core', 'claude-sessions', 'claudeSessionContinuity.js'));
assert.deepEqual(core.remoteControlSessionMeta(true), { claudeCode: { options: { settings: { remoteControlAtStartup: true } } } });
assert.equal(core.remoteControlSessionMeta(false), null);
assert.ok(core.isAutoRemoteControlMode('ask') && core.isAutoRemoteControlMode('always') && !core.isAutoRemoteControlMode('yes'));
const before = '{\n "model": "opus",\n "permissions": { "allow": ["Bash(ls)"] }\n}\n';
const on = core.withRemoteControlAtStartup(before, true);
assert.deepEqual(JSON.parse(on), { model: 'opus', permissions: { allow: ['Bash(ls)'] }, remoteControlAtStartup: true });
assert.ok(core.remoteControlAtStartupIn(on));
assert.deepEqual(JSON.parse(core.withRemoteControlAtStartup(on, false)), { model: 'opus', permissions: { allow: ['Bash(ls)'] } });
assert.deepEqual(JSON.parse(core.withRemoteControlAtStartup(null, true)), { remoteControlAtStartup: true });
assert.throws(() => core.withRemoteControlAtStartup('{ nope', true), /not valid JSON/);
assert.throws(() => core.withRemoteControlAtStartup('[1]', true), /not a JSON object/);
assert.equal(core.remoteControlAtStartupIn('{ nope'), false);
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"codeXR.claudeSessions.continueInTerminal | Code-XR: Continue a Claude Code Chat in the Terminal",
"codeXR.claudeSessions.continueOnClaudeAi | Code-XR: Continue a Claude Code Chat on claude.ai (Remote Control)",
"codeXR.claudeSessions.importFromWeb | Code-XR: Import a Claude Code Chat from claude.ai",
"codeXR.claudeSessions.toggleAutoRemoteControl | Code-XR: Continue Claude Code Sessions on claude.ai Automatically (On/Off)",
"codeXR.collaboration.joinRemote | Code-XR: Join Remote Session",
"codeXR.collaboration.selectAvatar | Code-XR: Select Avatar Color",
"codeXR.collaboration.selectIdentity | Code-XR: Select Collaboration Identity",
Expand Down Expand Up @@ -297,6 +298,7 @@
"codeXR.claudeSessions.continueInTerminal",
"codeXR.claudeSessions.continueOnClaudeAi",
"codeXR.claudeSessions.importFromWeb",
"codeXR.claudeSessions.toggleAutoRemoteControl",
"codeXR.collaboration.joinRemote",
"codeXR.collaboration.selectAvatar",
"codeXR.collaboration.selectIdentity",
Expand Down
Loading
Loading