# Opencode Clipboard Image

> Save clipboard images to a timestamped file and return a ready-to-paste path for OpenCode (Linux-first, X11/Wayland aware). Use when this capability is needed.

- Skill: `tomevault-io/opencode-clipboard-image` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/opencode-clipboard-image`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/opencode-clipboard-image/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/opencode-clipboard-image

---


# OpenCode Clipboard Image

## Purpose

Automate the common flow where pasting an image into terminal chat does not work: extract image data from the clipboard, save it to a file, and provide a path the user can reference in OpenCode.

## When To Use

- User says image paste is not working in OpenCode/TUI.
- User asks to "paste a screenshot" into OpenCode from clipboard.
- User wants a one-step workflow to save a clipboard image and attach it by path.

## Expected Outcome

1. Clipboard image is saved to `~/Pictures/opencode/clip-YYYYMMDD-HHMMSS.<ext>`.
2. Agent returns the absolute file path.
3. Agent gives the exact message pattern to use in OpenCode (for example: `@/home/user/Pictures/opencode/clip-....png`).

## Required Workflow

1. Detect Linux session type (`X11` or `Wayland`) when relevant:

```bash
echo "${XDG_SESSION_TYPE:-unknown}"
```

2. Ensure clipboard utility exists:
- X11: prefer `xclip`.
- Wayland: prefer `wl-paste` (package `wl-clipboard`).

3. If missing, provide the installation command for the detected distro, then continue.

4. Save clipboard image into a stable directory:

```bash
mkdir -p "$HOME/Pictures/opencode"
```

5. Use the first available image MIME type, save with matching extension, and print final path.

## Commands

### Linux X11 (`xclip`)

```bash
mkdir -p "$HOME/Pictures/opencode"
mime="$(xclip -selection clipboard -t TARGETS -o | tr ' ' '\n' | grep '^image/' | head -n1)"
if [ -z "$mime" ]; then
  echo "Clipboard does not currently contain an image. Copy an image first, then retry." >&2
  exit 1
fi
case "$mime" in
  image/png) ext="png" ;;
  image/jpeg) ext="jpg" ;;
  image/webp) ext="webp" ;;
  image/gif) ext="gif" ;;
  *) mime="image/png"; ext="png" ;;
esac
f="$HOME/Pictures/opencode/clip-$(date +%Y%m%d-%H%M%S).$ext"
xclip -selection clipboard -t "$mime" -o > "$f" && printf '%s\n' "$f"
```

### Linux Wayland (`wl-paste`)

```bash
mkdir -p "$HOME/Pictures/opencode"
mime="$(wl-paste --list-types | grep '^image/' | head -n1)"
if [ -z "$mime" ]; then
  echo "Clipboard does not currently contain an image. Copy an image first, then retry." >&2
  exit 1
fi
case "$mime" in
  image/png) ext="png" ;;
  image/jpeg) ext="jpg" ;;
  image/webp) ext="webp" ;;
  image/gif) ext="gif" ;;
  *) mime="image/png"; ext="png" ;;
esac
f="$HOME/Pictures/opencode/clip-$(date +%Y%m%d-%H%M%S).$ext"
wl-paste --type "$mime" > "$f" && printf '%s\n' "$f"
```

## Install Hints

- Debian/Ubuntu (X11): `sudo apt update && sudo apt install -y xclip`
- Debian/Ubuntu (Wayland): `sudo apt update && sudo apt install -y wl-clipboard`
- Arch: `sudo pacman -S xclip` or `sudo pacman -S wl-clipboard`
- Fedora: `sudo dnf install -y xclip` or `sudo dnf install -y wl-clipboard`

## Response Template

After saving successfully, respond with:

- Saved: `<absolute_path>`
- Use in OpenCode: `@<absolute_path>`

If the clipboard has no image MIME type, respond with:

- "Clipboard does not currently contain an image. Copy an image first, then retry."

## Safety

- Do not delete or overwrite existing files.
- Use timestamped filenames only.
- Never assume root/sudo access; provide install command if dependency is missing.

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/ye99) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-15 -->

