Skip to content

feat: add one-command setup for installed AI clients - #140

Open
PatrickSys wants to merge 1 commit into
masterfrom
cursor/one-command-init-6ee6
Open

PatrickSys wants to merge 1 commit into
masterfrom
cursor/one-command-init-6ee6

Conversation

@PatrickSys

Copy link
Copy Markdown
Owner

What / Why

npx -y codebase-context@2.4.0 init now finds the AI apps installed on the machine and adds a stdio server for the current folder. No config file has to be edited by hand. The prompt defaults to no. --yes skips the question.

--http keeps the older wizard, including the local web config for Cursor and OpenCode.

What it detects

Client Treated as installed when File written
Claude Code claude is on PATH, or ~/.claude or ~/.claude.json exists <project>/.mcp.json
Claude Desktop The app or its config folder exists macOS: ~/Library/Application Support/Claude/claude_desktop_config.json. Windows: %APPDATA%\Claude\claude_desktop_config.json. Linux: $XDG_CONFIG_HOME/Claude/claude_desktop_config.json (or ~/.config/Claude/...)
Cursor cursor or cursor-agent is on PATH, ~/.cursor exists, or the app exists <project>/.cursor/mcp.json
VS Code code is on PATH, or the app / user data folder exists <project>/.vscode/mcp.json (servers, type: stdio)
Windsurf windsurf is on PATH, ~/.codeium/windsurf exists, or the app exists ~/.codeium/windsurf/mcp_config.json
Codex CLI codex is on PATH, ~/.codex exists, or CODEX_HOME exists <project>/.codex/config.toml
Codex Desktop The app exists (/Applications/Codex.app or ~/Applications/Codex.app on macOS; %LOCALAPPDATA%\OpenAI\Codex, %LOCALAPPDATA%\Programs\Codex, or Program Files on Windows) Same project .codex/config.toml as the CLI, written once

The project is the current folder. --root wins over CODEBASE_ROOT. The server command is the Node binary that ran init, plus this package's entrypoint and that project path, so a desktop app does not need npx on its PATH.

Codex is written only in the project file. ~/.codex/config.toml is not opened, which is the overwrite case from #138. If that project file already has a different codebase-context entry, it is left byte for byte as it was.

How writing stays safe

  • Other servers and settings in the file are kept.
  • The same codebase-context entry is left as it is. Nothing is rewritten and no backup is added.
  • A different codebase-context entry stops that file. No backup, no write. Setup continues for the other clients and exits with code 1.
  • A file that does change gets a sibling backup named <file>.<utc-timestamp>.bak first.

Release notes

feat: add one-command setup for installed AI clients

The README quickstart now shows npx -y codebase-context@2.4.0 init and --yes. It still says these commands use 2.4.0 and points at the published 2.2.0 setup guide when that version is not on npm yet. Version was not bumped.

How to test manually

Build this branch first (pnpm build). Run node dist/index.js init from a scratch folder. Press Enter at the question to decline. Files change only after you answer yes, or when you pass --yes.

A real app under /Applications or C:\Program Files is still detected. Point the home and app-data variables below at a temp directory so Claude Desktop and Windsurf writes stay out of your real settings. Project files are written in the folder you run from.

macOS

export HOME=/tmp/cbc-init-home
mkdir -p "$HOME/Library/Application Support/Claude" \
  "$HOME/Library/Application Support/Code" \
  "$HOME/.claude" "$HOME/.cursor" "$HOME/.codex" \
  "$HOME/.codeium/windsurf" /tmp/cbc-init-project
cd /tmp/cbc-init-project
node /path/to/codebase-context/dist/index.js init

Answer no, confirm nothing changed, then run the same command with --yes. Check:

  • /tmp/cbc-init-project/.mcp.json
  • /tmp/cbc-init-project/.cursor/mcp.json
  • /tmp/cbc-init-project/.vscode/mcp.json
  • /tmp/cbc-init-project/.codex/config.toml
  • $HOME/Library/Application Support/Claude/claude_desktop_config.json
  • $HOME/.codeium/windsurf/mcp_config.json

Run --yes again. Matching files stay unchanged. Then change the codebase-context command in one file and run again: that file is not modified. Add an unrelated server to another file and run again: the other server remains, and a .bak file appears beside it.

If Codex is really installed, open the scratch folder and trust the project so it reads .codex/config.toml.

Windows (PowerShell)

$env:USERPROFILE = 'C:\temp\cbc-init-home'
$env:APPDATA = 'C:\temp\cbc-init-home\AppData\Roaming'
$env:LOCALAPPDATA = 'C:\temp\cbc-init-home\AppData\Local'
New-Item -ItemType Directory -Force @(
  "$env:APPDATA\Claude",
  "$env:APPDATA\Code",
  "$env:LOCALAPPDATA\Programs\cursor",
  "$env:LOCALAPPDATA\Programs\Microsoft VS Code",
  "$env:LOCALAPPDATA\Programs\Windsurf",
  "$env:LOCALAPPDATA\Programs\Codex",
  "$env:USERPROFILE\.claude",
  "$env:USERPROFILE\.codex",
  "$env:USERPROFILE\.codeium\windsurf",
  'C:\temp\cbc-init-project'
) | Out-Null
Set-Location C:\temp\cbc-init-project
node C:\path\to\codebase-context\dist\index.js init

Same checks. Claude Desktop's file is %APPDATA%\Claude\claude_desktop_config.json. A Microsoft Store copy of Codex under a versioned WindowsApps folder is not scanned. init --client codex-desktop --yes still writes the project file.

--http still asks which client to set up and still writes the local web config for Cursor and OpenCode.

Open in Web Open in Cursor 

`init` finds Claude Code, Claude Desktop, Cursor, VS Code, Windsurf, and Codex, then writes a stdio config for each one. Existing settings are merged, a different codebase-context entry is left unchanged, and a backup is saved before a file changes. `--http` keeps the older wizard.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T23:56:52.682748Z 3e73505 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

let existing: unknown;
try {
existing = JSON.parse(existingText) as unknown;
} catch (error) {
throw new Error(`Cannot merge ${client} config at ${filePath}: existing JSON is invalid.`, {
cause: error
});

P2 Badge Parse VS Code MCP configuration as JSONC

When an existing .vscode/mcp.json contains comments or trailing commas, JSON.parse rejects the file and setup skips VS Code instead of preserving its existing settings. These constructs are valid in practice—Microsoft's own VS Code mcp.json contains both a // comment and a trailing comma—so this path needs a JSONC-aware parser/editor.


const dottedEntry = new RegExp(
`^\\s*${mcpServersKey}\\s*\\.\\s*${codebaseContextKey}\\s*\\.`,
'm'

P2 Badge Detect inline dotted Codex entries before appending

When an existing Codex file expresses its server as mcp_servers.codebase-context = { command = "old", args = [] }, this regex misses it because it requires another dot after codebase-context; setup then appends [mcp_servers.codebase-context], defining the same key twice and leaving the resulting TOML invalid rather than preserving the conflicting file. Dotted keys and inline tables are valid representations under the TOML specification, so the conflict check should also recognize an equals sign here.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] Setup changes local AI-client settings for the project and, for two clients, the user account.

Fix reading of valid commented VS Code configs before merging.

Findings

  1. P1 Commented VS Code configs fail ▶
  2. P2 Failed writes break client settings ▶
  3. P2 Installed clients get missed ▶

Summary

Adds automatic stdio setup for installed AI clients, with project-specific launch paths and backups. The older wizard remains available through --http.

  • One init command connects installed AI clients to the current project.
  • Setup keeps other client settings and backs up files it changes.
  • The older HTTP setup still runs when developers pass --http.

Acknowledged limits:

  • PatrickSys explicitly acknowledged that the version was not bumped and that 2.4.0 may not be published, and provided a published-guide fallback.
  • PatrickSys explicitly identified that Microsoft Store Codex is not detected and provided --client codex-desktop as the workaround.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["init"] --> B{"--http?"}
  B -->|Yes| C["Older client wizard"]
  B -->|No| D["Detect clients or use --client"]
  D --> E["Build and combine file plans"]
  E --> F{"User approves or --yes?"}
  F -->|No| G["No files changed"]
  F -->|Yes| H["Read and merge each file"]
  H --> I["Skip matching or conflicting entries"]
  H --> J["Back up existing file and write config"]
Loading

Reviews (1) · Last reviewed commit: "feat: add one-command setup for installe..." · Reviewed by Greptile

Comment thread src/cli-init.ts
Comment on lines +516 to +520
: await _buildMergedMcpContent(
plan.configPath,
plan.content,
plan.clients[0]?.id ?? 'client',
plan.serverKey ?? 'mcpServers'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Commented VS Code configs fail

VS Code accepts comments and trailing commas in .vscode/mcp.json, but this new path reads that file through _buildMergedMcpContent, which uses JSON.parse. A valid file such as { "servers": {}, } therefore makes setup skip VS Code and exit with code 1. Use a comment-aware parser for this client and add a test with an existing commented file.

Comment thread src/cli-init.ts
Comment on lines +539 to +541
await fs.writeFile(backupPath, existing, 'utf8');
}
await fs.writeFile(plan.configPath, merged.content, 'utf8');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Failed writes break client settings

The new writer replaces live client settings with a direct fs.writeFile, which truncates the file before writing. If that write fails or is interrupted, Claude Desktop or Windsurf can be left with an empty or partial settings file, affecting their other servers too. The backup helps recovery but still requires manual repair. Write a temporary sibling file, then rename it over the destination after the write succeeds.

Comment thread src/init-clients.ts
Comment on lines +316 to +320
export function commandOnPath(command: string): Promise<boolean> {
const finder = process.platform === 'win32' ? 'where.exe' : 'which';
return new Promise((resolve) => {
execFile(finder, [command], { timeout: 5000, windowsHide: true }, (error) => {
resolve(error === null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Installed clients get missed

If a Linux machine has Node and a client on PATH but no which program, commandOnPath returns false for every command. A newly installed client without a settings folder is then missed, and setup can report that no clients are installed. Search the directories in PATH directly rather than requiring another executable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants