Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ import {
cellOutputHasError,
chooseWorkspaceDirectory,
compareSelections,
buildResumeCommand,
extractLLMGeneratedCode,
getSelectionInEditor,
getTokenCount,
Expand Down Expand Up @@ -1403,10 +1404,9 @@ const plugin: JupyterFrontEndPlugin<INotebookIntelligence> = {
return React.createElement(LauncherPicker, {
onSessionSelected: (session: IClaudeSessionInfo) => {
dialog.close();
const cmd = session.cwd
? `cd ${session.cwd} && claude --resume ${session.session_id}`
: `claude --resume ${session.session_id}`;
launchCliInTerminal(cmd);
launchCliInTerminal(
buildResumeCommand(session.cwd ?? '', session.session_id)
);
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,11 @@ export function safeAnchorUri(uri: string | undefined | null): string | null {
* user happens to be in the JupyterLab working directory.
*/
export function buildResumeCommand(cwd: string, sessionId: string): string {
const quotedSessionId = shellSingleQuote(sessionId);
if (!cwd) {
return `claude --resume ${sessionId}`;
return `claude --resume ${quotedSessionId}`;
}
return `cd ${shellSingleQuote(cwd)} && claude --resume ${sessionId}`;
return `cd ${shellSingleQuote(cwd)} && claude --resume ${quotedSessionId}`;
}

/**
Expand Down
14 changes: 11 additions & 3 deletions tests/ts/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,26 @@ describe('shellSingleQuote', () => {
describe('buildResumeCommand', () => {
it('wraps cd around the resume invocation when cwd is provided', () => {
expect(buildResumeCommand('/tmp/proj', 'abc-123')).toBe(
"cd '/tmp/proj' && claude --resume abc-123"
"cd '/tmp/proj' && claude --resume 'abc-123'"
);
});

it('quotes paths with spaces correctly', () => {
expect(buildResumeCommand('/Users/me/My Project', 'xyz')).toBe(
"cd '/Users/me/My Project' && claude --resume xyz"
"cd '/Users/me/My Project' && claude --resume 'xyz'"
);
});

it('quotes session ids before shell interpolation', () => {
expect(buildResumeCommand('/tmp/proj', "abc'; touch /tmp/pwned; '")).toBe(
"cd '/tmp/proj' && claude --resume 'abc'\\''; touch /tmp/pwned; '\\'''"
);
});

it('falls back to a bare resume when cwd is empty', () => {
expect(buildResumeCommand('', 'abc-123')).toBe('claude --resume abc-123');
expect(buildResumeCommand('', 'abc-123')).toBe(
"claude --resume 'abc-123'"
);
});
});

Expand Down
Loading