# How to Export Code Reviews from Tuicr: CLI and TUI Methods Explained

> Easily export code reviews from Tuicr using CLI and TUI methods. Learn how to save your reviews to markdown format with simple commands.

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

---

**Tuicr exports code reviews to markdown format either by copying to the system clipboard via the `:clip` command in the TUI or by writing to standard output using the `--output stdout` flag in the CLI.**

The Tuicr codebase (agavra/tuicr) provides a flexible export pipeline that converts review sessions into clean, numbered markdown documentation. Whether you need to archive review feedback, share it outside the terminal, or integrate it into documentation workflows, the export functionality in [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs) handles the transformation.

## The Export Architecture

The core export logic lives in [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs). This module provides two primary functions: `generate_export_content` builds the markdown string from a `ReviewSession` struct, while `export_to_clipboard` orchestrates the delivery mechanism. When you initiate an export, Tuicr first renders the review data into markdown format, then determines the most reliable method to place that text on your system clipboard or return it as a string.

## Exporting from the TUI Using the `:clip` Command

### Command Registration and Dispatch

In [`src/handler.rs`](https://github.com/agavra/tuicr/blob/main/src/handler.rs), the command registry maps the text command `clip` (and its alias `export`) to `CommandKind::Export` around lines 30-31. When you type `:clip` in Tuicr's command mode, the handler invokes the export pipeline at lines 380-390, calling `export_to_clipboard` with the current session state.

```bash

# Inside the Tuicr TUI, enter command mode and type:

:clip

# Status line displays: "Review copied to clipboard (via terminal)"

```

### Clipboard Handling Mechanisms

The `copy_text_to_clipboard` function (lines 81-99 in [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs)) implements a fallback chain for maximum compatibility:

1. **Native system clipboard** via platform-specific APIs
2. **OSC 52 escape sequence** for terminal emulators that support it
3. **External helper programs** such as `xclip` (X11), `wl-copy` (Wayland), or `pbcopy` (macOS)

This ensures the export works whether you are running locally or over SSH, and regardless of your display server.

## Exporting from the CLI with `--output stdout`

For non-interactive workflows, bypass the TUI entirely by using the `--output stdout` flag. This invokes the same `generate_export_content` function but writes the markdown directly to standard output instead of the clipboard.

```bash

# Export a saved review session to stdout

tuicr review add --input myreview.json --output stdout

# Alternative using the dedicated export command

tuicr export --output stdout

```

This method is ideal for piping review data into other tools, saving to files via shell redirection, or integrating into CI/CD pipelines.

## Customizing Export Behavior via [`config.toml`](https://github.com/agavra/tuicr/blob/main/config.toml)

Export appearance is controlled through the `[export]` table in your [`config.toml`](https://github.com/agavra/tuicr/blob/main/config.toml). The `ExportConfig` struct, referenced throughout [`markdown.rs`](https://github.com/agavra/tuicr/blob/main/markdown.rs), exposes several boolean options:

- **`intro`**: Include a header section explaining the review context
- **`legend`**: Append a legend defining comment type abbreviations
- **`scope_line`**: Show the git scope (branch/commit) being reviewed
- **`pr_metadata`**: Include pull request metadata when available

Configure these options to generate markdown that matches your team's documentation standards.

## Programmatic Export in Rust

You can leverage Tuicr's export functions directly in Rust applications. The `generate_export_content` function (lines 28-43) accepts a `ReviewSession`, `DiffSource`, and `ExportConfig` to produce a markdown string.

```rust
use tuicr::output::generate_export_content;
use tuicr::{app::DiffSource, config::ExportConfig, model::ReviewSession};

// Generate markdown from a session programmatically
let md = generate_export_content(
    &session,                     // ReviewSession you built or loaded
    &DiffSource::WorkingTree,     // Scope of the review
    &comment_type_defs,           // Vec<CommentTypeDefinition>
    &ExportConfig::default(),     // Export settings (can be tweaked)
    &remote_threads,              // Remote PR threads, if any
    Some("myrepo@main/worktree"), // Optional session slug header
)?;
println!("{}", md);

```

To copy directly to the clipboard from code, use `export_to_clipboard` (lines 54-71):

```rust
use tuicr::output::export_to_clipboard;

let msg = export_to_clipboard(
    &session,
    &diff_source,
    &comment_type_defs,
    &ExportConfig::default(),
    &remote_threads,
    None,
)?;
println!("{}", msg); // "Review copied to clipboard ..."

```

## Summary

- **TUI Export**: Type `:clip` (or `:export`) in command mode to copy the current review session to your clipboard using the logic in [`src/handler.rs`](https://github.com/agavra/tuicr/blob/main/src/handler.rs) and [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs).
- **CLI Export**: Append `--output stdout` to `tuicr review` or `tuicr export` commands to print markdown to standard output.
- **Clipboard Flexibility**: Tuicr automatically selects between OSC 52, native APIs, or external utilities like `xclip` and `pbcopy`.
- **Customization**: Modify the `[export]` section in [`config.toml`](https://github.com/agavra/tuicr/blob/main/config.toml) to control markdown content including legends, intros, and metadata.
- **Programmatic Access**: Use `generate_export_content` and `export_to_clipboard` from [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs) in your own Rust tools.

## Frequently Asked Questions

### Can I export Tuicr reviews directly to a file instead of the clipboard?

Tuicr does not currently offer a direct `--output file` flag. Instead, use the CLI method with shell redirection: `tuicr review add --input myreview.json --output stdout > review.md`. This captures the markdown output directly to a file while using the same export pipeline as the clipboard method.

### What clipboard methods does Tuicr support?

According to the source code in [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs), Tuicr implements a three-tier fallback system: native system clipboard APIs when available, the OSC 52 terminal escape sequence for remote sessions, and external helper binaries including `xclip` for X11, `wl-copy` for Wayland, and `pbcopy` for macOS.

### How do I customize the markdown format when exporting?

Export formatting is controlled by the `ExportConfig` struct defined in the configuration module. In your [`config.toml`](https://github.com/agavra/tuicr/blob/main/config.toml), set options under the `[export]` table such as `intro = false` to omit headers or `legend = true` to include comment type definitions. These settings are consumed by `generate_export_content` in [`src/output/markdown.rs`](https://github.com/agavra/tuicr/blob/main/src/output/markdown.rs).

### Is there a way to export a review without opening the TUI?

Yes. Use the non-interactive CLI mode with `tuicr export --output stdout` or `tuicr review add --input <file> --output stdout`. This bypasses the TUI entirely and uses the markdown generation logic directly, making it suitable for automation scripts and batch processing.