different-ai/openwork · error

command.name is required

Error message

command.name is required

What it means

writeCommandFile sanitizes command?.name via sanitizeCommandName before building the <name>.md path. If the command object is missing, has no name, or its name sanitizes to an empty string (e.g. only illegal characters like '/' or spaces), the write is aborted with 'command.name is required' rather than writing to a bogus path.

Source

Thrown at apps/desktop/electron/main.mjs:1524

  throw new Error("scope must be 'workspace' or 'global'");
}

async function listCommandNames(scope, projectDir) {
  const commandsDir = resolveCommandsDir(scope, projectDir);
  if (!(await isDirectory(commandsDir))) {
    return [];
  }
  const entries = await readdir(commandsDir, { withFileTypes: true });
  return entries
    .filter((entry) => entry.isFile() && entry.name.endsWith(".md"))
    .map((entry) => entry.name.replace(/\.md$/, ""))
    .sort();
}

async function writeCommandFile(scope, projectDir, command) {
  const safeName = sanitizeCommandName(command?.name);
  if (!safeName) {
    throw new Error("command.name is required");
  }
  const commandsDir = resolveCommandsDir(scope, projectDir);
  await mkdir(commandsDir, { recursive: true });
  const filePath = path.join(commandsDir, `${safeName}.md`);
  await writeFile(filePath, serializeCommandFrontmatter({ ...command, name: safeName }), "utf8");
  return execResult(true, `Wrote ${filePath}`);
}

async function deleteCommandFile(scope, projectDir, name) {
  const safeName = sanitizeCommandName(name);
  if (!safeName) {
    throw new Error("name is required");
  }
  const commandsDir = resolveCommandsDir(scope, projectDir);
  const filePath = path.join(commandsDir, `${safeName}.md`);
  if (await pathExists(filePath)) {
    await rm(filePath, { force: true });
  }

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Provide a non-empty command name composed of valid characters (alphanumerics, dashes, underscores).
  2. Trim the name and verify it is non-empty after removing invalid characters before saving.
  3. Fix the renderer form to require the name field before enabling Save.
  4. Check that the object being sent is the command itself, not a wrapper ({ command: { name } } vs { name }).

Example fix

// before
await writeCommandFile("workspace", dir, { description: "Run tests" });
// after
await writeCommandFile("workspace", dir, { name: "run-tests", description: "Run tests" });
Defensive patterns

Strategy: validation

Validate before calling

const safe = String(command?.name ?? '').trim();
if (!safe || /[\\/]/.test(safe)) {
  throw new Error('command.name must be a non-empty filename-safe string');
}

Type guard

function hasCommandName(command) {
  return typeof command?.name === 'string' && command.name.trim().length > 0;
}

Prevention

When it happens

Trigger: Calling the command-write API with command=null/undefined, an object lacking a name field, or a name consisting entirely of characters stripped by sanitizeCommandName (empty string, whitespace-only, slashes/path separators).

Common situations: A form in the renderer submitted before the user typed a name, a frontmatter parse dropped the name field, or a name containing only invalid characters ('///') passed validation UI but failed sanitization.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/589cd51fda8ac599. Report an issue: GitHub.