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 skillprints a guide. The agent reads it and runslocommands.lo mcpis an MCP server. The agent calls the operations of localspace as tools, and each tool checks its arguments. The toolguidegives the same guide.
You can use the two ways together.
Give the guide to the agent
Section titled “Give the guide to the agent”- Run
lo skillto read the guide. - Tell the agent to run
lo skillbefore 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.
Give the template guide to the agent
Section titled “Give the template guide to the agent”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.
- Run
lo skill templateto read the guide. - Tell the agent to run
lo skill templatebefore 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>.
Turn on the MCP server
Section titled “Turn on the MCP server”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:
mcp: enabled: trueTo turn the server off, use the same switch. Sessions that run at that time refuse each call immediately.
Register the server in the agent
Section titled “Register the server in the agent”The agent starts lo mcp for each session, as a stdio server. Register the command one time.
-
Run the command for your agent:
Terminal window claude mcp add --scope user localspace -- lo mcp # Claude Codecodex mcp add localspace -- lo mcp # Codex -
Start a new session of the agent.
Other clients, such as Cursor, read a JSON file. Add the server there:
{ "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.
Work in worktree mode
Section titled “Work in worktree mode”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.
- In the worktree, run
lo up, or call the toolupwithdirset to the worktree. - localspace makes a workspace with the name of the branch, and
feature/xbecomesfeature-x. - 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.
Run and test
Section titled “Run and test”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.
Handle the start guard
Section titled “Handle the start guard”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.
- The agent shows the message to you. The message tells which resource is short.
- You decide if the workspace must start anyway.
- If you agree, the agent calls
upagain withanyway: true. In the CLI, the agent runslo 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.
Handle errors
Section titled “Handle errors”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.
Keep your work safe
Section titled “Keep your work safe”The rules of localspace protect unsaved work. They apply to agents too.
remove_workspaceandlo rmrefuse 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
--forcedeletes 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_workspaceandsethave none. - A test run can leave untracked files in a checkout, such as
__pycache__.lo rmcounts them as unsaved work. The agent deletes them first. - The tool
servicemasks 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.
Plugin tools
Section titled “Plugin tools”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.