A few months ago, I found myself taking over maintenance of libuvc, a library that allows controlling USB Video Class (UVC) cameras from userspace, through libusb. This is a substantial task that I might not have considered pre-LLM, so I thought it’d be interesting to write up how I approached the challenge in this era, and the tradeoffs between human interventions and generated code.

My general approach has been to care deeply about the core logic of the library, and review every single line of production code. Tests and harnesses? Less so: I look at the overall design, then I’m often happy to treat them as a black box and mostly look at the error cases they generate. I think it’s a sensible tradeoff, especially compared with the status quo (no unit tests, no CI, no maintenance).

Step 1: Sort through open issues and PRs

The first thing I did was to go through open issues and PRs. The repo had seen almost no activity since ~2023, and issues were piling up, untriaged.

I went through issues one by one, adapting and merging what made sense in my fork. I used Claude mostly to help me categorize and keep track of the backlog, recording progress in a GitHub issue.

Around 14 PRs could be merged reasonably easily, with some relatively small Claude-assisted changes and rebases. This is mostly human work: I want to understand the production code.

Step 2: Add CI, unit tests, fuzzing, Android example

Along the way, I started modernizing the codebase, mainly to give me more confidence about the changes I’m making:

  • I replaced a disabled Travis CI with GitHub Actions.
  • Bounds checking is always tricky (#211 is a good example), and unit tests help a lot. I asked Claude to generate reference images for format conversion, and tests that call functions with edge-case inputs.
  • I also enabled ASan and UBSan in some runs, and added fuzzing of USB descriptor parsing and payload processing.

None of the above is particularly difficult for a human to do, but it requires a lot of copy-pasting, effort, trial and error (how do we set up GitHub Actions again? What about fuzzing? What are the ASan flags to enable? Will I ever understand CMake? How do I run this on a Mac?). Now, it’s mostly a one-shot prompt to Claude.

I also added an Android app example, as the permission flow on Android is a bit tricky and a user asked about it. This is a lot of boilerplate Claude-generated code; I mostly looked at the CMake build logic and how the device file descriptor is obtained from Android and passed to libuvc.

That was about 15 more merged PRs. Again, my philosophy here: review the harnesses lightly, review the production code carefully.

Step 3: Build a camera emulator

And now, perhaps the most interesting part: one I would not have considered spending time on a couple of years ago.

It’s difficult to maintain a project like libuvc without owning a bunch of USB cameras to regularly test the library on. But what if we could just build an emulator to imitate the behaviour of different UVC devices, spec-compliant or not? We’re never going to get fully accurate coverage of the device behaviour, but maybe we can get close enough?

Another advantage of the emulator is that it requires few, if any, changes to the library under test, unlike unit tests, where you’d often have to split functions to mock behaviour. A good thing for mature projects that mostly work fine, like libuvc, where extensive refactoring is more likely to introduce new issues.

My initial Claude prompt looked like this:1

Me · 2026-11-12 21:02

New project. I maintain libuvc, but I don’t have many devices to test with. Build an UVC emulator, in Rust. I’m not sure what a good interface will be (USBIP, ldpreload?), so make sure that part is generic and replaceable (we want more than some simple replay). I gave you the UVC specs in specs/, maybe implement something reasonably simple like my laptop webcam. In the future, we’ll want to implement many devices, add quirks like USB errors, etc, so try to keep things reasonably modular and flexible. Made sure to write good but succint design docs. Spin sugagents for simple tasks as Sonnet to try to keep token usage reasonable. I’m going to sleep soon so let me know if any urgent questions.

Claude · 2026-11-12 21:06

Proposes a Rust core with swappable transports (LD_PRELOAD shim, USB/IP server); no sudo, so can’t attach vhci-hcd.

Me · 2026-11-12 21:07

Is there something that still uses libusb, but passes raw packets, or something like that? So that we still have libusb running

Me · 2026-11-12 21:10

actually I like usbip most TBH, tell me what you need. But I don’t like to run vhci-hcd on my kernel, what if it crashes, can you run stuff in a VM?

Me · 2026-11-12 21:14

Actually. Sorry, changed my mind. Start with the libusb shim approach, but again, make sure it’s modular so we can go USB-IP later on.

Roughly an hour later, Claude had a prototype up and running:

Claude · 2026-11-12 22:21

I built the UVC emulator. Real libuvc streams from an emulated copy of your laptop webcam through the libusb shim, and through USB/IP against the real kernel inside a throwaway VM. All three test suites pass and clippy is clean.

Me · 2026-11-12 22:25

Then, can you add some sensible features from the UVC specs? (USB 3.0 I guess?) and look at libuvc issues for example of devices with weird behaviour – and ideally we’ll want to reach really high code coverage on libuvc testing.

Then I really went to sleep.

The next morning, I had 25,000 lines of (mostly) Rust code, and 93.2% libuvc line coverage. I called the project emuvc and pushed it to GitHub.

tests api_test, stream_test Path 1: libusb shim, all in one process (no root, fast) libuvc emuvc-libusb LD_PRELOAD, replaces libusb Path 2: USB/IP, all inside a throwaway QEMU VM (real kernel) libuvc libusb V4L2 capture uvcvideo (reference) vhci-hcd USB/IP client USB/IP emuvc-usbip server on 127.0.0.1 emuvc core built into both paths USB host engine device models real cameras synthetic (UVC 1.0–1.5) known-bad configs fault injection libuvc Other userspace Linux kernel emuvc
Overall architecture of the UVC emulator.

We have a bunch of additional libuvc tests that we run against two paths. In the first one, we replace libusb with an LD_PRELOAD shim: faster, but perhaps a bit less accurate (we do not exercise libusb at all). In the second one, we run a USB/IP server, and have a VM kernel connect to it as if it were a real USB device. One powerful aspect of the USB/IP path is that we can also bind the Linux kernel’s uvcvideo driver against our emulated device and compare behaviour (instead of just reading its source code).

I was not going to review 25,000 lines; this was way too much, and probably of little value. So I decided to treat the implementation details as a black box, and just asked Claude to try to increase code coverage, dig into the UVC spec, and go through any open or closed libuvc issues. I also had Claude build CI scripts that clearly summarize test cases exposing potential libuvc bugs, so we can triage them later. I then skimmed through and merged 62 generated emuvc PRs, leading to a total of 40,000 lines (96.6% libuvc line coverage, 87.7% condition coverage).

The hard part, still in progress, is to go through those potential bugs and identify what is worth fixing. A libuvc crash? A memory leak? Always worth it. Non-compliant device behaviour that libuvc rejects gracefully? Probably not worth it, unless an actual device out there behaves that way.

So far, the emulator has found 12 bugs leading to merged PRs, and I still need to make a judgement call on 23 more.

Conclusion

So, to summarize, my current approach to maintaining a hardware-related open-source project with AI:

  • I care about production code, I review changes carefully, and I make sure the changes actually fix a real problem.
  • I do not care as much about CI harnesses, boilerplate code, or unit tests. I look more at the overall design and architecture, review the code lightly, and spend most time on examining the production code changes they indirectly cause.
  • Emulators are cheap and easy nowadays, at least for UVC devices with a very well-written spec and lots of examples. emuvc would have been weeks or months of work to build. The emulator was built with a $20/month Claude Pro plan, over a couple of weeks, and I only ran out of credits in one week (partly because of other projects). So the total cost is on the order of $10, or less.

Some of the future work we can consider doing with this emulator:

  • For any future reported libuvc issue, I will ask for USB descriptors, detailed logs, and ideally usbmon output. We can feed that to Claude and add emulator support for more quirky devices.
  • We use the Linux kernel uvcvideo driver to compare behaviour, but we could even test uvcvideo itself, if we wanted to (not really my goal at this stage).
  • There is some USB/IP support for Windows, so we could potentially test Windows’ own UVC driver.
  • If we wanted to rewrite libuvc (say, in Rust ,-P), we now have a reasonably good emulator to test it against, and at least make sure we replicate existing library behaviour.
  • We could have the emulator drive a physical USB device gadget, and exercise an arbitrary UVC driver implementation on any USB host/OS combination we want:
Host under test Windows, macOS, Android, Linux… with its own UVC driver USB cable Small board with a USB device port (e.g. Raspberry Pi) USB gadget raw-gadget or FunctionFS emuvc same device models and quirks System under test Linux kernel emuvc Physical hardware
Possible future setup: the emulator drives a USB gadget on a physical board.

Finally, thanks to Ken Tossell for libuvc! It’s an old project by now, but it still has some meaningful use cases.

  1. The full initial session log is here, for the curious. ↩