Skip to content

feat(cua-driver-rs): wire up --claude-code-computer-use-compat + make it default for claude - #1678

Merged
f-trycua merged 1 commit into
mainfrom
claude-code-computer-use-compat
May 24, 2026
Merged

feat(cua-driver-rs): wire up --claude-code-computer-use-compat + make it default for claude#1678
f-trycua merged 1 commit into
mainfrom
claude-code-computer-use-compat

Conversation

@f-trycua

@f-trycua f-trycua commented May 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

The `--claude-code-computer-use-compat` flag was documented in Skills/SKILL.md as the recommended Claude Code install but was a silent no-op on the Rust binary — the only artifact was an orphan `platform-macos/src/tools/screenshot_compat.rs` not even in `mod.rs`.

This PR finishes the port and makes it the default output of `mcp-config --client claude` (and `--client claude-code`).

What the flag does

When `cua-driver mcp --claude-code-computer-use-compat` is on argv, the registry swaps the regular `screenshot` tool for a compat variant — same tool name, different schema + behaviour:

Regular Compat
`pid` optional required
`window_id` optional (falls back to whole display) required
Format `png` or `jpeg`, configurable always JPEG @ 85%
Window validation none window must belong to pid + be visible
Trailing text `"✅ Window screenshot — WxH ..."` window-coordinate-space note pointing at pixel tools

Mirrors `ClaudeCodeComputerUseCompatTools.swift` in the Swift port.

What the default output now says

```
$ cua-driver mcp-config --client claude
claude mcp add --transport stdio cua-computer-use -- mcp --claude-code-computer-use-compat
```

  • Server name `cua-computer-use` because Claude Code reserves the literal `computer-use` key for its built-in tool family.
  • `--client claude-code` accepted as an alias for `--client claude`.

Implementation

  1. macOS: wired `screenshot_compat.rs` into `tools/mod.rs`. Added `register_tools_with_compat(compat)` for the MCP path; existing `register_tools()` calls `with_compat(false)` for ListTools / Describe / Call.

  2. Windows + Linux: added `ScreenshotCompatTool` next to `ScreenshotTool` in each platform's `tools/impl_.rs` (~80 lines each, same shape as the macOS variant).

  3. `build_registry(compat: bool)` on each platform conditionally registers ScreenshotTool or ScreenshotCompatTool.

  4. CLI plumbing: `--claude-code-computer-use-compat` parsed top-level in `cli.rs`, added to `Command::Mcp { claude_code_compat }`. Both Mcp arms in `main.rs` store it into a process-global `static CLAUDE_CODE_COMPAT: AtomicBool` which `build_registry` / `build_registry_no_cursor` read when picking the screenshot variant.

  5. `mcp-config --client claude` / `--client claude-code` outputs the compat install command by default.

Verified on Windows

  • Build clean (`cargo build --release -p cua-driver` — 0 warnings).
  • `cargo test --test-threads=1` — 49+28+32 all pass (pre-existing telemetry-parallel flake unrelated to this PR).
  • `cua-driver mcp-config --client claude` prints the compat command.
  • `cua-driver mcp --claude-code-computer-use-compat` initialize → `tools/list` returns compat screenshot with `required: ["pid", "window_id"]` and the window-scoped description.
  • `cua-driver mcp` (no flag) returns regular screenshot with `required: []`.

Test plan

  • Windows build/test green
  • MCP `initialize` + `tools/list` smoke-tested in both modes
  • Reviewer: re-trigger `cd-rust-cua-driver.yml` to confirm macOS + Linux compile
  • Reviewer: end-to-end test in Claude Code: `claude mcp add ...` with the new default command, verify the daemon serves the compat tool set
  • Reviewer: verify the compat `screenshot` on macOS produces window-scoped images Claude Code can consume in vision flows

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added --claude-code-computer-use-compat flag to enable Claude Code computer-use compatibility mode.
    • MCP server configuration now supports Claude Code-compatible operations across all platforms with optimized tool implementations.

Review Change Stack

… it default for claude

The flag was previously documented in Skills/SKILL.md as the recommended
Claude Code install command but was a silent no-op on the Rust binary —
the only artifact was an orphan platform-macos/src/tools/screenshot_compat.rs
not even in mod.rs.

This PR finishes the port:

1. **macOS**: wire screenshot_compat.rs into tools/mod.rs. Add
   `register_tools_with_compat(compat)` for the MCP path; existing
   `register_tools()` calls `with_compat(false)` for ListTools/etc.

2. **Windows + Linux**: add `ScreenshotCompatTool` next to the regular
   `ScreenshotTool` in each platform's `tools/impl_.rs`. Same shape as
   the macOS variant — `pid` + `window_id` BOTH required, validates
   window belongs to pid, JPEG @ 85%, returns a text note pointing the
   caller at pixel-addressed tools so the LLM uses the window's
   coordinate space.

3. **`build_registry(compat: bool)`** on each platform conditionally
   registers ScreenshotTool or ScreenshotCompatTool — same MCP tool
   name "screenshot", so callers see one or the other depending on
   how the daemon was started.

4. **CLI plumbing**: `--claude-code-computer-use-compat` parsed in
   `cli.rs`, added to `Command::Mcp { claude_code_compat }`. Both Mcp
   arms in main.rs store it into a `static CLAUDE_CODE_COMPAT:
   AtomicBool` which `build_registry` / `build_registry_no_cursor`
   read when picking the screenshot variant. Static keeps the
   dependency arrow pointed away from platform crates.

5. **`mcp-config --client claude` and `--client claude-code`** now
   default to the compat command:
       claude mcp add --transport stdio cua-computer-use \
           -- <binary> mcp --claude-code-computer-use-compat
   The server name is `cua-computer-use` (Claude Code reserves the
   literal "computer-use" key for its built-in tool family) and the
   binary self-registers the compat tool set on launch.

## Verified on Windows

- Build clean, 0 warnings.
- `cargo test --test-threads=1 -p cua-driver -p mcp-server -p platform-windows`: 49+28+32 all pass.
- `cua-driver mcp-config --client claude` prints the compat command.
- `cua-driver mcp --claude-code-computer-use-compat` initialize:
  `tools/list` returns the compat screenshot with pid + window_id
  required and the window-scoped description.
- `cua-driver mcp` (no flag) returns the regular screenshot with no
  required fields.

macOS + Linux not compile-checked locally; CI will catch issues there.
@vercel

vercel Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored May 24, 2026 12:40pm

Request Review

@coderabbitai

coderabbitai Bot commented May 24, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR introduces a --claude-code-computer-use-compat CLI flag that enables Claude Code computer-use compatibility mode. The flag is parsed during MCP command setup, persisted in a global atomic state, and threaded through each platform's tool registry to conditionally register alternate window-scoped screenshot tool implementations instead of the default full-screen variants.

Changes

Claude Code Computer-Use Compatibility Mode

Layer / File(s) Summary
CLI flag parsing and MCP config generation
libs/cua-driver/rust/crates/cua-driver/src/cli.rs
New --claude-code-computer-use-compat boolean flag added to Command::Mcp variant and parsed during argument processing. run_mcp_config() updated to emit the flag when adding the cua-computer-use server for both claude and claude-code clients.
Global compat flag and MCP dispatcher wiring
libs/cua-driver/rust/crates/cua-driver/src/main.rs
Global CLAUDE_CODE_COMPAT atomic flag introduced. Both macOS and non-macOS MCP command handlers store the parsed flag. Non-macOS registry builders (build_registry and build_registry_no_cursor) read the flag and pass compat through all platform registration calls. macOS handler reads and passes to register_tools_with_compat().
macOS platform compat tool registration
libs/cua-driver/rust/crates/platform-macos/src/lib.rs, libs/cua-driver/rust/crates/platform-macos/src/tools/mod.rs
New register_tools_with_compat(compat: bool) entry point and updated register_tools_with_cursor() signature. Tools module now declares screenshot_compat submodule and register_all() conditionally registers ClaudeCodeCompatScreenshotTool when compat=true, otherwise ScreenshotTool.
Linux platform compat tool implementation and registry
libs/cua-driver/rust/crates/platform-linux/src/lib.rs, libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs, libs/cua-driver/rust/crates/platform-linux/src/tools/mod.rs
New ScreenshotCompatTool struct validates pid and window_id, captures window screenshot, resizes to max_image_dimension, converts to JPEG (quality 85), and returns image plus structured metadata. Registry build_registry(compat: bool) conditionally registers compat or normal tool variant.
Windows platform compat tool implementation and registry
libs/cua-driver/rust/crates/platform-windows/src/lib.rs, libs/cua-driver/rust/crates/platform-windows/src/tools/impl_.rs, libs/cua-driver/rust/crates/platform-windows/src/tools/mod.rs
New ScreenshotCompatTool validates (pid, window_id) visible window, captures as JPEG (quality 85), and returns image plus instructional text. Registry build_registry(compat: bool) conditionally registers compat or normal tool variant.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • trycua/cua#1424: Both PRs implement the same Claude Code computer-use compatibility mode by wiring the --claude-code-computer-use-compat flag to register/use the cua-computer-use server and swapping the screenshot tool behavior to the window-scoped compat shim.
  • trycua/cua#1663: Both PRs touch the same screenshot tool implementations/registry wiring: the main PR adds a new compat-mode ScreenshotCompatTool and selects it via build_registry(compat), while the retrieved PR changes ScreenshotTool defaults (JPEG@85 and max_image_dimension=1568) that are still used when compat=false.

Poem

🐰 Whiskers twitching with delight,
A compat flag brings focus tight,
Window screenshots, crisp and clean,
For Claude Code's keen machine sight,
On three platforms, tools take flight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: implementing the --claude-code-computer-use-compat flag and making it default for Claude clients.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude-code-computer-use-compat

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@f-trycua
f-trycua merged commit ec07873 into main May 24, 2026
5 of 7 checks passed
@f-trycua
f-trycua deleted the claude-code-computer-use-compat branch May 24, 2026 12:44
f-trycua added a commit that referenced this pull request May 24, 2026
…de compat MCP entry (#1679)

The Claude Code section in `post-install-hints.txt` listed both the
plain `cua-driver` MCP server and the `--claude-code-computer-use-compat`
variant. Since #1678 made compat mode the default for Claude Code, the
plain entry is redundant — keep only the compat-mode line and reword
the description to stand on its own.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
f-trycua added a commit that referenced this pull request May 24, 2026
…bypass PowerShell arg mangling (#1680)

Follow-up to #1678. The `claude mcp add NAME -- BIN mcp --extra-flag`
form works in bash + cmd but PowerShell's native-command arg parser
mangles `--<long-flag>` tokens passed after a bare `--`, producing:

    error: unknown option '--claude-code-computer-use-compat'

even though commander.js (claude CLI's parser) handles `--` correctly.
Verified by running the exact same command in Git Bash on the same
Windows host and seeing the MCP server register cleanly.

Switch the output to `claude mcp add-json`, which takes the whole
server config as a single JSON string. No shell + no parser ambiguity
on either dash. Smoke-tested end-to-end via `eval` of the generated
output — registers + lists + removes cleanly.

Binary path is normalised to forward slashes (Windows accepts them
and forward-slash-in-JSON is fewer escape headaches across bash + PS).
The single-quoted JSON literal works in PowerShell + bash + cmd-with-
EnableDelayedExpansion. cmd users with naive double-quoted shells can
paste the raw JSON into `~/.claude.json` instead — `mcp-config` with
no `--client` flag still emits that format.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant