add-command
FreeNo executable scriptsNot checkedGuide for adding new CLI commands or subcommands to todoist-cli. Use when implementing new SDK endpoints, adding subcommands to existing command groups, or…
by todoist★ 340 GitHub starsAbout this skill
Adding a New CLI Command or Subcommand
Follow this checklist when adding new commands. Each step references the exact file to modify.
1. Mock API (src/test-support/mock-api.ts)
Add a mock for each new SDK method in createMockApi(). Place it in the correct entity group.
- List/read methods:
.mockResolvedValue({ results: [], nextCursor: null })or appropriate empty default - Mutation methods:
vi.fn()(no default return needed)
2. Spinner Messages (src/lib/api/core.ts)
Add an entry to API_SPINNER_MESSAGES for each new SDK method.
Color convention:
blue— read/fetch operationsgreen— create/join operationsyellow— update/delete/archive mutations
3. Read-Only Permissions (src/lib/permissions.ts)
If the new command uses a read-only SDK method (e.g., getXxx, listXxx), add it to the KNOWN_SAFE_API_METHODS set. This set uses a default-deny approach: any method not listed is treated as mutating and will be blocked when the CLI is authenticated with a read-only OAuth token (td auth login --read-only).
- Read-only methods (fetch/list/view): add to
KNOWN_SAFE_API_METHODS - Mutating methods (add/update/delete/archive/move): do NOT add — they are blocked by default, which is the correct behavior
4. Agent-Friendly Design Checklist
Every new command should satisfy these properties. They ensure the CLI works well for both humans and AI agents. See 7 Principles for Agent-Friendly CLIs for background.
Non-interactive by default — All input via flags, positional args, or
--stdin. Never usereadline,prompt(), or block waiting for TTY input. When a required argument is missing, callfailWithUsage(cmd)fromsrc/lib/missing-argument.ts— don't prompt.Structured, parseable output — Data commands must support
--json(and--ndjsonfor lists). Results go to stdout, diagnostics to stderr. Spinners auto-suppress when!process.stdout.isTTY(seesrc/lib/spinner.ts). Exit code 0 on success, non-zero on failure.Fail fast with actionable errors — Use
CliErrorwith a specific error code, a message naming the exact problem, and hints that include correct invocation syntax, valid values, or example commands. Validate all inputs before making API calls.Safe retries and explicit mutation boundaries — Mutating commands support
--dry-run. Destructive + irreversible commands require--yes. Create commands return the entity ID (useisQuiet()for bare ID output for scripting, e.g.id=$(td task add "Buy milk" -q)).Progressive help discovery — Parent command groups include
.addHelpText('after', ...)with 2–3 concrete examples. Every.description()is a clear one-line purpose statement. When a required positional arg is missing, callfailWithUsage(cmd): it prints help to stderr and exits 1, or throwsMISSING_ARGUMENTunder--json/--ndjson. Never a barecmd.help(), which prints to stdout and exits 0.Composable and predictable structure — Use consistent subcommand verbs (
list/view/create/update/delete/browse). Use consistent flag names across entities (--project <ref>,--json,--dry-run,--yes,--limit,--cursor,--all). Support--stdinfor text content where applicable (read it withreadStdin()from@todoist/cli-core, and test it withmockStdin()from@todoist/cli-core/testing).Bounded, high-signal responses — List commands use
paginate()fromsrc/lib/pagination.tswith--limit <n>,--cursor, and--allflags. When results are truncated,formatNextCursorFooter()tells the user how to fetch more. JSON output usesformatJson()orformatPaginatedJson()to return essential fields by default, passing the--fullflag for complete output.
5. Command Implementation (src/commands/<entity>/)
Commands with multiple subcommands use a folder-based structure:
src/commands/<entity>/
index.ts # registerXxxCommand — creates parent cmd, wires subcommands
list.ts # async function listXxx(...) — one file per subcommand
view.ts # async function viewXxx(...)
create.ts # async function createXxx(...)
helpers.ts # shared constants/utilities used by multiple subcommands (optional)
- index.ts: Imports all subcommand handlers, creates the Commander tree, exports
registerXxxCommand - Subcommand files: Export one async action handler + any option interfaces. Use
../../lib/for lib imports. No Commander imports (only index.ts uses Commander). - helpers.ts: Only needed when multiple subcommands share a utility/constant.
Single-subcommand commands (e.g., add.ts, today.ts) remain as flat files.
Adding a subcommand to an existing command
- Create a new file
src/commands/<entity>/<action>.tswith the handler function - Import and wire it in
src/commands/<entity>/index.ts
Flag convent
Install add-command in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
FAQ
What does the add-command skill do?
Guide for adding new CLI commands or subcommands to todoist-cli. Use when implementing new SDK endpoints, adding subcommands to existing command groups, or extending CLI functionality.
How do I install the add-command skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the add-command skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
by Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
by Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
by Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
by Anthropic