跪拜 Guibai
← Back to the summary

A Desktop Pet That Reacts to Your AI Coding Agent

AI Desktop Pet Creation: From a Static Image to a Dynamic Desktop Pet

It started simply: a friend showed me his Codex desktop pet—a little creature crouched in the corner of the screen, resting its chin on its hand when Codex was thinking, working when it ran tools, and giving a V-sign when the task was done. My immediate reaction was: "I want one too."

Why I Dared to Start

First, my background: I have some AI programming basics, but I'm definitely not a guru. Being able to make this desktop pet didn't rely on any profound skills, but rather on "breaking down steps + letting AI do the heavy lifting."

If you've also been tempted but felt you couldn't do it, this article is for you—because it really isn't that hard. I broke the whole process into four steps, each independently verifiable:

  1. Find an image → Use AI to generate a dynamic video
  2. Extract frames from the video → Turn them into a transparent-background "sprite sheet"
  3. Use a desktop framework to "wrap" the sprite sheet → The desktop pet is born
  4. Connect to Cursor / Claude Code "events" → It changes as you work

Let's go through them step by step.

Step 1: Make a Static Image "Move"

The core of a desktop pet is that "it must have actions." I don't have the ability to draw frame-by-frame by hand, so I took a shortcut: AI video generation.

I took my friend's image, threw it into an AI video generation tool, and had it generate action videos like the character "resting chin in thought," "raising hand in a V-sign," and "typing on a keyboard."

The tools I used were Doubao and Jimeng, chosen for their generous free quotas + natural movements + stable output.

There are a few real pitfalls in this step, let me clear them for you first:

Step 2: Frame Extraction + Background Removal, Turning It into a "Sprite Sheet"

This step turns the video into material that a program can play. Let me explain a few terms in plain language:

For this step, I wrote a small script (Python, OpenCV for frame extraction + Pillow for background removal). The process is: extract frames → remove white background frame by frame → keep only the largest "connected region" (to prevent watermarks and noise from mixing in) → uniformly crop to the same bounding box → scale → automatically find loop segments → stitch into a sprite sheet.

Tip: Quantize the color palette (e.g., compress to 256 colors). For this kind of flat-shaded cartoon style, it's almost lossless but can reduce file size by about 85%. A 14MB image sequence compressed down to just 1.6MB.

At this point, you already have a bunch of playable "material," just one "shell" away from a desktop pet.

Step 3: Add a "Shell" to Let It Crouch in the Desktop Corner

For the shell, I used Tauri 2 + Svelte 5. Let me explain both terms:

This shell needs to do several things: a transparent, borderless, always-on-top window that doesn't appear in the taskbar; draggable and remembers its position; a right-click menu to switch skins; a system tray to show/hide/exit.

Tauri basically has ready-made capabilities for all of these. After AI helped me set it up, the desktop pet "crouched" in the bottom-right corner of my screen for the first time. Running desktop pet

Step 4: Bring It "Alive"—Connecting Agent Events

A static desktop pet is boring. What truly makes it "mood-driven" is event-driven behavior.

The principle is this: Programming agents like Cursor / Claude Code / Codex all support something called hooks. You can think of them as "triggers"—at certain moments (starting to think, starting to execute a tool, task completion), the agent triggers this hook to call a command you specify.

My approach: Write a tiny bridge script and attach it to the hooks. Whenever the agent acts, the script POSTs a uniformly formatted message to the local 127.0.0.1:4271 port. The service inside the desktop pet receives it, forwards it to the frontend, and the frontend decides which animation to play and which speech bubble to display based on the state.

Thus, this linkage was born:

Here, I strictly adhered to one principle: The bridge script always exits quickly and never blocks the Agent. The desktop pet is just an observer; it must not jam up your work.

Current Status & Pitfalls I Encountered

Now the desktop pet is running stably, supporting Claude Code / Codex / Cursor. It can switch skins, scale, lock monitoring to a specific session, auto-start on boot, and auto-update.

A few pitfalls I stepped into:

  1. Other desktop pets can "steal" your hooks: I had previously installed another desktop pet on my machine, which would overwrite ~/.claude/settings.json and knock off my attached hooks. The symptom was "the desktop pet suddenly stopped receiving events."
  2. Transparent windows have shadow borders: On Windows, transparent windows need to have shadows turned off, otherwise there's a thin border around them, which looks ugly. Just one line of configuration.
  3. Don't be fooled by "no response": For a while, I thought the completion state wasn't displaying. After troubleshooting for ages, it turned out the "completion" animation only played for a fraction of a second before returning to idle, invisible to the naked eye. The state hold time needed to be extended.

Where I'm Stuck, Seeking Expert Advice

Writing up to here, the desktop pet is already a qualified "mood display." But my desired next step is: Let it go from "watching" to "talking"—converse with it via voice or text, and let it help me control the computer.

The ideal form is: I say "Help me open the browser to search for something or open a program," it understands, executes, and gives me feedback through the desktop pet's expressions and bubbles.

Where am I stuck? On "how to make the desktop pet a true execution entry point"—should I embed a dialogue/voice loop directly inside the desktop pet, or reuse an existing Agent (letting it call Claude Code / Codex capabilities)? Which voice solution to use (local ASR or cloud interface)? How to handle the permission boundaries and security of desktop control?

On this front, I'm currently in a state of "having some ideas but unsure about the technical route." If you've worked on a similar "desktop pet + voice assistant / desktop control" project, or have recommended solutions, please point the way in the comments. I'd be immensely grateful.

Finally

My biggest takeaway from the whole process is: "Looks hard" and "is actually hard" are two different things. Once broken down, every step has ready-made tools and AI to carry the load for you. You just need to be the person who "strings the steps together."

Have you ever been tempted to make a desktop pet? Or made some small project that "others find useless, but you had a blast making"? Come chat in the comments—maybe your story will be our next article.

Comments

Top 2 of 5 from juejin.cn, machine-translated. The original thread is authoritative.

Halifax

What's the prompt? I'm using Codex and it just spins left and right.

树下有只猫  · 1 likes

chibi girl, long dark brown wavy hair, big round glasses, cute round face, big brown eyes, wearing light green oversized sweater with a small pocket patch, white shorts, simple flat 2d cartoon style, thick outlines, solid colors, white background,chibi girl, long dark brown wavy hair, big round glasses, cute round face, big brown eyes, wearing light green oversized sweater with a small pocket patch, white shorts, simple flat 2d cartoon style, thick outlines, solid colors, white background,thinking state, one hand raised touching chin, head tilted slightly to the side, eyes looking upward, thoughtful expression, a glowing yellow lightbulb icon or question mark floating above head, cartoon logic. That's one of the prompts. I generated it with DeepSeek. The first half is shared across all actions, and the part after that is the action-specific prompt you need. I sent it to Doubao or Jimeng — both have free credits you can use.

Halifax  → 树下有只猫

[Fist salute]

绵绵土豆冰

I gave the image to Codex and had it generate a Luo Xiaohei for me, but one Codex update broke compatibility. I had the AI tweak it for ages and still couldn't get drag-and-drop working. Swore off the whole thing...

树下有只猫

Could it be a mouse click-through issue or the desktop pet's hit zone being off? I ran into both of those problems when I was building mine before.