setup: Add script to share agent state via container home symlinks

This commit is contained in:
Jeena 2026-09-12 21:38:39 +09:00
parent a3aa03e14d
commit d110942710
2 changed files with 119 additions and 0 deletions

View file

@ -31,6 +31,14 @@ source ~/Projects/agent-container/agent.aliases
This makes the `opencode`, `claude`, `pi`, and `agent-container` commands available in new sessions, plus the `opencode-local`, `claude-local`, and `pi-local` variants that run the tools directly on the host.
Optionally run the setup script to share agent state (`.claude`, `.pi`, `.agents`, OpenCode state, ...) between the container and the host:
```sh
~/Projects/agent-container/setup.sh
```
It moves existing state into the container home and symlinks it back into `$HOME`, so containerized tools and the `*-local` variants share logins, settings, and history. See "Sharing agent state between host and container via symlinks" below. The script is safe to re-run and skips items it cannot handle safely.
The container home directory at `$XDG_DATA_HOME/agent-container/container-home/` serves as a central `$HOME` inside every container, independent of which project directory you start in. Everything written to `$HOME` inside the container persists there.
## Environment Variables
@ -85,6 +93,8 @@ To remove all containers, the image, and the persistent home directory:
agent-container purge
```
Note that this also deletes the shared agent state that lives in the container home (`.claude`, `.pi`, ...). The symlinks in your `$HOME` will dangle afterwards.
## Sharing host config files via hard links
The container home at `~/.local/share/agent-container/container-home/` is mounted as `/home/<username>` inside every container. You can hard link files from your real `$HOME` into this directory so the container sees them without copying or syncing.
@ -102,6 +112,10 @@ Avoid linking sensitive files such as `~/.ssh/id_*` or `~/.gnupg/` -- keeping th
## Sharing agent state between host and container via symlinks
The repository ships a `setup.sh` script that automates the following for `.claude`,
`.claude.json`, `.pi`, `.agents`, and the OpenCode state directories. The manual
recipe for any other directory looks like this:
State directories such as `.claude/`, `.pi/`, or `.agents/` can be shared between the
containerized tools (`claude`, `pi`, `opencode`) and their local variants
(`claude-local`, `pi-local`, `opencode-local`). Keep the real data in the container home