can1357/oh-my-pi · error

Host "${name}" not found in ${filePath}

Error message

Host "${name}" not found in ${filePath}

What it means

removeSSHHost looks up the host name in the parsed config and throws if no entry with that exact name exists at filePath. Removal is by literal alias match; pattern-style or case-differing names will not be found.

Source

Thrown at packages/coding-agent/src/ssh/config-writer.ts:163

		},
	};

	// Write back
	await writeSSHConfigFile(filePath, updated);
}

/**
 * Remove an SSH host from a config file.
 *
 * @throws Error if host doesn't exist
 */
export async function removeSSHHost(filePath: string, name: string): Promise<void> {
	// Read existing config
	const existing = await readSSHConfigFile(filePath);

	// Check if host exists
	if (!existing.hosts?.[name]) {
		throw new Error(`Host "${name}" not found in ${filePath}`);
	}

	// Remove host
	const { [name]: _removed, ...remaining } = existing.hosts;
	const updated: SSHConfigFile = {
		...existing,
		hosts: remaining,
	};

	// Write back
	await writeSSHConfigFile(filePath, updated);
}

/**
 * List all host names in a config file.
 */
export async function listSSHHosts(filePath: string): Promise<string[]> {
	const config = await readSSHConfigFile(filePath);

View on GitHub (pinned to 9690622007)

Solutions

  1. List hosts via readSSHConfigFile(filePath) to confirm the exact stored name
  2. Verify you are targeting the correct config file path
  3. Make the removal idempotent by checking existence before calling
  4. Use updateSSHHost instead if the goal was to modify, not delete

Example fix

// before
await removeSSHHost(path, "Prod"); // stored as "prod"
// after
const cfg = await readSSHConfigFile(path);
if (cfg.hosts?.["Prod"]) await removeSSHHost(path, "Prod");
Defensive patterns

Strategy: validation

Validate before calling

const hosts = (await readSSHConfigFile(filePath)).hosts ?? {};
if (hosts[name]) await removeSSHHost(filePath, name);

Type guard

null

Try / catch

try { await removeSSHHost(p, name); } catch (e) { if (!(e instanceof Error && e.message.includes("not found"))) throw e; /* already gone: idempotent */ }

Prevention

When it happens

Trigger: Calling removeSSHHost(filePath, name) where existing.hosts[name] is undefined — name never added, already removed, or spelled differently.

Common situations: Idempotent cleanup scripts running twice, typos in the alias, names differing in case, or editing a different config file (project vs ~/.ssh/config) than the one containing the host.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/bad9a6c736168bc1. Report an issue: GitHub.