Repository navigation
feat: add one-command setup for installed AI clients - #140
PatrickSys wants to merge 1 commit into
Conversation
`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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
codebase-context/src/cli-init.ts
Lines 243 to 249 in 3e73505
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.
codebase-context/src/cli-init.ts
Lines 349 to 351 in 3e73505
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".
[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
SummaryAdds automatic stdio setup for installed AI clients, with project-specific launch paths and backups. The older wizard remains available through
Acknowledged limits:
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"]
Reviews (1) · Last reviewed commit: "feat: add one-command setup for installe..." · Reviewed by Greptile |
| : await _buildMergedMcpContent( | ||
| plan.configPath, | ||
| plan.content, | ||
| plan.clients[0]?.id ?? 'client', | ||
| plan.serverKey ?? 'mcpServers' |
There was a problem hiding this comment.
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.
| await fs.writeFile(backupPath, existing, 'utf8'); | ||
| } | ||
| await fs.writeFile(plan.configPath, merged.content, 'utf8'); |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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.
What / Why
npx -y codebase-context@2.4.0 initnow 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.--yesskips the question.--httpkeeps the older wizard, including the local web config for Cursor and OpenCode.What it detects
claudeis on PATH, or~/.claudeor~/.claude.jsonexists<project>/.mcp.json~/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/...)cursororcursor-agentis on PATH,~/.cursorexists, or the app exists<project>/.cursor/mcp.jsoncodeis on PATH, or the app / user data folder exists<project>/.vscode/mcp.json(servers,type: stdio)windsurfis on PATH,~/.codeium/windsurfexists, or the app exists~/.codeium/windsurf/mcp_config.jsoncodexis on PATH,~/.codexexists, orCODEX_HOMEexists<project>/.codex/config.toml/Applications/Codex.appor~/Applications/Codex.appon macOS;%LOCALAPPDATA%\OpenAI\Codex,%LOCALAPPDATA%\Programs\Codex, or Program Files on Windows).codex/config.tomlas the CLI, written onceThe project is the current folder.
--rootwins overCODEBASE_ROOT. The server command is the Node binary that raninit, plus this package's entrypoint and that project path, so a desktop app does not neednpxon its PATH.Codex is written only in the project file.
~/.codex/config.tomlis not opened, which is the overwrite case from #138. If that project file already has a differentcodebase-contextentry, it is left byte for byte as it was.How writing stays safe
codebase-contextentry is left as it is. Nothing is rewritten and no backup is added.codebase-contextentry stops that file. No backup, no write. Setup continues for the other clients and exits with code 1.<file>.<utc-timestamp>.bakfirst.Release notes
feat: add one-command setup for installed AI clientsThe README quickstart now shows
npx -y codebase-context@2.4.0 initand--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). Runnode dist/index.js initfrom 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
/ApplicationsorC:\Program Filesis 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
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.jsonRun
--yesagain. Matching files stay unchanged. Then change thecodebase-contextcommand 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.bakfile appears beside it.If Codex is really installed, open the scratch folder and trust the project so it reads
.codex/config.toml.Windows (PowerShell)
Same checks. Claude Desktop's file is
%APPDATA%\Claude\claude_desktop_config.json. A Microsoft Store copy of Codex under a versionedWindowsAppsfolder is not scanned.init --client codex-desktop --yesstill writes the project file.--httpstill asks which client to set up and still writes the local web config for Cursor and OpenCode.