neoclide/coc.nvim · error

Command: ${command} not found

Error message

Command: ${command} not found

What it means

coc.nvim's command registry has no entry under the requested name, so commands.executeCommand throws. This is thrown synchronously when the command string does not match any registered command (registered via registerCommand, built-in commands, or extension contributions).

Source

Thrown at src/commands.ts:159

    })
  }

  /**
   * Executes the command denoted by the given command identifier.
   *
   * * *Note 1:* When executing an editor command not all types are allowed to
   * be passed as arguments. Allowed are the primitive types `string`, `boolean`,
   * `number`, `undefined`, and `null`, as well as [`Position`](#Position), [`Range`](#Range), [`URI`](#URI) and [`Location`](#Location).
   * * *Note 2:* There are no restrictions when executing commands that have been contributed
   * by extensions.
   * @param command Identifier of the command to execute.
   * @param rest Parameters passed to the command function.
   * @return A promise that resolves to the returned value of the given command. `undefined` when
   * the command handler function doesn't return anything.
   */
  public executeCommand<T>(command: string, ...rest: any[]): Promise<T> {
    let cmd = this.commands.get(command)
    if (!cmd) throw new Error(`Command: ${command} not found`)
    return Promise.resolve(cmd.execute.apply(cmd, rest))
  }

  /**
   * @internal
   * Used for user invoked command.
   */
  public async fireCommand(id: string, ...args: any[]): Promise<unknown> {
    // needed to load onCommand extensions
    await events.fire('Command', [id])
    let start = Date.now()
    let res = await this.executeCommand(id, ...args)
    if (args.length == 0) {
      await this.addRecent(id, events.lastChangeTs > start)
    }
    return res
  }
  /**

View on GitHub (pinned to 50e974d969)

Solutions

  1. Check the exact command name against the extension's README or :CocList commands output
  2. Ensure the extension providing the command is installed and activated
  3. Wrap executeCommand in try/catch or check the registry before invoking
  4. If lazy-loading, wait for extension activation before calling the command

Example fix

// before
await actions.executeCommand('coc clangd.switchSourceHeader')
// after
const name = 'clangd.switchSourceHeader'
if (commands.has(name)) await actions.executeCommand(name)
else log(`command ${name} not available`)
Defensive patterns

Strategy: try-catch

Validate before calling

// check registry before executing
if (!commands.has('my.command')) return notify('command not available')

Try / catch

try {
  await actions.executeCommand(name, ...args)
} catch (e) {
  if (String(e.message).includes('not found')) notify(`Unknown command: ${name}`)
  else throw e
}

Prevention

When it happens

Trigger: Calling coc.actions.executeCommand('some.command') with a typo, executing a command contributed by an extension that is not installed or failed to activate, or executing a command before its extension registered it.

Common situations: User keymaps or statusline configs hardcode a coc command name from outdated docs; extensions renamed/removed commands; commands invoked in init scripts before extensions load.

Related errors


AI-assisted analysis of neoclide/coc.nvim@50e974d969 (2026-08-31). Data as JSON: /api/errors/24aceb683079bd6d. Report an issue: GitHub.