hono-electron-ipc
A Claude Code plugin for implementing type-safe IPC communication in Electron applications using Hono RPC, CQRS architecture, and reactive state management.
Features
- Type-Safe IPC: Full TypeScript inference across main and renderer processes
- Factory Pattern with DI: Dependency injection for testable services
- Zod Validation: Request validation with Zod schemas
- CQRS Architecture: Observable queries and ResultAsync commands
- Reactive State: Jotai hybrid atoms with IPC subscriptions
- Migration Support: Migrate existing ipcRenderer/ipcMain to Hono
Installation
From Marketplace
/plugin marketplace add napochaan/hono-electron-ipc
/plugin install hono-electron-ipc
Local Development
claude --plugin-dir ./hono-electron-ipc
Quick Start
1. Initialize Hono IPC
/hono-electron-ipc:init
This scaffolds the complete directory structure:
src/
├── shared/
│ └── callable/
│ ├── index.ts # Factory and app creation
│ └── types.d.ts # Type export for client
├── main/
│ └── callable/
│ └── index.ts # Service injection
└── renderer/
└── src/
└── adapters/
└── client.ts # Type-safe hc client
2. Add Routes (Basic)
/hono-electron-ipc:add-route users
Creates a new route with Zod validation:
// src/shared/callable/users/index.ts
import { zValidator } from '@hono/zod-validator';
import { Hono } from 'hono';
import { z } from 'zod';
const app = new Hono<HonoEnv>();
export const routes = app
.get('/', (c) => c.json({ users: [] }))
.get('/:id', (c) => c.json({ id: c.req.param('id') }));
3. Use in Renderer
import { client } from '@adapters/client';
// Full autocomplete and type checking!
const res = await client.users[':id'].$get({ param: { id: 'usr_123' } });
const user = await res.json();
Advanced Patterns
CQRS Service with Observable Queries
/hono-electron-ipc:new-service users
Creates a CQRS service:
export class UserServiceImpl implements UserService {
#notify = new BehaviorSubject(Date.now());
// Query: Observable for reactive data streams
list(): Observable<User[]> {
return concat(
from(this.#getUsers()),
this.#notify.pipe(mergeMap(() => this.#getUsers()))
);
}
// Command: ResultAsync for type-safe operations
create(data: CreateUserData): ResultAsync<void, Error> {
return this.#insertUser(data)
.andThen(() => {
this.#notify.next(Date.now());
return okAsync(void 0);
});
}
}
Reactive Jotai Atoms with IPC Subscriptions
/hono-electron-ipc:new-hybrid-atom users
Creates a hybrid atom (stream + HTTP fallback):
// Stream atom (IPC subscription)
const streamUsersAtom = atom<{ value: User[] }>();
streamUsersAtom.onMount = (set) => {
const handler = debounce(async () => {
const data = await client.users.$get().then(r => r.json());
set({ value: data });
}, 300);
handler();
return usersSource.subscribe(handler);
};
// Hybrid selector
export const usersAtom = atom(async (get) => {
const stream = get(streamUsersAtom);
if (stream === undefined) return get(singleFetchAtom);
return stream.value;
});
Type-Safe Route with CQRS Integration
/hono-electron-ipc:new-route users
Creates a route with CQRS service integration:
const route = new Hono()
.get('/', async (c) => {
const users = await firstValueFromResult(
c.var.services.users.list()
);
return users.match(
(data) => c.json(data, 200),
(error) => c.json({ error: error.message }, 500)
);
});
// Client: Full type inference
const users = await client.users.$get().then(r => r.json());
Migrating Existing IPC
/hono-electron-ipc:migrate
This orchestrates a full migration from traditional IPC to Hono:
- Analyze - Finds all
ipcMain.handle and ipcRenderer.invoke calls
- Plan - Designs RESTful route structure
- Execute - Creates route files and updates registrations
Commands
Basic Commands
| Command | Description |
|---|
/hono-electron-ipc:init | Initialize Hono IPC architecture |
/hono-electron-ipc:add-route [name] | Add a basic route with validation |
/hono-electron-ipc:migrate | Migrate existing IPC to Hono |
Advanced Commands (CQRS + Reactive)
| Command | Description |
|---|
/hono-electron-ipc:new-service [name] | Create CQRS service with Observable/ResultAsync |
/hono-electron-ipc:new-route [name] | Create route with CQRS integration |
/hono-electron-ipc:new-hybrid-atom [name] | Create Jotai hybrid atom with IPC subscription |
Skills
Core Skills
hono-ipc-setup
Auto-triggers when discussing IPC setup, Hono for Electron, or type-safe IPC.