Agent CLI
Give the app a command line, so an agent can do everything a person can
do in the window:
tasks items add --title "Call the dentist"
. The app
binary is the CLI. Each command goes to the running app over a private
socket, runs there like a button press, and the window updates live.
text
Claude Code --bash--> tasks items add ... --socket--> Tasks.app (runs the command, saves, redraws)
Claude Desktop --MCP--> tasks mcp --socket--> same commands, same app
CLI, MCP, or App Intents
| Way in | Who uses it | Ship it |
|---|
| CLI | Claude Code, Codex, scripts, people in Terminal | Always. Agents learn it from , and it costs no context until used |
| MCP () | Claude Desktop and other clients with no shell | Optional. The same commands, one tool each. One line to register |
| App Intents | Siri, Spotlight, Shortcuts | Separate work. Agents cannot call them |
The CLI talks to the running app, never to the database file. Then there is
one writer, the app's checks and side effects run, and the window shows the
change at once. If the app is closed, the CLI opens it in the background.
Rules and reasons: rules.md.
1. List the commands
Read the user stories (
). Write each thing a person does as
a command,
, and mark it:
- read: , , . Safe to run any time.
- write: , , . Changes data, can be undone.
- destructive: , . Only reports what it would
do until is given.
Add
(is it running, what is open, counts) and
(show
a page in the window), so an agent can see and steer the app.
Check: every M1 story has its commands, and each command is marked.
2. Add the files
bash
"${CLAUDE_SKILL_DIR}/scripts/add-agent-cli.sh" <app-folder> <cli-name>
It copies
(core, socket, CLI, MCP, example
commands) and
, moves
to
, starts the socket
in the main view's
, and makes
link
. Apps not made from the template: do the same
by hand, following the script.
Check: the script printed "added the agent CLI", and
passes.
3. Write the commands
Replace the examples in
Agent/AgentCommands.swift
. Each command has a
name, a one-line summary, its params, a full example, its mark
(
or
), and a
that uses the same model code
as the window's buttons. Never copy logic: call the function the button
calls.
- Every model an agent touches gets . Commands
show the first 8 characters as , and accept any unique start of it.
- Results are small JSON objects: the fields an agent needs, not the
whole model. Lists take and , and return
and .
- Errors throw with a message that says how to fix it:
"no item with id 3f2a. Run ".
All the rules: rules.md.
Check:
lists every command from step 1, and
<cli-name> help <command>
shows its params and example.
4. Build and install
bash
./build.sh
<cli-name> help
installs the app and links
to the
binary inside it, so the CLI always matches the app. If the shell cannot
find it, add
to
in
.
Check:
prints the app's version.
5. Test
bash
"${CLAUDE_SKILL_DIR}/scripts/check-agent-cli.sh" <cli-name>
It starts a test copy of the app on a temporary database, checks help,
JSON output, error codes, every read command, and the MCP tool list, then
quits the test copy. Then run each write command once by hand, with
APP_STORE=/tmp/<App>-test.store
, and look at the window: the change shows
without a reload.
Check: the script prints
.
6. Teach agents
Write
.claude/skills/<cli-name>/SKILL.md
in the app's repo from
teach-agents.md: what the app is, the safety rules,
the main commands, and "run
for the rest". To use the
app from any folder, also copy it to
~/.claude/skills/<cli-name>/
. Add
one line to the app's
: "Drive the app with
. See
.claude/skills/<cli-name>/SKILL.md
."
Check: a fresh
claude -p "List my starred items with <cli-name>"
finds
the CLI and answers from real data.
7. MCP, when the user wants it
For Claude Desktop, or to get one approval prompt per tool:
bash
claude mcp add --scope user <cli-name> -- ~/Applications/<App>.app/Contents/MacOS/<App> mcp
codex mcp add <cli-name> -- ~/Applications/<App>.app/Contents/MacOS/<App> mcp
Claude Desktop: add it to
~/Library/Application Support/Claude/claude_desktop_config.json
under
, with the full path and
. More in
teach-agents.md.
Check:
shows the server as connected.
Done when every command from step 1 runs through the CLI against the
running app,
prints
, the app's repo
has the agent skill from step 6, and a fresh Claude Code session can do a
real task with it.