Skip to content

Latest commit

 

History

History
38 lines (23 loc) · 2.92 KB

File metadata and controls

38 lines (23 loc) · 2.92 KB

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

What this is

A VS Code extension that adds a ✨ button to the Source Control panel. Clicking it reads the git diff, pipes it to the local Claude CLI (claude -p), and writes the returned commit message into the SCM input box. The entire extension is one file: extension.js (~150 lines, plain CommonJS — no build step, no TypeScript, no dependencies).

Commands

npm run package   # builds the .vsix into dist/ via vsce (the only script)

There is no build, lint, or test setup — extension.js is shipped as-is. To test changes, install the packaged .vsix (Ctrl+Shift+PExtensions: Install from VSIX…) or run the Extension Development Host from VS Code (F5).

Architecture notes

The flow lives in the claudeCommitButton.generate command handler:

  1. Repo resolution — the scm/title menu passes the SourceControl as arg; match it against git.repositories by rootUri, else fall back to the first repo. The git API comes from the built-in vscode.git extension (getAPI(1)).
  2. Diff selection — staged diff (repo.diff(true)) first; if empty, fall back to the whole working tree (repo.diff(false)). Truncated to MAX = 6000 chars before sending.
  3. CLI invocationexecFile(claudePath, args) with the diff written to stdin (not passed as an arg). The prompt goes over stdin; flags lock the CLI down: -p (print mode), --tools '', --strict-mcp-config, --setting-sources '', --no-session-persistence, --dangerously-skip-permissions. Model and effort come from settings.
  4. Result is trimmed and assigned to repo.inputBox.value.

CLI path resolution (the subtle part)

resolveCli()detectClaude() handles the Windows npm-shim problem, which is the main source of complexity:

  • User-configured cliPath setting wins; otherwise where/which claude.
  • On Windows, npm installs three shims (claude, claude.cmd, claude.ps1). Node's execFile can't reliably spawn the extensionless shell script or .cmd and pipe stdin, so the code prefers the real claude.exe — either found directly in where output, or derived from a shim's directory via the known npm layout (node_modules/@anthropic-ai/claude-code/bin/claude.exe).
  • Resolved path is memoized in cachedCli (revalidated with fs.existsSync).

When editing detection logic, preserve this .exe-preference ordering — it's the fix for Claude-installed-under-WSL/Git-Bash and npm-shim cases documented in the README.

Optional proposed-API mode

An unused-by-default buttonLocation setting can move the button inside the commit box using VS Code's proposed contribSourceControlInputBoxMenu API. This can't ship in the .vsix and needs manual local setup — see the README's "button inside the message box" section. Don't add the proposed API to the shipped package.json.