A terminal workspace for Markdown writing, agent edits, and passage-by-passage review, backed by Git.
Edit a document yourself or work beside an agent. Save drafts in ordinary Git history, inspect what changed, and keep or restore individual passages.
Margin desk with Claude Code connected to Z.ai (GLM-5.3). The agent recommends edits on the left. Margin shows changed passages and review controls on the right. You can also use Margin without an agent.
- Write: edit Markdown source with autosave, selection, undo, and recovery.
- Review: compare before and after, keep clearer prose, and restore unwanted changes.
- Work with an agent: request edits to selected text while you continue writing.
- Browse history: read earlier versions and restore a document through a new commit.
- Control the scope: choose which Markdown files Margin captures and reviews.
Saving, checkpointing, and reviewing are separate actions:
| Action | Result |
|---|---|
| Save | Write the current text to the working file |
| Checkpoint | Preserve the writing scope in a Git commit |
| Review | Apply keep or restore decisions and record the review |
Saving and checkpointing never approve changes. Agent results still need review.
You need Git and Rust with Cargo. The repository pins its Rust toolchain
in rust-toolchain.toml. The optional desk also needs tmux 3.1 or newer.
git clone https://github.com/nibzard/margin.git
cd margin
cargo install --path . --locked
margin --helpCargo installs margin in its binary directory, usually ~/.cargo/bin.
Add that directory to your PATH if your shell cannot find the command.
See the support matrix for tested platforms and versions.
Run these commands from the cloned Margin repository in one Bash session. They create a separate temporary Git repository.
MARGIN_EXAMPLES="$PWD/examples"
MARGIN_DEMO=$(mktemp -d "${TMPDIR:-/tmp}/margin-demo.XXXXXX")
mkdir -p "$MARGIN_DEMO/content"
cp "$MARGIN_EXAMPLES"/before/*.md "$MARGIN_DEMO/content/"
cd "$MARGIN_DEMO"
git init -b writing
git config --local user.name "Demo Writer"
git config --local user.email "demo@example.test"
margin init --scope content/Apply the supplied edits, checkpoint them, and open the review:
cp "$MARGIN_EXAMPLES"/after/*.md content/
margin checkpoint --message "Revise the garden documents"
margin tui --view changesIn Changes, use n and p to move between passage groups.
Press K to keep a change or r to restore its earlier text.
Press Enter to inspect the finish summary, then Enter again to apply it.
Undecided changes are kept when you confirm.
The examples include a shorter opening and unconfirmed changes to times and measurements. Try keeping the opening and restoring the facts. See the full walkthrough for scripted review and historical restoration.
From an existing Git repository, choose a directory of Markdown documents:
margin init --scope content/
margin tuiReplace content/ with your writing directory. Initialization records its
starting point. Files outside the writing scope stay outside capture and review.
Use margin status to check what is saved and what still needs review.
Open a document directly with margin content/article.md. Paths are relative
to the repository root.
Click Commands or press Ctrl+P to find actions, documents, headings,
and requests. The palette preserves your text and selection when you cancel.
Use Requests to inspect work, compare proposals, cancel, or retry delivery.
In an uninitialized Git repository, e opens a writing-scope preview.
Confirm it with Enter, or cancel with Esc.
Press e in Read to edit Markdown source. Margin saves after a
750-millisecond pause. Press Esc to save and return to reading.
Switching documents retains your cursor and undo history.
Press C in reading to checkpoint the writing scope and open Changes.
This retains review decisions for unchanged patches and reports retained and
reset counts. Changed or uncertain groups return to undecided.
| Key in the reading or review interface | Action |
|---|---|
1 / 2 / 3 |
Open Read / Changes / History |
Tab / Shift+Tab |
Move focus between interface areas |
f |
Find and open a document |
/ |
Search the current view |
Ctrl+F |
Search source across the workspace |
: |
Find actions, documents, and headings |
? |
Open contextual help |
] in Changes |
Jump to the next undecided group |
E in Read |
Open the configured external editor |
Review decisions are saved locally and remain unapplied. Quit flushes progress;
use Resume saved review in : to return. Resume checks the complete review
identity and requires a fresh finish confirmation. Changed comparisons leave
older drafts available for inspection.
The : palette accepts ordinary typing and paste as query text. Arrows select,
Enter opens, and Esc closes. In reduced-update mode, Enter first matches an
edited query; a later Enter opens its result.
Use Pin current document as reference, Pin selected version as reference, or Choose reference… in the palette to keep a read-only snapshot nearby. Reference scroll and search are independent. Working snapshots refresh only on request. Return to review before editing, deciding, restoring, or finishing. See the workspace guide.
While editing, use F1 for help. Ordinary keys insert text instead of running
reading or review actions. Ctrl+Z and Ctrl+Y undo and redo source edits.
Use Shift with movement to select text.
You can click documents, headings, tabs, and change groups. Click a reading
passage to edit it. The wheel scrolls; in the editor, it leaves the cursor in place.
Inside tmux, pointer input needs your mouse on setting. Margin does not change it.
Hold Shift for your terminal's text selection.
To configure an external editor, for example Neovim:
margin init --editor-argv-json '["nvim", "--"]'
margin edit --path content/article.mdSee the editing guide for all editor shortcuts, save conflicts, recovery, and source-size limits.
Run an installed agent beside Margin in a tmux desk:
margin desk -- claudeReplace claude with your agent's executable and arguments. Margin does not
install or authenticate the agent. The screenshot uses Claude Code configured
for Z.ai; that provider is optional.
In a side-by-side desk, Margin occupies the left 70% and the agent the right 30%.
Inside tmux, the desk adds a window. Outside tmux, it creates and attaches to
a dedicated session. Narrow terminals use separate windows instead of split
panes. Quitting Margin leaves the agent running. Without tmux, run margin tui
and your agent in separate terminal tabs.
To request an edit, select source and press F2. Type an instruction and press
Enter. An empty selection requests the whole document. Margin saves the latest
text before creating the request. You can continue writing while the agent works.
The agent must use Margin's request commands to return a result. Other edits to files are treated as external changes. For Claude Code, install the optional integration from your writing repository:
margin hook install claude --dry-run
margin hook install claudeThe installer adds local hook settings and managed guidance in CLAUDE.md and
AGENTS.md. It preserves unrelated settings and refuses to replace edited
guidance blocks. Starting a desk alone does not install this integration.
Queued requests reach Claude Code at startup or on your next prompt. Margin tracks
delivery per Claude session and shows waiting and delivered counts. Requests do not interrupt
an active turn. Other agents can use the request commands.
Results preserve supported separate edits and pause on conflicts. In the editor,
F6 shows conflict details, F3 uses the proposal, and F4 keeps your text.
Ctrl+U undoes the latest applied agent edit when later changes would not be overwritten.
Press B in reading to inspect requests.
An agent can also show you a document without taking keyboard focus:
margin open content/article.md --line 42Run this command from the desk's agent pane. See the desk link guide for clickable links and terminal setup.
Use --help on any command for its options and --json for structured results.
| Command | Purpose |
|---|---|
margin status |
Inspect capture and review state |
margin context --json |
Inspect writing context and pending requests |
margin checkpoint --message "Revise the opening" |
Save a draft commit |
margin diff |
Compare the draft with the last valid review baseline |
margin diff --working |
Inspect working changes before checkpointing |
margin review --input review.json --dry-run |
Preview a review plan |
margin review --input review.json |
Apply the review plan |
margin log |
Browse writing history |
margin show --path content/article.md --revision HEAD |
Read a saved document |
margin restore --input restore.json |
Restore a historical document through a new commit |
margin note --text "Keep the concrete example" |
Attach feedback to the current checkpoint |
margin requests list --json |
Inspect agent requests |
margin doctor |
Inspect recovery state |
Review plans use identifiers from margin diff --json. Repeating a completed
review or restoration request returns its receipt. Historical restoration leaves
the restored content pending review. The example walkthrough
builds valid plans from your repository's current history.
Margin is under active development. Try it in the disposable example repository before adopting it for your writing.
- Source editing, review, history, and agent requests are implemented.
- Linked Git worktrees remain inspection-only.
- Source editing supports files up to 1 MiB. Use an external editor for larger files.
- Conflict checks cannot prevent every race with unrelated editors or Git commands.
- Physical terminal link checks and pointer hover remain open work.
See the documentation and plan index for delivery status and remaining work. to-do.json is a backlog snapshot and can lag current implementation.
Run these commands from the Margin repository:
cargo build --locked
cargo test --all-targets --lockedTests use temporary Git repositories to check content, history, scope, and recovery.
The desk suite needs tmux 3.1 or newer. It skips with a notice when tmux is unavailable.
Set MARGIN_REQUIRE_TMUX=1 to make missing tmux a failure.
The continuous integration (CI) workflow runs pull-request and nightly verification tiers. See CI setup, the support matrix, and the terminal smoke matrix for requirements and evidence.
- Example walkthrough
- Source editing, agent requests, and recovery
- Behavior and design specification
- Notes and feedback
- Review plan schema
- Notes schema
- Formal review model and mutation checks
Licensed under the Apache License 2.0.
