agentleFS
hqhq1025hqhq1025/clipaste/AGENTS.md

clipaste

AGENTS.md60 starsChanged 3 months agoMITView on GitHub

Instructions for coding agents working with clipaste — both installing it for a user and contributing to this repository. clipaste is a clipboard daemon that makes screenshot paste work in terminal AI tools (Claude Code, Codex CLI, Cursor CLI), locally on macOS/Windows and across SSH/WSL2 boundaries. Graphical Linux hosts provide read-only PNG clipboard capture for the SSH bridge. This is the entry point. It classifies the machine, runs the checks that are meaningful for that machine, and returns fix commands…

  • Reads credentials
  • Installs packages
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository3 other files it gives its agents.

The file

Show its rules and text

We split this AGENTS.md into the rules it gives an agent

22 rules. About 0 are common, 3 are distinctive, and 19 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 19

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Do not guess at the state of a clipaste install — ask doctor.

    line 23
  2. Distinctive:

    Do not reclassify those consumers as hosts.

    line 109
  3. Very specific:

    Ensure the appropriate binary directory (~/.local/bin for the extracted archive or normally ~/.cargo/bin for Cargo) is on PATH.

    line 146
  4. Very specific:

    All Wayland clipboard accesses use wl-paste --watch in bounded one-shot mode, which refuses popup fallback and verifies actual compiled-in …

    line 168
  5. Very specific:

    Run host diagnostics as the same desktop user and in the same session.

    line 177
  6. Very specific:

    No display produces actionable guidance to start from a graphical desktop or configure a consumer.

    line 182
  7. Very specific:

    Keep cache directories 0700 and files 0600, with no automatic expiry.

    line 197
  8. Very specific:

    Run this on the local macOS, Windows, or graphical Linux clipboard host, not on the remote consumer.

    line 204
  9. Very specific:

    Run this inside the WSL2 distro, with clipaste.exe already running on Windows:

    line 223
  10. Very specific:

    Never tell a user to press Cmd+V in an SSH session: that sends the *local* file path as text, which the remote agent cannot open.

    line 256
  11. Very specific:

    Verify with clipaste doctor --json: the daemon check detail contains server-only.

    line 276
  12. Very specific:

    Do not install a Linux systemd service automatically or present it as a fix for missing desktop access.

    line 284
  13. Very specific:

    Do not classify all Linux machines as hosts or as unsupported-host: actual SSH sessions and configured headless consumers retain ssh-remote …

    line 288
  14. Very specific:

    Do not bind the daemon to 0.0.0.0 or add firewall exceptions to "fix" connectivity.

    line 290
  15. Very specific:

    Do not write shims by hand.

    line 293
  16. Very specific:

    Do not kill -9 the daemon to restart it.

    line 295
  17. Very specific:

    Do not report success without a passing clipaste doctor.

    line 298
  18. Very specific:

    Generated shell must be syntax-checked in tests: Every shim and setup script is asserted against bash -n.

    line 365
  19. Distinctive:

    No silent fallbacks: When detection fails, list what was tried and why, and say what the user should do.

    line 368
  20. Distinctive:

    Run the Release workflow manually on the release commit to validate packaging without publishing.

    line 379
  21. Very specific:

    After validation, tag vX.Y.Z and push.

    line 383
  22. Very specific:

    Update the Homebrew formula in hqhq1025/homebrew-clipaste.

    line 385

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

Instructions for coding agents working with clipaste — both installing it for a user and contributing to this repository.

clipaste is a clipboard daemon that makes screenshot paste work in terminal AI tools (Claude Code, Codex CLI, Cursor CLI), locally on macOS/Windows and across SSH/WSL2 boundaries. Graphical Linux hosts provide read-only PNG clipboard capture for the SSH bridge.


Part 1 — Installing clipaste for a user

The one command that tells you what to do

clipaste doctor --json

This is the entry point. It classifies the machine, runs the checks that are meaningful for that machine, and returns fix commands or guidance where available. Do not guess at the state of a clipaste install — ask doctor.

{
  "version": "2.4.1",
  "os": "macos",
  "role": "clipboard-host",
  "status": "warn",
  "checks": [
    {
      "name": "daemon",
      "status": "ok",
      "detail": "daemon responding on 127.0.0.1:18340",
      "fix": null
    },
    {
      "name": "clipboard",
      "status": "warn",
      "detail": "no image staged yet — take a screenshot, then re-run doctor",
      "fix": null
    }
  ]
}
FieldContract
roleclipboard-host / ssh-remote / wsl2 / unsupported-host decides which checks apply
statusworst of all checks: ok, warn, fail
checks[].statusok / warn / fail
checks[].fixa remediation command or guidance, or null when no single command applies
exit code0 usable (ok or warn), 1 broken, 2 bad arguments

A warn is not a failure. "No screenshot on the clipboard yet" is the normal state of a freshly installed machine — do not report it to the user as a problem, and do not try to fix it.

Consumers of the JSON output must accept unsupported-host for platforms without a backend. Do not apply it to Linux as a whole: Linux host diagnostics must distinguish missing tools, missing session access, and missing compositor data-control from consumer helper or bridge failures.

Decide where you are before installing anything

clipaste has two sides and they install differently. Getting this wrong is the single most common mistake.

OS / contextLocal clipboard-host daemonConsumer of another host's clipboard
macOSSupportedSSH remote via clipaste-paste
WindowsSupportedVia WSL2
Native Linux desktopRead-only image/png via Wayland data-control or X11/XWaylandSupported over SSH via shims / clipaste-paste
Headless LinuxNo display; host startup fails with guidanceSupported with configured helpers / SSH
WSL2No; the Windows daemon is requiredSupported via wsl-setup
Clipboard host                              Consumer
macOS / Windows / graphical Linux
  PNG cache -> loopback HTTP -> SSH tunnel -> SSH remote
  run ssh-setup on this host                 shims / clipaste-paste

Windows -> HTTP over WSL networking -------> WSL2
  Windows daemon                            run wsl-setup inside the distro

Local macOS / Windows: existing clipboard normalization and paste
                       (skipped with CLIPASTE_SERVER_ONLY=1; HTTP serving remains)
Local Linux: read-only PNG capture, no added text-path paste

clipaste doctor --json reports which side you are on as role. Trust it over uname: an SSH session into a Mac is ssh-remote, not clipboard-host.

The role contract applies in this order:

  1. WSL context: wsl2, even if SSH environment variables are also present.
  2. An actual SSH session: ssh-remote, including SSH into macOS.
  3. A local macOS or Windows machine, or graphical local Linux session: clipboard-host. Linux backend access still needs validation.
  4. A headless Linux machine with a configured consumer helper: ssh-remote, even without SSH environment variables; keep checking its helper and bridge.
  5. Linux without a display or consumer indicators: clipboard-host with a failing backend check and actionable graphical-session guidance. Other platforms without a backend or consumer indicators retain unsupported-host.

WSL remains a Windows consumer even when WSLg supplies display variables. SSH session detection takes precedence over a Linux desktop's display variables. Do not reclassify those consumers as hosts.

Install on the clipboard host

macOS:

brew install hqhq1025/clipaste/clipaste
brew services start clipaste
clipaste doctor --json

Windows (PowerShell, no admin needed):

irm https://raw.githubusercontent.com/hqhq1025/clipaste/main/install.ps1 | iex
clipaste doctor --json

Linux desktop (Ubuntu package example):

sudo apt install wl-clipboard xclip curl

Releases since v2.5.0 include static Linux archives for x86_64-unknown-linux-musl and aarch64-unknown-linux-musl. Download the matching architecture, verify against the release's SHA256SUMS, extract it, then:

install -Dm755 clipaste "$HOME/.local/bin/clipaste"
export PATH="$HOME/.local/bin:$PATH"
clipaste

Source installation with Rust/Cargo is also supported: cargo install --git https://github.com/hqhq1025/clipaste --tag v2.6.0 --locked. Ensure the appropriate binary directory (~/.local/bin for the extracted archive or normally ~/.cargo/bin for Cargo) is on PATH. Start clipaste as the desktop user in a graphical-session terminal and leave it running. No Linux service or auto-start entry is installed. In a separate terminal from that same session, run:

clipaste doctor --json
clipaste ssh-setup user@host

For development, cargo build --release works from the checkout. Linux retains doctor and consumer setup, including wsl-setup; do not add a blanket compile_error! gate that blocks consumer machines.

Linux backend and verification contract

  • CLIPASTE_BACKEND=auto is the default. Prefer real system wl-paste with usable data-control access; otherwise warn and use system xclip through an accessible DISPLAY, or fail with actionable guidance if unavailable. HTTP consumer shims do not count as system clipboard tools.
  • Native Wayland requires wl-clipboard >=2.2 for empty-selection watch events. All Wayland clipboard accesses use wl-paste --watch in bounded one-shot mode, which refuses popup fallback and verifies actual compiled-in data-control support. Ext-only compositors need wl-clipboard >=2.3 built with ext-data-control support; wlr-data-control works with compatible 2.2+ builds. Version 2.1.x triggers the auto XWayland fallback or fails without DISPLAY; a version number alone does not establish protocol support.
  • CLIPASTE_BACKEND=wayland requires native data-control access and fails instead of falling back. CLIPASTE_BACKEND=x11 requires xclip and an accessible DISPLAY. Use the same override for the daemon and doctor.
  • Run host diagnostics as the same desktop user and in the same session. Wayland needs WAYLAND_DISPLAY and XDG_RUNTIME_DIR; X11/XWayland needs DISPLAY and display authorization. SSH, sudo, stale tmux environments, and services can lack that context. Setting a variable alone does not establish display access.
  • No display produces actionable guidance to start from a graphical desktop or configure a consumer. Wayland-only sessions without data-control must fail with guidance to use XWayland (xclip + DISPLAY) or an X11 session. Never use focus-stealing windows or arbitrary forced-focus Wayland polling.
  • GNOME Wayland may require its XWayland clipboard bridge. Require reporters to copy a screenshot from a native Wayland app, re-run doctor, then verify the image fetched on the remote with clipaste-paste. An X11-only test is insufficient, and a backend probe is not universal compatibility evidence.
  • Linux polls every 300 ms and reads image/png without modifying the clipboard. It saves to the private stable PNG cache, then serves through existing loopback HTTP and SSH shims / clipaste-paste. It does not add file URLs or text, and does not promise local terminal text-path paste. Image file-copy offering only a URI is not supported yet.
  • Clipboard clears, non-image content, and recognized private markers clear the staged image. Historical cache paths remain; this is not cache erasure. Keep cache directories 0700 and files 0600, with no automatic expiry.
  • Preserve existing macOS/Windows clipboard normalization and paste workflows. Linux tests do not establish macOS/Windows regression coverage or universal desktop compatibility; report exactly which platforms were verified.

Wire up an SSH remote

Run this on the local macOS, Windows, or graphical Linux clipboard host, not on the remote consumer. It needs the local daemon running, and it edits the local ~/.ssh/config.

clipaste ssh-setup user@host             # non-interactive; idempotent
clipaste ssh-setup user@host -p 22222    # custom SSH port

It detects the remote OS itself and installs the right helpers. Then the user must open a new SSH session — the RemoteForward tunnel only exists in sessions started after the config change. Verify from inside that new session:

clipaste doctor --json   # role should be "ssh-remote", status "ok"

Wire up WSL2

Run this inside the WSL2 distro, with clipaste.exe already running on Windows:

clipaste wsl-setup                  # probes for the Windows host address
clipaste wsl-setup --host 127.0.0.1 # skip probing, use this address

Both networkingMode=mirrored and the default NAT mode are handled. If setup reports that nothing answered, read its output — it lists every address it tried and why, and states plainly that NAT-mode WSL cannot reach a loopback-bound daemon.

Tell the user the right paste gesture

This differs per tool and per location, and telling a user the wrong one wastes their time:

WhereClaude Code / Cursor CLICodex CLI
Local terminal (macOS / Windows)Cmd+V (macOS) / Ctrl+VCmd+V (macOS) / Ctrl+V
SSH into LinuxCtrl+Vclipaste-paste, then paste the printed path
SSH into macOSclipaste-pasteclipaste-paste
WSL2Ctrl+Vclipaste-paste, then paste the printed path

Codex CLI reads the clipboard in-process (via arboard) and never shells out to xclip, so it cannot use the shim. clipaste-paste writes the image to a real file on the current host and prints the path — hand that path to the tool.

The local shortcut row does not apply to Linux hosts. Linux serves clipboard PNG images to remote consumers without inserting a local text path. It also does not apply to a macOS/Windows daemon in server-only mode (below).

Never tell a user to press Cmd+V in an SSH session: that sends the local file path as text, which the remote agent cannot open.

Server-only mode

The macOS/Windows daemon adds a file path to the local clipboard after each screenshot. Offer CLIPASTE_SERVER_ONLY=1 when the user only pastes into agents over SSH or WSL2, or reports that GUI apps paste a path instead of the image (on Windows the rewrite drops the bitmap). The daemon then leaves the clipboard as copied and still serves images to remote consumers. Do not enable it for a user who pastes screenshots into local terminals: those rely on the path.

  • Windows: setx CLIPASTE_SERVER_ONLY 1, set $env:CLIPASTE_SERVER_ONLY = "1" in the same PowerShell, then stop and restart clipaste.exe from it. The Run entry and reinstalls keep the setting.
  • macOS: brew services cannot pass environment variables. Replace it with a LaunchAgent that sets EnvironmentVariables, following the README recipe, and restart that agent with launchctl kickstart -k, not brew services restart.
  • Linux never modifies the clipboard; the variable changes nothing there.

Verify with clipaste doctor --json: the daemon check detail contains server-only. If it does not, the running daemon did not receive the variable or predates the mode (v2.5.0 and earlier ignore it). Values other than 1 and 0 stop the daemon at startup. In this mode, no path on the local clipboard is expected; do not report it as a fault.

Things not to do

  • Do not install a Linux systemd service automatically or present it as a fix for missing desktop access. Follow the reported tool/session/data-control guidance. For a consumer, run ssh-setup on its clipboard host and reconnect; WSL2 still requires the Windows daemon and wsl-setup inside the distro.
  • Do not classify all Linux machines as hosts or as unsupported-host: actual SSH sessions and configured headless consumers retain ssh-remote diagnostics.
  • Do not bind the daemon to 0.0.0.0 or add firewall exceptions to "fix" connectivity. It listens on loopback deliberately; the image bytes on that port are the user's screen contents.
  • Do not write shims by hand. ssh-setup / wsl-setup generate them with the correct URL baked in; a hand-written one drifts silently.
  • Do not kill -9 the daemon to restart it. Use brew services restart clipaste (macOS), stop clipaste.exe normally (Windows), or Ctrl+C in its graphical terminal (Linux).
  • Do not report success without a passing clipaste doctor. "The install command exited 0" is not the same as "paste works". On Linux, also verify a real screenshot end to end, especially when XWayland fallback is reported.

Part 2 — Contributing to this repository

Layout

src/
├── main.rs        CLI entry + argument parsing (one parser per subcommand)
├── common.rs      version, port, temp-file handling, image conversion, http_get
├── server.rs      HTTP server on 127.0.0.1:18340 (/health, /clipboard/type, /clipboard/image)
├── doctor.rs      environment classification + checks + human/JSON rendering
├── ssh_setup.rs   shim templates, ssh-setup, wsl-setup, host detection
├── linux.rs       read-only PNG polling via system wl-paste / xclip (cfg linux)
├── macos.rs       NSPasteboard watcher (cfg macos)
└── windows.rs     clipboard-format listener (cfg windows)

Build and test

cargo build
cargo test          # must stay green; no network access required
cargo clippy --all-targets

The default cargo test suite runs without a daemon, without a network, and without touching the real $HOME. Keep that default isolated; anything that needs a home directory must take one via an env override, as remote_script_run_installs_into_empty_home does.

Opt-in Linux desktop integration tests use real clipboard tools in isolated Xvfb and headless Sway sessions, with temporary HOME/cache/runtime directories. They do not use the real user's clipboard. From the repository root on Linux, with Rust/Cargo, Clippy, and loopback port 18340 free:

sudo apt install xvfb xclip sway wl-clipboard dbus-x11 python3-pil curl
bash tests/linux/run.sh

The Sway tests require wl-clipboard >=2.2; upgrade older distro packages first. The runner executes unit tests, strict Clippy, and clipboard/HTTP smoke tests. Alternatively, the existing container recipe builds wl-clipboard 2.3.0; run it without mounting desktop sockets or the user's home:

docker build -f tests/linux/Dockerfile -t clipaste-linux-test .
docker run --rm clipaste-linux-test

Isolated Xvfb/Sway coverage does not establish compatibility with GNOME, ext-only compositors, or the reporter's native application.

Conventions this codebase holds to

  • No new dependencies without a strong reason. The point of clipaste is that it stays lightweight. Linux uses distro clipboard tools with 300 ms polling; do not apply macOS/Windows idle measurements to it. HTTP is curl; JSON output is hand-rolled in common::json_escape. If you need serde, justify it.
  • Pure functions for anything with logic. Parsing, ordering, config rewriting, and rendering are all separated from I/O so they can be tested directly — see wsl_host_candidates, build_ssh_config, render_json.
  • Generated shell must be syntax-checked in tests. Every shim and setup script is asserted against bash -n; a typo there would only ever fail on a user's remote host.
  • No silent fallbacks. When detection fails, list what was tried and why, and say what the user should do. A green tick that hides a broken tunnel is worse than a red one.
  • Comments explain why, not what. Assume the reader can read Rust.

Releasing

  1. Bump version in Cargo.toml and VERSION in src/common.rs — they must match; doctor compares the running daemon's reported version against the binary's and warns on skew.
  2. cargo test && cargo clippy --all-targets
  3. Run the Release workflow manually on the release commit to validate packaging without publishing. It builds macOS (aarch64 + x86_64), Windows x86_64, and static Linux musl (aarch64 + x86_64) artifacts. Linux release binaries run through the isolated Xvfb/Sway smoke tests on native architecture runners.
  4. After validation, tag vX.Y.Z and push. The same workflow builds and publishes the artifacts with SHA256SUMS. Never rewrite an existing release tag.
  5. Update the Homebrew formula in hqhq1025/homebrew-clipaste.

When fixing a reported issue

Reproduce the failure shape in a test before fixing it. The WSL mirrored-mode bug (#7) is the model: the fix is a handful of lines, but the tests encode every networking mode so the next change cannot silently break the others.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.