fix: Always use npx — stop silent global install failures

Remove the npm install -g attempt from the installer that silently
fails on many systems (permissions, PATH, node version managers).
All configs (MCP server, hooks, next-steps) now always use
npx @colbymchenry/codegraph. Global install offered as an optional tip.

Fixes #37, #38
This commit is contained in:
Colby McHenry
2026-02-19 15:28:56 -06:00
parent 3be779f6f6
commit 675aab386a
4 changed files with 26 additions and 73 deletions
+6 -25
View File
@@ -98,28 +98,9 @@ function writeJsonFile(filePath: string, data: Record<string, any>): void {
}
/**
* When true, all configs use `npx @colbymchenry/codegraph` instead of the
* bare `codegraph` command. Set by the installer when global install fails.
* Get the MCP server configuration — always uses npx for reliability
*/
let useNpxFallback = false;
export function setUseNpxFallback(value: boolean): void {
useNpxFallback = value;
}
/**
* Get the MCP server configuration for the given location
*/
function getMcpServerConfig(location: InstallLocation): Record<string, any> {
if (location === 'global' && !useNpxFallback) {
// Global: use 'codegraph' command directly (globally installed and in PATH)
return {
type: 'stdio',
command: 'codegraph',
args: ['serve', '--mcp'],
};
}
// Local or npx fallback: use npx to run the package
function getMcpServerConfig(): Record<string, any> {
return {
type: 'stdio',
command: 'npx',
@@ -140,7 +121,7 @@ export function writeMcpConfig(location: InstallLocation): void {
}
// Add or update codegraph server
config.mcpServers.codegraph = getMcpServerConfig(location);
config.mcpServers.codegraph = getMcpServerConfig();
writeJsonFile(claudeJsonPath, config);
}
@@ -221,8 +202,8 @@ export function hasPermissions(location: InstallLocation): boolean {
* PostToolUse(Edit|Write) → mark-dirty (async, non-blocking)
* Stop → sync-if-dirty (sync, ensures fresh index before next user turn)
*/
function getHooksConfig(location: InstallLocation): Record<string, any> {
const command = (location === 'global' && !useNpxFallback) ? 'codegraph' : 'npx @colbymchenry/codegraph';
function getHooksConfig(): Record<string, any> {
const command = 'npx @colbymchenry/codegraph';
return {
PostToolUse: [
@@ -277,7 +258,7 @@ export function writeHooks(location: InstallLocation): void {
settings.hooks = {};
}
const newHooks = getHooksConfig(location);
const newHooks = getHooksConfig();
// For each hook event (PostToolUse, Stop), merge with existing entries
for (const [event, newEntries] of Object.entries(newHooks)) {