Connect your agent
Give Claude Code, Codex, Cursor and other AI agents the Cua Spaces tools from the app or the terminal, see what they can do, run agents inside a Space, and give them a provider key.
Connecting an agent gives it the cua skills and the cua MCP server. After
that, it can create Spaces, run commands in them, send files, show you the
desktop and share a Space whenever you ask.
Connect Claude Code to Cua Spaces and ask it to list your Spaces (35 seconds, no sound).
Connect from the app#
On first run, Pick your agent lists the agents found on this computer, most used first: Hermes, Claude Code, Codex, Cursor, then the rest. Each row names the settings file Cua changes. Every agent found starts ticked. Untick any you do not want, then press Continue: the app adds the Cua skills and MCP server to the settings of each ticked agent. Nothing is changed before you press Continue. If an agent was already open, close it and open it again. Connecting none is fine: untick every agent or press Choose later, then connect agents later in Settings, Connections.
Per computer#
Everything on this screen belongs to this computer only:
- The Cua skills and MCP server go into each agent's settings on this computer. On another computer, install Cua Spaces there and pick its agents.
- Sign-ins and keys stay on this computer too. Another computer keeps its own.
Codex and ChatGPT#
Codex signs in with your ChatGPT account on its own, with codex login. When
Codex is connected, the screen shows ChatGPT sign-in: press Sign in
and finish in the browser that opens. Codex keeps the sign-in on this computer,
and Cua never reads or copies it. On another computer, sign in to Codex there
(press Sign in in its first run, or run codex login).
An agent that Cua runs in a Space uses the provider keys saved on the computer that hosts the Space: the OpenAI key for Codex and the Anthropic key for Claude Code. Add them on Pick your agent or in Settings, Connections. They stay in this computer's Keychain (Credential Manager on Windows).
Claude Code and your Claude plan#
If you already use Claude Code on this computer, Cua can run it in your Spaces with the same Claude plan. Press Connect next to Claude Code in Settings, Connections. Before it reads anything, Cua says what it will do and waits for you to press Use my sign-in:
- Cua reads the sign-in Claude Code already keeps on this computer. On a Mac
that is the Keychain item "Claude Code-credentials", and macOS asks you to
allow it. On Linux and Windows, and when Claude Code keeps it in a file, it
is
.credentials.jsonin Claude Code's folder (~/.claude, or the folderCLAUDE_CONFIG_DIRnames). Who you are comes from Claude Code's.claude.json, which holds no tokens. - Cua keeps the access token in its own Keychain item, never your refresh token, and changes nothing about Claude Code's own sign-in. You stay signed in to Claude Code.
- This computer's own Claude Code uses it. Runs on your other computers and
Spaces don't get it unless you turn on Copy my sign-in to my other
computers (Settings, Connections, On another computer; off by default).
Then each Claude Code run there gets the access token as
CLAUDE_CODE_OAUTH_TOKEN. Only Claude Code gets it: Hermes and the other agents never do, and a Space has no refresh token to spend.
Sign in on another computer#
When Claude Code or Codex runs on another computer or Space that isn't signed
in, the agent's message offers Sign in to Codex on Mac mini (or Claude
Code). Cua starts the agent's own sign-in on that computer (codex login --device-auth, claude auth login) and shows you its link: open it on your
phone or computer and sign in with ChatGPT or Claude. Codex shows a short code
to type on that page; for Claude Code, paste the code the page shows back into
Cua. The message is then sent again. The sign-in stays in that computer's own
Claude Code or Codex, so you only do this once per computer; Cua never holds
it. A Space that is made again from its image asks again. For a team, use an
API key instead ("or use an API key").
The row then reads Signed in as you@example.com (Claude Max), the same words on the Claude Code page, the Anthropic row and the card an agent shows when it can't start.
An access token lasts a few hours. A refresh token works only once, so if Cua
refreshed it too, your own Claude Code would be signed out. Cua never refreshes.
When its copy is about to run out, the next run reads the newer one Claude Code
has refreshed on its own. If Claude Code hasn't run for a while, Cua asks Claude
Code to refresh its own sign-in (one short request through claude -p, at most
every five minutes). Only when there is nothing newer does the row read Needs
reconnect, with Reconnect: open Claude Code once, or run claude auth login, then press Reconnect.
If Claude Code isn't signed in on this computer, Cua offers the ways on in this
order: sign in with Claude Code (claude auth login in Terminal, then try
again), paste a token made with claude setup-token (a long-lived token for
people who prefer one), or use an Anthropic API key. Sign out removes Cua's copy
and never touches Claude Code.
To connect an agent later, or to remove one, open Settings, Connections:
- Press Connect next to a detected agent under Coding apps to set it up.
- Open the agent's row to switch Cua skills and Cua tools on or off, or press Remove Cua from the agent to take out what Cua added.
Connect from a terminal#
cua agents setup does the same as the app. It adds the cua skills and MCP
server to each agent you name.
cua connect detect # read-only: which supported agents are installed
cua connect setup --agents claude,codex --yes
cua connect status # what Cua configured for each agent
cua connect remove --dry-run # lists what it would remove
cua connect remove # removes only what Cua Spaces added (Cua Driver's entries stay)The supported agents include Claude Code, Codex, Cursor, Gemini CLI, Hermes, OpenClaw and more. If yours is not on the list, add the server by hand:
claude mcp add cua -- cua daemon mcp
codex mcp add cua -- cua daemon mcpcua daemon mcp starts cua daemon if it is not running, so every agent on
this computer shares the same Spaces, sandboxes and streams.
Only the sign-in#
Sometimes you want the Claude sign-in for the Spaces and nothing else, for
example for a demo, or for a home Space that runs Claude Code and must not touch
how Claude Code on your Mac is set up. Add --sign-in-only:
cua connect setup --sign-in-onlyIt does what Use my sign-in does and no more. It adds no Cua skills and no
Cua server to Claude Code, so ~/.claude.json and ~/.claude/skills are not
changed, and it never starts Claude Code to refresh its sign-in: a sign-in that
has run out is refused with a plain sentence, and you open Claude Code once and
try again. It keeps the access token only, in Keyvault on this Mac, and never
prints it. The only things it writes are inside the Cua folder. On a Mac, macOS
asks once whether Cua may read the Keychain item "Claude Code-credentials":
that question is yours to answer, and Cua has no way around it. Undo it with
cua connect remove --sign-in.
Check that it works#
- If your agent was already running, start a new session. Agents load their tools when a session starts.
- Ask: "List my Cua Spaces."
- If your agent asks permission to use a
cuatool, allow it. Agents ask in their own window or terminal.
Then try the request the app offers at the end of its first run. The agent makes a Space on this computer:
Make a Linux Space on this Mac and show its desktop in a new window.
On Windows the request says "this PC", and on Linux "this computer". When that works, try a bigger task:
| Ask your agent | What it does |
|---|---|
| "Open a Linux Space and run my test suite in it" | Creates a Space, uploads your project and runs the tests inside it (create_space, upload, space_bash). |
| "Use my Space's browser to finish the checkout test and show me" | Moves your signed-in browser session into the Space, then drives the Space's browser (teleport_browser_session). |
| "Share this Space with a teammate as a viewer" | Shares the Space with read-only access (share_space). Cua Spaces asks you to confirm first. |
Open the Space in Cua Spaces to watch it work. What your agent can do lists the tools it gets.
What your agent can do#
By default the cua MCP server gives an agent every Spaces tool except the few that are for a person only, plus sandbox, computer, skills and other tools. MCP tools lists each one with the permission that gates it, and Limit what an agent can do narrows the set. For the computer the agent runs on, use Cua Driver instead. The main ones:
list_spaces / create_space {reuse} -> pick, reuse or create a Space
space_bash {space, command} -> run commands inside it
send_file {space, path} -> drop a host file into ~/Downloads (sha256-verified)
stream_endpoint -> a ticketed media URL
list_tools / call_tool -> cua-driver tools in the Space, or any declared service
delete_space {space} -> delete it and stop meteringspace is an id or a name. A tool whose feature the Space lacks returns
capability_missing. For every tool and its parameters, see the
Spaces reference.
Limit what an agent can do#
Give an agent that only needs to look read-only access:
claude mcp add cua -- cua daemon mcp --permissions spaces:readonlySee permissions for the full list.
space_bash, send_file, teleport_app and hotspot_start act with your
authority. Grant spaces:readonly to agents that don't need to change
anything.
Run an agent inside a Space#
An agent can also start other agents inside a Space, as long-lived threads.
| Tool | Does |
|---|---|
agent_capabilities | Ready harnesses (claude-code, openai-codex). |
agent_start {space, agent, prompt, show} | Start a detached run. show tails it in a terminal on the Space desktop. |
agent_message {space, run_id, text, force} | Next turn. Refused mid-turn unless force. |
agent_status, agent_list, agent_stop | State, output tail, stop. |
Runs live in the guest (~/.spaces-agents/<run_id>/) and survive the client
going away. Host credential files are never copied into the Space: an API
key reaches a run only as env you name for that run (env_from_host), or as
a key saved in Settings → Connections for that harness.
In TypeScript a run is a thread:
import { embedded } from "@trycua/cua"
import { startThread } from "@trycua/cua/spaces"
const bot = await startThread(embedded().spaces(), {
agent: "claude-code",
prompt: "Open the repo in the Space and run the tests",
placement: { type: "dedicated", on: "local", deleteOnClose: true },
})
await bot.send("Now fix the failing test")
console.log(await bot.status())
await bot.close() // stops the run and deletes the Spaceplacement shared ({ type: "shared", space, acknowledgeNoIsolation: true })
reuses a Space you name. adoptThread(spaces, spaceId, runId) reattaches.
The lower-level calls are one run per thread and one message per turn. A message sent mid-turn is refused (or queued) unless forced, so show the reason. The TypeScript and Rust tabs are from the examples in other languages, and the Swift tab is from Cua Bots.
const report = await space.agentStart(bot.agent, prompt, false, options)
const t = new BotThread(bot, report.runId, space)const r = await this.space.agentMessage(this.runId, message, false)
if (!r.ok) {
this.fold.note(this.turns.length, `Refused: ${r.reason}`)
return { accepted: false, reason: r.reason }
}Agent keys#
Claude Code, Codex and the other harnesses need a provider key to run. Add it once in Cua Spaces, Settings, Connections, and every agent you start in a Space gets the key it needs.
- Anthropic (
ANTHROPIC_API_KEY): Claude Code and other agents that use Claude. - OpenAI (
OPENAI_API_KEY): Codex and other agents that use OpenAI models. - Another key: save it under the variable its agent reads, like
GEMINI_API_KEYorOPENROUTER_API_KEY.
Each provider is one row under Providers, which shows only •••• and the
key's last four characters. Click the row for when you added it, the apps it
works with, Disconnect, and Add another key if you keep more than one.
A key is never shown again after you save it. Hermes, OpenCode, Goose, Pi and
OpenClaw can be pointed at any connected provider or key from their Provider
row (see Connections).
Cua in Terminal, the cua command, installs from Settings, General.
The same works from the cua CLI. The key is read from stdin, so it never lands
in your shell history:
cua agent keys
pbpaste | cua agent keys set anthropic
cua agent keys set other --env GEMINI_API_KEY < gemini.key
cua agent keys rm OPENAI_API_KEYWhich agents get a key#
When an agent starts (agent_start, a persistent agent's turn, a routine), the
Cua daemon adds the saved keys that agent's harness reads, and no others: a
Claude Code run gets ANTHROPIC_API_KEY, a Codex run gets OPENAI_API_KEY, and
a Gemini CLI run gets neither. A key you pass yourself (env, or env_from_host
from the daemon's environment) wins over a saved one.
- Other keys reach a run only when its harness reads that variable, or when
the caller names it in
env_from_host. - A custom endpoint (
base_url) gets no saved key unless it is named inenv_from_host, so a key is never sent to a proxy you didn't mean it for. - In the Space the key is written 0600 into the run's own directory and redacted from the run's event log, like any key a run gets.
agent_capabilities counts saved keys: a harness whose key is saved reports
auth: ok. A run with no key fails before anything is installed, and the error
says to add the key in Settings, Connections or to set it for the Cua daemon.
Where the keys are kept#
The Cua daemon keeps the keys in one item of your login Keychain (service
ai.cua.session, the same item service as your Cua sign-in). The item trusts the Cua apps of this
Mac, so the app, the daemon and the cua CLI read it without a prompt, and
agents started at night by a routine still get their key.
The keys are not kept in the Keyvault. The Keyvault holds app sessions and passwords that you approve one use at a time and can lock. A provider key has to reach an agent the moment it starts, unattended, with no vault to set up first.
Agents never see this list. agent_keys.list, agent_keys.set and
agent_keys.remove are methods of the daemon for the Cua app, not MCP tools:
no agent can read, add or remove a key. Their answers carry only the provider,
the variable, the last four characters and when the key was added. Keys never
go to logs or usage data.
A build of cua that keeps its session in a file can't save agent keys, with one
exception, the Local development channel. On the Stable channel (Linux today,
or an unsigned build) agent keys are never written to a plain file. Set the key
in the Cua daemon's environment there instead (export ANTHROPIC_API_KEY=...,
then cua daemon stop and cua daemon start) and name it in env_from_host.
The Local channel, used to develop Cua itself, does save them: it writes an
agent-keys file with mode 0600, unencrypted, and warns you. Don't put real
production keys in it. Windows uses the Credential Manager the same way as the
macOS Keychain.
If it doesn't work#
| What you see | What to do |
|---|---|
The agent has no cua tools | Run cua agents status. Then start a new session in the agent. In Hermes, run /reload-mcp. |
"The Cua daemon isn't running. Start Cua, or run cua daemon start." | Open Cua Spaces, or run cua daemon start. |
| Your agent is not in the app's list | Run cua agents detect to see every supported agent, or add the server by hand as shown above. |
| The agent can't reach a Space on another computer | Sign in on this computer, and make sure the computer is added to your account. See Add a computer. |
Next#
- Create a Space: run an agent's work in a new desktop.
- Add a computer: give your agent another computer.
- Agents in a Space: agents with a name, a memory and schedules.