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: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
"title": "Open Claude Code Chat",
"category": "Claude Code Chat",
"icon": "icon-bubble.png"
},
{
"command": "claude-code-chat.showPlan",
"title": "Show Plan Files",
"category": "Claude Code Chat"
}
],
"keybindings": [
Expand All @@ -73,6 +78,9 @@
"commandPalette": [
{
"command": "claude-code-chat.openChat"
},
{
"command": "claude-code-chat.showPlan"
}
],
"editor/context": [
Expand Down
107 changes: 106 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ export function activate(context: vscode.ExtensionContext) {
provider.loadConversation(filename);
});

const showPlanDisposable = vscode.commands.registerCommand('claude-code-chat.showPlan', () => {
provider.showPlanFiles();
});

// Offer to notify Claude when a plan file (~/.claude/plans/*.md) is saved from the editor
const planFileSaveDisposable = vscode.workspace.onDidSaveTextDocument(document => {
provider.handlePlanFileSaved(document);
});

// Register webview view provider for sidebar chat (using shared provider instance)
const webviewProvider = new ClaudeChatWebviewProvider(context.extensionUri, provider);
vscode.window.registerWebviewViewProvider('claude-code-chat.chat', webviewProvider);
Expand Down Expand Up @@ -98,7 +107,7 @@ export function activate(context: vscode.ExtensionContext) {
}
});

context.subscriptions.push(disposable, loadConversationDisposable, configChangeDisposable, statusBarItem, uriHandler);
context.subscriptions.push(disposable, loadConversationDisposable, showPlanDisposable, planFileSaveDisposable, configChangeDisposable, statusBarItem, uriHandler);
}

export function deactivate() {
Expand Down Expand Up @@ -595,6 +604,9 @@ class ClaudeChatProvider {
case 'openFile':
this._openFileInEditor(message.filePath);
return;
case 'showPlanFiles':
this.showPlanFiles();
return;
case 'openDiff':
this._openDiffEditor(message.oldContent, message.newContent, message.filePath);
return;
Expand Down Expand Up @@ -3866,6 +3878,99 @@ class ClaudeChatProvider {
this._context.globalState.update('wslAlertDismissed', true);
}

// ─── Plan Files ───

private _getPlansDir(): string {
const homeDir = process.env.HOME || process.env.USERPROFILE || '';
return path.join(homeDir, '.claude', 'plans');
}

public async showPlanFiles(): Promise<void> {
const plansDir = this._getPlansDir();

let entries: [string, vscode.FileType][];
try {
entries = await vscode.workspace.fs.readDirectory(vscode.Uri.file(plansDir));
} catch {
vscode.window.showInformationMessage('No plan files found in ~/.claude/plans/');
return;
}

const mdFiles = entries.filter(([name, type]) => (type & vscode.FileType.File) !== 0 && name.toLowerCase().endsWith('.md'));
if (mdFiles.length === 0) {
vscode.window.showInformationMessage('No plan files found in ~/.claude/plans/');
return;
}

const plans: { name: string; filePath: string; mtime: number }[] = [];
for (const [name] of mdFiles) {
const filePath = path.join(plansDir, name);
try {
const stat = await vscode.workspace.fs.stat(vscode.Uri.file(filePath));
plans.push({ name, filePath, mtime: stat.mtime });
} catch { /* stat failed, skip */ }
}
plans.sort((a, b) => b.mtime - a.mtime);

if (plans.length === 0) {
vscode.window.showInformationMessage('No plan files found in ~/.claude/plans/');
return;
}

if (plans.length === 1) {
this._openFileInEditor(plans[0].filePath);
return;
}

const picked = await vscode.window.showQuickPick(
plans.map(plan => ({
label: plan.name.replace(/\.md$/i, ''),
description: new Date(plan.mtime).toLocaleString(),
filePath: plan.filePath
})),
{ placeHolder: 'Select a plan file to open' }
);

if (picked) {
this._openFileInEditor(picked.filePath);
}
}

public async handlePlanFileSaved(document: vscode.TextDocument): Promise<void> {
const savedPath = document.uri.fsPath;
if (!savedPath.toLowerCase().endsWith('.md')) {
return;
}

const plansDir = path.resolve(this._getPlansDir());
const resolvedSavedPath = path.resolve(savedPath);
const isWithinPlansDir = process.platform === 'win32'
? resolvedSavedPath.toLowerCase().startsWith(plansDir.toLowerCase() + path.sep)
: resolvedSavedPath.startsWith(plansDir + path.sep);

if (!isWithinPlansDir) {
return;
}

const fileName = path.basename(savedPath, '.md');
const hasActiveWebview = !!(this._panel || this._webview);

if (!hasActiveWebview) {
vscode.window.showInformationMessage(`Plan file "${fileName}" saved.`);
return;
}

const selection = await vscode.window.showInformationMessage(
`Plan file "${fileName}" saved. Tell Claude about your changes?`,
'Send to Claude',
'Dismiss'
);

if (selection === 'Send to Claude') {
this._sendMessageToClaude(`I updated the plan file "${fileName}" in ~/.claude/plans/. Please re-read it and adjust your approach accordingly.`);
}
}

private async _openFileInEditor(filePath: string) {
try {
const uri = vscode.Uri.file(filePath);
Expand Down
6 changes: 6 additions & 0 deletions src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4319,6 +4319,12 @@ const getScript = (isTelemetryEnabled: boolean, opencreditsApiUrl: string = 'htt
});
}

function showPlanFiles() {
vscode.postMessage({
type: 'showPlanFiles'
});
}

function restoreToCommit(commitSha) {
vscode.postMessage({
type: 'restoreCommit',
Expand Down
1 change: 1 addition & 0 deletions src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const getHtml = (isTelemetryEnabled: boolean, opencreditsApiUrl: string = 'https
<div id="sessionStatus" class="session-status" style="display: none;">No session</div>
<button class="btn outlined" id="settingsBtn" onclick="toggleSettings()" title="Settings">⚙️</button>
<button class="btn outlined" id="historyBtn" onclick="toggleConversationHistory()">📚 History</button>
<button class="btn outlined" id="plansBtn" onclick="showPlanFiles()" title="Open a plan file (~/.claude/plans)">📋 Plans</button>
<button class="btn primary" id="newSessionBtn" onclick="newSession()">New Chat</button>
</div>
</div>
Expand Down