Skip to content

Use localspace with coding agents

A coding agent can run and test its change in a workspace. The workspace has separate ports, databases and env, so the agent does not collide with you or with other agents.

localspace gives an agent two ways to work:

  • lo skill prints a guide. The agent reads it and runs lo commands.
  • lo mcp is an MCP server. The agent calls the operations of localspace as tools, and each tool checks its arguments. The tool guide gives the same guide.

You can use the two ways together.

  1. Run lo skill to read the guide.
  2. Tell the agent to run lo skill before it uses localspace.

The guide tells the agent how to find its workspace and how to start it. It also tells how to read logs, how to run tests and how to clean up. It shows where the templates are, how to select branches with --match, and the effect of each --force. lo skill --json prints the same text in the markdown field.

An agent that uses MCP has no shell for this. The server tells it to call the tool guide before it uses localspace.

An agent can also write or change a template, or the .localspace.yaml file of a repository. For this work, lo skill template prints a second guide.

  1. Run lo skill template to read the guide.
  2. Tell the agent to run lo skill template before it writes a template.

The guide tells where templates live and which fields the file has. It gives the syntax of the references, and it has short examples. It tells the agent to check the file with lo template validate <name> and to read the template reference for all fields. lo skill template --json prints the text in the markdown field. An unknown topic fails with the code invalid.

An agent that uses MCP calls the tool guide with topic set to template. The tool templates checks a template with template, or the .localspace.yaml of a repository with dir. In the CLI, the agent runs lo template validate <name> or lo template validate <path>.

The MCP server is off by default. It lets an agent start and stop workspaces and run commands in services. You decide to give that power to agents. When the server is off, lo mcp stops and prints an error.

Use one of these two ways:

  • Open the dashboard, go to Settings and MCP, and turn on Serve coding agents.
  • Add this to config.yaml:
~/.localspace/config.yaml
mcp:
enabled: true

To turn the server off, use the same switch. Sessions that run at that time refuse each call immediately.

The agent starts lo mcp for each session, as a stdio server. Register the command one time.

  1. Run the command for your agent:

    Terminal window
    claude mcp add --scope user localspace -- lo mcp # Claude Code
    codex mcp add localspace -- lo mcp # Codex
  2. Start a new session of the agent.

Other clients, such as Cursor, read a JSON file. Add the server there:

mcp.json
{
"mcpServers": {
"localspace": { "command": "lo", "args": ["mcp"] }
}
}

If the client does not get the PATH of your shell, write the full path of lo in command. The MCP section of the dashboard shows the commands with the full path of your lo.

Worktree mode is the shortest path for an agent. The agent works in a git worktree of a repository that has a .localspace.yaml file.

  1. In the worktree, run lo up, or call the tool up with dir set to the worktree.
  2. localspace makes a workspace with the name of the branch, and feature/x becomes feature-x.
  3. The workspace runs the code of the worktree in place. It does not copy the code.

If the repository has no .localspace.yaml, the agent makes a workspace from a template. It runs lo new <name> --template <template> <service>=<branch> and then lo up <name>. The tools are new_workspace and up. See branches and templates.

The agent uses these commands and tools in a work cycle:

Task Command Tool
Read the guide lo skill guide
Find the workspace lo ls --json workspaces
Start it lo up up
Read the logs lo logs logs
Find the reason for a crash lo runs logs with runs
Run the tests lo exec exec
Reset a database lo db reset db_reset
Stop it lo down down

up waits until each service is ready. The result lists the units that did not start in failed. See MCP tools for all tools.

If the machine has less free memory or disk than the workspace used on average, up refuses and starts nothing. This is the start guard. It prevents a start that makes the machine slow.

  1. The agent shows the message to you. The message tells which resource is short.
  2. You decide if the workspace must start anyway.
  3. If you agree, the agent calls up again with anyway: true. In the CLI, the agent runs lo up <workspace> --yes.

The agent must not use anyway or --yes without your agreement. If localspace has no usage data, or if you turn off Usage history, the guard does not refuse.

When a call fails, the tool result is an error. The CLI with --json prints the same text:

{ "error": { "code": "conflict", "message": "..." } }
Code Meaning Action of the agent
invalid The request or the template is incorrect. Corrects the arguments or the template.
not_found The workspace, the template, the service or the resource is not there. Finds the name with workspaces.
conflict The state refuses the request. Reads the message. It does not work around the refusal.
unavailable Docker, a git remote or a plugin is down. Reports it.

See errors for more.

The rules of localspace protect unsaved work. They apply to agents too.

  • remove_workspace and lo rm refuse if a worktree that localspace made holds uncommitted or unpushed work. The agent must commit and push, and then call again.
  • localspace does not touch a worktree that it did not make. An agent must not remove such a worktree.
  • Each --force deletes or breaks something. The guide tells the agent to run it only after you agree.
  • The only MCP tool with a force option is down. It stops a workspace that other workspaces use. remove_workspace and set have none.
  • A test run can leave untracked files in a checkout, such as __pycache__. lo rm counts them as unsaved work. The agent deletes them first.
  • The tool service masks the values of secrets in the env that it gives.
  • Each tool has an effect: it reads, it changes, or it destroys. The client uses the effect to prompt you before it calls a tool that can lose data.

A plugin can add tools to the MCP server. They show in the list of the MCP section, with the name of the plugin. A plugin that you install while a session runs adds its tools to the next session. See write a plugin.