# How to Export Reviews to Clipboard or stdout as Markdown in tuicr

> Easily export tuicr reviews to clipboard or stdout as Markdown using :clip or :export commands. Stream formatted reviews directly to your terminal.

- Repository: [Almog Gavra/tuicr](https://github.com/agavra/tuicr)
- Tags: how-to-guide
- Published: 2026-08-07

---

**To export reviews as Markdown in tuicr, use the `:clip` command to copy to your system clipboard or the `:export` command with the `--output-to-stdout` flag to stream the formatted review directly to your terminal.**

The `agavra/tuicr` repository provides a dual-path export system that converts PR review sessions into portable Markdown. Whether you need to paste structured feedback into GitHub, Slack, or a local file, the export pipeline in [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs) handles formatting, clipboard integration, and stdout redirection.

## Understanding the Markdown Generation Pipeline

The core export logic resides in [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs). The `generate_export_content()` function aggregates session notes, comment types, file- and line-level comments, PR metadata, and optional remote threads into a single formatted string.

```rust
// src/output/markdown.rs
pub fn generate_export_content(
    session: &ReviewSession,
    diff_source: &DiffSource,
    comment_types: &[CommentTypeDefinition],
    config: &ExportConfig,
    remote_threads: &Option<Vec<RemoteThread>>,
    session_slug: String,
) -> Result<String, Box<dyn Error>> {
    // Assembles headers, metadata, and comment blocks
}

```

This function returns a complete Markdown document that respects your configured headers, legends, and formatting preferences defined in the `ExportConfig` struct from [`src/config/mod.rs`](https://github.com/agavra/tuicr/blob/main/src/config/mod.rs).

## Copying Reviews to the Clipboard

The `export_to_clipboard()` function bridges the Markdown generator with your system clipboard. Located in [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs), it first calls `generate_export_content()`, then passes the resulting string to `copy_text_to_clipboard()`.

```rust
// src/output/markdown.rs
pub fn export_to_clipboard(
    session: &ReviewSession,
    diff_source: &DiffSource,
    comment_types: &[CommentTypeDefinition],
    config: &ExportConfig,
    remote_threads: &Option<Vec<RemoteThread>>,
    session_slug: String,
) -> Result<String, Box<dyn Error>> {
    let content = generate_export_content(
        session, diff_source, comment_types, config, remote_threads, session_slug
    )?;
    copy_text_to_clipboard(&content)?;
    Ok("Review copied to clipboard".to_string())
}

```

### Cross-Platform Clipboard Support

The `copy_text_to_clipboard()` function automatically selects the appropriate backend for your environment:

- **macOS**: Uses `pbcopy` for direct pasteboard access
- **Wayland**: Invokes `wl-copy` for native clipboard integration
- **X11**: Falls back to `xclip` for traditional Linux desktops
- **tmux/SSH**: Emits OSC 52 escape sequences to transfer text through terminal multiplexers
- **Universal fallback**: Leverages the `arboard` crate when native tools are unavailable

When you invoke the `:clip` command in the TUI, the handler in [`src/handler.rs`](https://github.com/agavra/tuicr/blob/main/src/handler.rs) routes the request to `export_to_clipboard()` and displays a status confirmation upon success.

## Exporting to stdout for Piping

For automation and scripting workflows, tuicr supports streaming Markdown directly to standard output. When the `--output-to-stdout` flag is set (or the `:export` command is invoked in TUI mode), the handler bypasses the clipboard utilities and writes `generate_export_content()`'s output directly to stdout before exiting.

```bash

# Export review to stdout and redirect to a file

tuicr --output-to-stdout --session my-review > review-notes.md

# Pipe review directly to another tool

tuicr --output-to-stdout | gh pr comment --body-file -

```

This approach is particularly useful in CI/CD pipelines or when composing reviews in external editors.

## Customizing the Exported Markdown

The `ExportConfig` struct in [`src/config/mod.rs`](https://github.com/agavra/tuicr/blob/main/src/config/mod.rs) controls the structure and verbosity of your exported reviews. You can modify these settings in your [`config.toml`](https://github.com/agavra/tuicr/blob/main/config.toml):

```toml
[export]
intro = "Code review comments:"
legend = false               # Omit the "Comment types:" legend line

scope_line = true            # Include "Reviewing [branch]" banner

pr_metadata = true           # Show PR title and author

comments_header = "## Comments"

remote_comments_header = "## Upstream Threads"

```

These options affect both clipboard and stdout exports, ensuring consistent formatting across all output methods.

## Summary

- **`generate_export_content()`** in [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs) assembles session data into formatted Markdown
- **`export_to_clipboard()`** copies reviews using native tools (`pbcopy`, `wl-copy`, `xclip`), OSC 52 sequences, or the `arboard` crate
- **`--output-to-stdout`** streams Markdown directly to your terminal for piping and automation
- **`ExportConfig`** provides granular control over headers, legends, and metadata inclusion
- The handler in [`src/handler.rs`](https://github.com/agavra/tuicr/blob/main/src/handler.rs) binds `:clip` and `:export` commands to these export functions

## Frequently Asked Questions

### What clipboard methods does tuicr support?

tuicr supports platform-native tools including `pbcopy` for macOS, `wl-copy` for Wayland, and `xclip` for X11. When running in tmux or over SSH, it automatically falls back to OSC 52 escape sequences. If none of these are available, it uses the `arboard` Rust crate as a final fallback.

### How do I export reviews when running tuicr over SSH?

When connected via SSH or running inside tmux, tuicr automatically detects the environment and uses OSC 52 escape sequences to transfer clipboard data through your terminal emulator. Ensure your terminal supports OSC 52, or use the `--output-to-stdout` flag to print the Markdown and manually copy it.

### Can I customize which sections appear in the exported Markdown?

Yes. Modify the `[export]` table in your [`config.toml`](https://github.com/agavra/tuicr/blob/main/config.toml) to toggle the legend, PR metadata, scope lines, and custom headers. These settings in [`src/config/mod.rs`](https://github.com/agavra/tuicr/blob/main/src/config/mod.rs) affect both clipboard and stdout output formats.

### What's the difference between the `:clip` and `:export` commands?

The `:clip` command copies the formatted review to your system clipboard and keeps the TUI running, displaying a confirmation message. The `:export` command (or `--output-to-stdout` CLI flag) writes the Markdown to stdout and immediately exits the application, making it ideal for scripting and file redirection.