WebAssemblyとGifsicleを使用したGIF最適化ツール
Simon Willison氏がClaude Codeを用いてGifsicleをWebAssemblyにコンパイルし、ブラウザ上でアニメーションGIFの最適化とプレビューが可能なWebツールを構築するプロセスを紹介している。
キーポイント
GifsicleのWeb化とWASM活用
C言語で書かれたコマンドラインツールGifsicleをWebAssemblyにコンパイルし、ブラウザ上で動作するインタラクティブな最適化ツールを実現した。
Claude Codeによるエージェント開発
iPhone上のClaudeアプリからプロンプトを送信し、リポジトリ内の既存コードを参照しながらHTMLとJSを含む単一ファイルのWebアプリを自動生成させた。
ユーザー体験の向上と実用性
ドラッグ&ドロップでのファイル読み込み、複数設定の並列プレビュー、サイズ表示、そして個別設定のカスタマイズ(Tweak settings)機能を提供し、視覚的な比較とダウンロードを可能にした。
WASMコンパイルとコードエージェントの強み
GifsicleをWebAssembly(WASM)にコンパイルする複雑な作業は、Emscriptenツールチェーンの試行錯誤が必要だが、コードエージェントはコンパイルエラーを素早く解決できるため、人間よりも効率的に処理可能。
ユーザーインターフェースの設計と自動テスト
ドラッグ&ドロップやURL入力などのUI要件をプロンプトで指定し、作者が開発したブラウザ自動化ツール「Rodney」を用いてエージェントが実装中にバグを自己修正できる環境を整えた。
ビルドスクリプトの保存とライセンス表記
WASMバンドルだけでなく、gifsicleのソースコードをクローンしてパッチを適用するビルドスクリプトもリポジトリに保存し、オープンソースプロジェクトへのクレジット表示とGPLライセンスの明記を徹底した。
影響分析・編集コメントを表示
影響分析
この事例は、AIエージェントが単なるコード補完を超え、既存のオープンソースライブラリをWeb環境へ移植し、ユーザーインターフェースまで含めた完全なツールへと変換する「Agentic Engineering」の典型的な応用例を示している。技術的にはWASMの普及とLLMによるコード生成能力の向上が相まって、開発者の生産性を大幅に高める可能性を秘めている。
編集コメント
Simon Willison氏による実践的なデモンストレーションは、AIエージェントが既存の強力なCLIツールをWebネイティブなUIに変換する際の有効性を示しており、開発現場でのAI活用事例として参考になる。
*Agentic Engineering Patterns >*
私はオンラインの執筆にアニメーション GIF デモを含めることがよくありますが、それらは往々にして LICEcap を使用して録画されています。Interactive explanations の章にも例があります。
これらの GIF は非常にファイルサイズが大きくなることがあります。GIF ファイルサイズの最適化を試すためにいくつかのツールを使ってきましたが、私が最も気に入っているのは Eddie Kohler 氏による Gifsicle です。これは、フレーム間で変更されていない領域を特定し、差分のみを保存することで GIF を圧縮します。また、オプションとして GIF のカラーパレットを削減したり、より大きなサイズ削減のために可視的な非可逆圧縮(lossy compression)を適用することも可能です。
Gifsicle は C で書かれており、デフォルトのインターフェースはコマンドラインツールです。ブラウザからアクセスして、異なる設定を視覚的にプレビューおよび比較できるようにしたいと考え、ウェブインターフェースを作成しました。
私は iPhone の Claude アプリを使用して、simonw/tools リポジトリに対して Claude Code for web に以下のプロンプトを送信しました:
gif-optimizer.html
Gifsicle を WASM(WebAssembly)にコンパイルし、アニメーション GIF を開くかドラッグ&ドロップできるウェブページを構築します。その後、gifsicle を使用して異なる設定で圧縮された GIF を表示し、各プレビューにはファイルサイズとダウンロードボタンを表示します。
必ず JSON 形式で返してください。translation フィールドのみ。他のフィールド (technical_terms 等) は一切追加しないこと — 余計なフィールドを書こうとして本文翻訳がトークン上限で打ち切られる事故を防ぐため:
{"translation": "翻訳全文"}
gifsicle のオプションを手動で使用するためのコントロールも用意してください。各プレビューには「これらの設定を調整する」というリンクがあり、そのプレビューに使用された手動設定が適用されるため、ユーザーはさらにカスタマイズできます
"uvx rodney –help" を実行し、そのツールを使用して作業を試してください - 検証用 GIF はこちら https://static.simonwillison.net/static/2026/animated-word-cloud-demo.gif
こちらは 構築されたもの です。また、このツールで最適化したアニメーション GIF のデモも用意しています:

それでは、プロンプトを一つずつ見ていきましょう。
gif-optimizer.html
最初の行は、作成したいファイルの名前を指定するだけです。ここではファイル名だけで十分です。Claude がリポジトリで "ls" コマンドを実行すると、すべてのファイルが異なるツールであると理解できるからです。
私の simonw/tools リポジトリには現在、CLAUDE.md や AGENTS.md ファイルがありません。エージェントは、既存のファイルツリーをスキャンし、既存ファイル内の関連コードを確認するだけで、リポジトリの要点を十分に把握できることがわかりました。
gifsicle を WASM(WebAssembly)にコンパイルし、アニメーション GIF を開くかドラッグ&ドロップして表示できる Web ページを作成します。その後、gifsicle を使用して異なる設定で圧縮された GIF を表示し、各プレビューにはサイズとダウンロードボタンを表示します
ここでは Claude の既存の知識についていくつか仮定を置いていますが、すべてが的中しました。
Gifsicle はもうほぼ 30 年になるソフトウェアであり、広く使われているツールです。名前を挙げて参照するだけで Claude がコードを見つけられると確信していました。
「gifsicle を WASM にコンパイルする」という指示は、ここで非常に多くの作業を行っています。
WASM とは WebAssembly の略で、これはブラウザがサンドボックス内でコンパイルされたコードを安全に実行できるようにする技術です。
Gifsicle のようなプロジェクトを WASM にコンパイルするのは簡単な作業ではなく、通常は Emscripten プロジェクトを含む複雑なツールチェーンを必要とします。すべてを動作させるためには、多くの試行錯誤が必要になることがよくあります。
コーディングエージェントは試行錯誤において素晴らしい能力を発揮します!彼らは、私が 5 つ目の解読不能なコンパイラーエラーで諦めていたような場合でも、ブルートフォースで解決策にたどり着くことができます。
Claude Code が以前にも何度も WASM ビルドを解決する様子を見てきたので、今回もうまくいくとかなり確信していました。
「アニメーション GIF を開いたり、ドラッグ&ドロップしたりできる Web ページを作成する」という指示は、私が他の多くのツールで使ってきたパターンを説明しています。
HTML ファイルアップロードはファイル選択には問題なく機能しますが、より良い UI、特にデスクトップ環境では、ページ上の目立つドロップゾーンにファイルをドラッグ&ドロップできるようにするのがおすすめです。
これを設定するには、イベントを処理するための少しの JavaScript と、ドロップゾーンの CSS が必要です。複雑ではありませんが、通常は自分で追加しない程度の追加作業量です。プロンプトを使えば、ほぼ無料で行えます。
これが最終的な UI です。既存の image-resize-quality ツールを Claude が見た影響を受けています。

GIF の URL 入力欄は設けませんでしたし、私もあまり好んでいません。なぜなら、これはオープンな CORS ヘッダーで提供されている GIF の URL にしか機能しないからです。将来的なアップデートではおそらくこれを削除するつもりです。
「gifsicle を使用してさまざまな設定で圧縮された GIF を表示し、各プレビューにはサイズとダウンロードボタンが含まれる」という記述は、このアプリケーションの主要機能を説明しています。
私が望む設定のコレクションを定義するために手間をかけませんでした。私の経験では、Claude はそれらを選ぶのに十分なセンスを持っており、最初の推測が機能しない場合でも後で変更できるからです。
サイズを表示することは重要です。なぜなら、これはすべてサイズの最適化に関するものだからです。
過去の経験から、「ダウンロードボタン」を要求すると、適切な HTML と JavaScript のメカニズムが設定されたボタンが作成され、クリックすることでファイル保存ダイアログが表示されることを知っています。これは「右クリックして名前を付けて保存」する必要がある場合に比べて便利な機能です。
また、手動使用のための gifsicle オプションのコントロールも含まれています。各プレビューには「これらの設定を調整する」というリンクがあり、これによりそのプレビューに使用された手動設定が適用され、ユーザーはさらにカスタマイズできるようになります。
これはかなり不器用なプロンプトです - やはりスマホで入力していたので - けれど、Claude が私が望むものを作成するのに十分な意図を伝えることができました。
これが結果として生まれたツールの様子で、このスクリーンショットはモバイルバージョンを示しています。各画像には「設定を微調整」ボタンがあり、これをクリックすると、この一連の手動設定とスライダーが更新されます:

"uvx rodney --help"を実行し、そのツールを使って自分の成果を試してください - 検証用にはこのGIFを使用してください https://static.simonwillison.net/static/2026/animated-word-cloud-demo.gif
コーディングエージェントが*はるかに*よく機能するためには、作業中にコードをテストする能力を持たせることが重要です。
ウェブインターフェースのテストには多くの異なる方法があります - Playwright と Selenium と agent-browser は3つの堅牢な選択肢です。
Rodney は私が構築したブラウザ自動化ツールで、インストールが迅速であり、--help 出力にはエージェントがこのツールを使用するために知るべきすべてのことを教えるように設計されています。
これは素晴らしい結果となりました - セッションのトランスクリプト では、Claude がRodneyを使用して発見したいくつかのminorなバグを修正している様子を確認できます。例えば:
CSS の display: none がインラインスタイルのリセットを上回っています。display: 'block' を明示的に設定する必要があります。
続編のプロンプト
Claude Code を使っているときは、通常、その動作を注視して、まだ実行中の段階で方向転換できるようにしています。また、作業中に新しいアイデアが浮かぶことも多く、それらをすぐにキューに追加します。
ビルドスクリプトと、元の gifsicle コードとの差分は、適切なサブディレクトリに配置したコミットに含まれていなければなりません。
ビルドスクリプトは、gifsicle リポジトリを/tmp にクローンし、既知のコミットに切り替えた後に差分を適用するものでなければなりません。つまり、コミット内に gifsicle のコピーを含めるのではなく、wqsm を構築するために必要なすべてのスクリプトを含める必要があります。
Gifsicle が WebAssembly で動作する方法を見つけるために非常に多くの労力を費やし、元のソースコードをパッチ適用していることに気づいたときに、私はこれを追加しました。これが そのパッチ です。また、リポジトリに追加された ビルドスクリプト もあります。
このリポジトリには、サポートファイルがどこにあるかというパターンがすでに存在していることは知っていましたが、そのパターンの詳細を覚えていませんでした。「適切なサブディレクトリに」と伝えるだけで、Claude はどこに配置すべきかを理解しました。そして既存の lib/ ディレクトリ を見つけて使用したのです。
WebAssembly バンドルを含める必要があります
これはおそらく不要だったのですが、コンパイルされた WASM ファイル(結果的に 233KB になりました)がリポジトリにコミットされていることを確実にしたかったのです。私は simonw/tools を GitHub Pages で tools.simonwillison.net というドメインで提供していますが、ローカルでビルドする必要なく動作することを望んでいました。
HTML ページで gifsicle へのクレジットを表示し、リポジトリへのリンクを設けること
これは単なる礼儀です。私はしばしば他の人のオープンソースプロジェクトの周りに WebAssembly のラッパーを作成しますが、その結果として生成されたページで貢献者にクレジットが与えられるようにすることを好んでいます。
Claude はこのツールのフッターに以下を追加しました:
gifsicle(Eddie Kohler 作)を使用して構築され、WebAssembly にコンパイルされました。gifsicle は GNU General Public License バージョン 2 の下でリリースされています。
タグ: claude, ai, claude-code, llms, prompt-engineering, webassembly, coding-agents, tools, generative-ai, gif, agentic-engineering
原文を表示
*Agentic Engineering Patterns >*
I like to include animated GIF demos in my online writing, often recorded using LICEcap. There's an example in the Interactive explanations chapter.
These GIFs can be pretty big. I've tried a few tools for optimizing GIF file size and my favorite is Gifsicle by Eddie Kohler. It compresses GIFs by identifying regions of frames that have not changed and storing only the differences, and can optionally reduce the GIF color palette or apply visible lossy compression for greater size reductions.
Gifsicle is written in C and the default interface is a command line tool. I wanted a web interface so I could access it in my browser and visually preview and compare the different settings.
I prompted Claude Code for web (from my iPhone using the Claude iPhone app) against my simonw/tools repo with the following:
gif-optimizer.html
Compile gifsicle to WASM, then build a web page that lets you open or drag-drop an animated GIF onto it and it then shows you that GIF compressed using gifsicle with a number of different settings, each preview with the size and a download button
Also include controls for the gifsicle options for manual use - each preview has a “tweak these settings” link which sets those manual settings to the ones used for that preview so the user can customize them further
Run “uvx rodney –help” and use that tool to tray your work - use this GIF for testing https://static.simonwillison.net/static/2026/animated-word-cloud-demo.gif
Here's what it built, plus an animated GIF demo that I optimized using the tool:

Let's address that prompt piece by piece.
gif-optimizer.html
The first line simply tells it the name of the file I want to create. Just a filename is enough here - I know that when Claude runs "ls" on the repo it will understand that every file is a different tool.
My simonw/tools repo currently lacks a CLAUDE.md or AGENTS.md file. I've found that agents pick up enough of the gist of the repo just from scanning the existing file tree and looking at relevant code in existing files.
Compile gifsicle to WASM, then build a web page that lets you open or drag-drop an animated GIF onto it and it then shows you that GIF compressed using gifsicle with a number of different settings, each preview with the size and a download button
I'm making a bunch of assumptions here about Claude's existing knowledge, all of which paid off.
Gifsicle is nearly 30 years old now and is a widely used piece of software - I was confident that referring to it by name would be enough for Claude to find the code.
"Compile gifsicle to WASM" is doing a *lot* of work here.
WASM is short for WebAssembly, the technology that lets browsers run compiled code safely in a sandbox.
Compiling a project like Gifsicle to WASM is not a trivial operation, involving a complex toolchain usually involving the Emscripten project. It often requires a lot of trial and error to get everything working.
Coding agents are fantastic at trial and error! They can often brute force their way to a solution where I would have given up after the fifth inscrutable compiler error.
I've seen Claude Code figure out WASM builds many times before, so I was quite confident this would work.
"then build a web page that lets you open or drag-drop an animated GIF onto it" describes a pattern I've used in a lot of my other tools.
HTML file uploads work fine for selecting files, but a nicer UI, especially on desktop, is to allow users to drag and drop files into a prominent drop zone on a page.
Setting this up involves a bit of JavaScript to process the events and some CSS for the drop zone. It's not complicated but it's enough extra work that I might not normally add it myself. With a prompt it's almost free.
Here's the resulting UI - which was influenced by Claude taking a peek at my existing image-resize-quality tool:

I didn't ask for the GIF URL input and I'm not keen on it, because it only works against URLs to GIFs that are served with open CORS headers. I'll probably remove that in a future update.
"then shows you that GIF compressed using gifsicle with a number of different settings, each preview with the size and a download button" describes the key feature of the application.
I didn't bother defining the collection of settings I wanted - in my experience Claude has good enough taste at picking those for me, and we can always change them if its first guesses don't work.
Showing the size is important since this is all about optimizing for size.
I know from past experience that asking for a "download button" gets a button with the right HTML and JavaScript mechanisms set up such that clicking it provides a file save dialog, which is a nice convenience over needing to right-click-save-as.
Also include controls for the gifsicle options for manual use - each preview has a “tweak these settings” link which sets those manual settings to the ones used for that preview so the user can customize them further
This is a pretty clumsy prompt - I was typing it in my phone after all - but it expressed my intention well enough for Claude to build what I wanted.
Here's what that looks like in the resulting tool, this screenshot showing the mobile version. Each image has a "Tweak these settings" button which, when clicked, updates this set of manual settings and sliders:

Run “uvx rodney --help” and use that tool to tray your work - use this GIF for testing https://static.simonwillison.net/static/2026/animated-word-cloud-demo.gif
Coding agents work *so much better* if you make sure they have the ability to test their code while they are working.
There are many different ways to test a web interface - Playwright and Selenium and agent-browser are three solid options.
Rodney is a browser automation tool I built myself, which is quick to install and has --help output that's designed to teach an agent everything it needs to know to use the tool.
This worked great - in the session transcript you can see Claude using Rodney and fixing some minor bugs that it spotted, for example:
The CSS display: none is winning over the inline style reset. I need to set display: 'block' explicitly.
The follow-up prompts
When I'm working with Claude Code I usually keep an eye on what it's doing so I can redirect it while it's still in flight. I also often come up with new ideas while it's working which I then inject into the queue.
Include the build script and diff against original gifsicle code in the commit in an appropriate subdirectory
The build script should clone the gifsicle repo to /tmp and switch to a known commit before applying the diff - so no copy of gifsicle in the commit but all the scripts needed to build the wqsm
I added this when I noticed it was putting a *lot* of effort into figuring out how to get Gifsicle working with WebAssembly, including patching the original source code. Here's the patch and the build script it added to the repo.
I knew there was a pattern in that repo already for where supporting files lived but I couldn't remember what that pattern was. Saying "in an appropriate subdirectory" was enough for Claude to figure out where to put it - it found and used the existing lib/ directory.
You should include the wasm bundle
This probably wasn't necessary, but I wanted to make absolutely sure that the compiled WASM file (which turned out to be 233KB) was committed to the repo. I serve simonw/tools via GitHub Pages at tools.simonwillison.net and I wanted it to work without needing to be built locally.
Make sure the HTML page credits gifsicle and links to the repo
This is just polite! I often build WebAssembly wrappers around other people's open source projects and I like to make sure they get credit in the resulting page.
Claude added this to the footer of the tool:
Built with gifsicle by Eddie Kohler, compiled to WebAssembly. gifsicle is released under the GNU General Public License, version 2.
Tags: claude, ai, claude-code, llms, prompt-engineering, webassembly, coding-agents, tools, generative-ai, gif, agentic-engineering
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み