Skip to content
Merged
41 changes: 4 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,17 @@
# Claudiu

Claudiu is a native desktop app, written in Rust with [Rune](https://github.com/anomalyco/rune), that runs several [Claude Code](https://code.claude.com) sessions in one window on Windows, macOS and Linux. It is a personal project with rough edges. Issues and pull requests are welcome.
Claudiu is a native desktop app, written in Rust with [Rune](https://github.com/anomalyco/rune), that runs several [Claude Code](https://code.claude.com) sessions in one window on Windows, macOS and Linux. It is a personal project with rough edges: macOS and Linux are lightly tested, and the macOS build isn't notarized. Issues and pull requests are welcome.

> **Claudiu is an independent project. It is not affiliated with, endorsed by or sponsored by Anthropic.** Claude and Claude Code are trademarks of Anthropic.

## What it does

Each session is your own `claude` process in a real pseudo-terminal, so Claude Code's keys, mouse and paste work unchanged. Claudiu has no API keys and never calls the Anthropic API. Sign-in stays with Claude Code. The first launch opens a setup window that checks for `claude` (required) and `gh` (optional), links to their install pages and installs nothing. It also has an optional switch that turns off six Claude Code features that add tokens to every request and that coding rarely uses, such as Artifacts and bundled skills. Settings → Claude Code tools shows each switch as high, medium or low savings. Settings has a Check setup button to open it again. A sidebar lists your running sessions, with the rest in a Recent list at its bottom that opens and scrolls. Settings → Projects adds, renames, reorders and removes projects. Removing one keeps its sessions, and the notice that follows has an Undo button. Ended sessions resume through `claude --resume`, and sessions that were running come back at the next start.

Around the terminal, Claudiu adds an editor mode (Ctrl+Shift+E) with files, tabs, search, Git change marks and language-server diagnostics, definitions and completion. It also adds usage and context meters, a GitHub pane for issues and pull requests through your `gh` login (Claude attaches the ones it works on to the right sidebar, from this project or another repository), defaults for the model, effort and permission mode of new sessions, and extra Claude accounts that share one configuration: settings, `CLAUDE.md`, keybindings, MCP servers, folder trust and the options `/config` saves, with your main `~/.claude` too. An account with a running session takes a changed `/config` option once its sessions have ended. You name a session yourself, from its right-click menu, by regenerating its title, or with `/rename` in Claude Code, which Claudiu's sidebar follows. When a reply needs a table, chart or diagram, Claude draws it as a card inside the terminal, under the tool call, and the card scrolls with the transcript. Cards can hold buttons that send a message for you, collapsible sections, tabs and charts, and they come back when you reopen a session. A session can move between git worktrees the way it switches branches, so several agents work on separate branches at once: the worktree button in the top bar switches the shown session into another worktree, or into a new one that Claudiu makes on a branch you name, and its conversation continues there (a session that has no conversation yet starts over in the new folder). Claude can switch the session itself with the `switch_worktree` tool, after you approve it and once its turn ends. In the menu, the hover x removes a worktree, the branch button's x deletes a local branch after telling you which commits would be lost, and ending the last session in a worktree offers to remove it. Claudiu keeps the worktrees it makes in its own data folder, outside your repositories, so they never show up in `git status`; Settings has a Worktrees page that lists them to show in the file manager or remove. Settings lists the rest.

Ctrl+Shift (Cmd+Shift on macOS) plus a letter drives the app. Everything else reaches Claude Code. Editor mode finds `rust-analyzer`, `tsc --lsp` and `gleam` on your PATH and installs nothing.

To reduce background rendering, an inactive window updates streaming terminal output at most four times a second, with a final update when output stops. Returning to the window restores the normal frame rate. Busy sidebar icons stop animating while the window is inactive, the sidebar is hidden, or editor mode hides it. When a session finishes or asks a question while the window is in the background, Claudiu sends a system notification.
Each session is your own `claude` process in a real terminal, and sign-in stays with Claude Code. Around it, Claudiu adds a sidebar of running and recent sessions, notifications when a background session finishes or asks something, an editor mode (Ctrl+Shift+E), usage meters, a GitHub pane, cards Claude draws inline, sessions that move between git worktrees, extra accounts that share one configuration, and Codex and OpenCode subagents (Settings → Custom subagents). Codex subagents need Node and a `codex login`, OpenCode subagents need `opencode` on PATH, and with Allow edits on, either acts without Claude Code's permission rules. Settings lists the rest.

## What it touches

Claudiu never deletes a transcript. It writes to Claude Code's own data only to change the settings you switch in Claudiu, as `/config` does, to sync shared files between accounts, and to append one line to a transcript when a session that `claude --worktree` put in a worktree moves to another folder, so Claude Code knows it has left that worktree. Nothing is uploaded and terminal contents are never logged. The only network use is GitHub: the update check (off with `"settings": { "update_url": "" }` in `state.json`) and the GitHub pane. State lives in `%LOCALAPPDATA%\m4rocks\Claudiu\data` on Windows, `~/Library/Application Support/Claudiu` on macOS and `~/.local/share/claudiu` on Linux, and crashes go to `crash.log` there.

## Known gaps

- macOS is lightly tested, and the build isn't notarized, so Gatekeeper complains on first launch.
- Linux is new and lightly tested.
- Quitting ends running PTYs. Sessions stay resumable, but live processes don't survive a restart.
Claudiu never calls the Anthropic API or deletes a transcript, and it changes Claude Code's settings only when you flip a switch. Its network use is GitHub (the update check and the GitHub pane), plus npm and OpenAI once you turn on Codex subagents, and the providers you set up in OpenCode once you turn on OpenCode subagents. Terminal contents are never logged.

## Development

You need stable Rust. On Windows you also need Visual Studio Build Tools (C++) and the Windows SDK. On Linux you need the headers Rune builds against; on Debian or Ubuntu:

```sh
sudo apt install libwayland-dev libxkbcommon-dev libvulkan1 zlib1g-dev
```

Tasks go through [just](https://just.systems); run `just` to list them.

```sh
just run # dev build: shows stderr, never checks for updates
just test # app tests and mod tests (the mod tests need the claude CLI)
just lint # clippy
just ci # what CI checks, plus the mod and the web build
```

The repository has three parts:

- `src/` is the app, including the MCP server that each session connects to.
- `mod/` is the Claude Code plugin each session loads, which writes the usage snapshots.
- `web/` is the Astro site.

`CLAUDE.md` has the conventions for contributing. Releases use [Velopack](https://velopack.io) and GitHub Releases: bump `version` in `Cargo.toml`, then `git tag vX.Y.Z && git push --tags`. `scripts\package.ps1` builds a local installer. The Linux release is an AppImage.
You need stable Rust, plus Visual Studio Build Tools on Windows or the headers Rune builds against on Linux, and [just](https://just.systems): `just run`, `just test`, `just ci`. `src/` is the app, `mod/` is the Claude Code plugin each session loads, and `web/` is the site. `CLAUDE.md` has the conventions. To release, bump `version` in `Cargo.toml` and push a `vX.Y.Z` tag.
138 changes: 137 additions & 1 deletion mod/hooks/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
// paints the live card over them. Claudiu's measured height comes back in `CLAUDIU_VISUAL_PREFIX<call>.rows`.
// - One-shot completions: runs requests from `CLAUDIU_ASK_FILE` (commit messages, session titles) with
// `$.model.complete`, on this session's own client, so Claudiu needs no `claude -p`.
// - Custom subagents: registers the Codex and OpenCode agent types `CLAUDIU_SUBAGENTS` lists. Claude never runs for
// those agents: each turn is answered here with what the agent writes through `CLAUDIU_EXE --acp`, and its last
// message is handed back with SubagentHandback.

// ---- Constants ----------------------------------------------------------------------------------------------------

Expand All @@ -33,6 +36,7 @@ const PROMPT_MAX = 20000 // characters of a message Claudiu asks the session to
const EFFORTS = ['low', 'medium', 'high', 'xhigh', 'max']
const ASK_MODELS = ['haiku', 'sonnet', 'opus']
const VISUAL_TOOL = 'mcp__claudiu__show_visual'
const HANDBACK_TOOL = 'SubagentHandback'
// The /config row for background compaction ("Precompute compaction"). Claude Code lists it only while a server-side
// flag enables the feature; without the row the setting does nothing, so Claudiu offers the switch only with it.
const PRECOMPUTE_ROW = 'precomputeCompactionEnabled'
Expand All @@ -49,6 +53,10 @@ let askPoll // watches CLAUDIU_ASK_FILE
let askSeen = null // id of the last request looked at
let asking = false // a completion is running; a poll that finds another request waits for it
const cardRows = new Map() // show_visual call id -> rows reserved for its card
const AGENT_NAMES = { codex: 'Codex', opencode: 'OpenCode' } // the agents of `claude/subagents.rs`, by their key
const AGENT_PREFIX = 'Claudiu:' // what Claude Code puts before an agent type this plugin registers
const customTypes = new Map() // agent type name -> { agent, model, edits } of each custom agent type Claudiu defined
const customRuns = new Map() // agent id -> { type, prompt, turnId, report } of each custom subagent started
const published = new Set() // call ids whose card file this process wrote from the transcript
let rowsPoll // watches the heights Claudiu measures
let visualChain = Promise.resolve() // visual writes in order, without holding up the stream
Expand Down Expand Up @@ -337,6 +345,130 @@ async function watchSessionName($) {
})
}

// ---- Custom subagents ---------------------------------------------------------------------------------------------

// Registers the custom agent types Claudiu listed for this session (`claude/subagents.rs`); Claude Code names each
// `Claudiu:<name>`. Interactive Claude Code ignores `claude --agents`, so this is where they are defined. A missing or
// broken list registers none.
async function registerSubagents($) {
customTypes.clear()
const listed = await $.env.get('CLAUDIU_SUBAGENTS')
if (!listed || !(await $.env.get('CLAUDIU_EXE'))) return
let agents
try {
agents = JSON.parse(listed)
} catch {
return
}
for (const agent of Object.keys(AGENT_NAMES)) {
const listing = agents?.[agent]
for (const { name, model, description, prompt } of listing?.types ?? []) {
if (![name, model, description, prompt].every(v => typeof v === 'string')) continue
// Claude never runs for this agent (customStep answers its turns) unless this module lost track of it; the
// prompt then says so.
await $.agent.register({ name, description, prompt, model: 'haiku', tools: [] })
.then(() => customTypes.set(AGENT_PREFIX + name, { agent, model, edits: listing.edits === true }))
.catch(() => {})
}
}
}

// Notes the task of each custom subagent as it starts; its turns are answered by customStep.
async function onAgentSpawn($, e, next) {
const r = await next(e)
if (r.agentId && customTypes.has(e.subagentType)) {
customRuns.set(r.agentId, { type: e.subagentType, prompt: e.prompt, turnId: null, report: null, handedBack: 0 })
}
return r
}

// The custom run of a subagent, or undefined for any other agent. A reload of this module forgets the runs it noted,
// so an agent of a custom type not noted is taken up from the agent list, with its newest message as the task.
async function customRun($, agentId) {
if (customRuns.has(agentId) || customTypes.size === 0) return customRuns.get(agentId)
const agent = (await $.agent.list().catch(() => [])).find(a => a.id === agentId)
if (!agent || !customTypes.has(agent.type)) return undefined
const run = { type: agent.type, prompt: null, turnId: null, report: null, handedBack: 0 }
customRuns.set(agentId, run)
return run
}

// The task for this turn: the Agent call's prompt on the first turn, the newest message to the agent after that
// (a message sent to a finished subagent starts a turn of its own).
async function customTask($, run, agentId) {
if (run.turnId === null && run.prompt !== null) return run.prompt
const messages = await $.session.messages({ agentId }).catch(() => [])
const last = Array.isArray(messages) ? messages.filter(m => m.role === 'user' && m.text?.trim()).at(-1) : undefined
return last?.text ?? run.prompt ?? ''
}

// Answers one step of a custom subagent: runs the task in its agent, streams what the agent writes and does as the
// subagent's own text (saved in its transcript, which only the person reads), and hands back the agent's last message
// as the report. The agent runs once per turn; a later step of the same turn (a refused hand-back)
// hands back the same report once more, then ends the turn with the report as plain text so a hand-back that keeps
// being refused can't loop.
async function* customStep($, e, next, run) {
if (run.turnId !== e.turnId || run.report === null) {
const prompt = await customTask($, run, e.agentId)
run.turnId = e.turnId
run.handedBack = 0
const { agent, model, edits } = customTypes.get(run.type)
const name = AGENT_NAMES[agent]
yield { kind: 'text', index: 0, text: `${name} on ${model}, ${edits ? 'edits allowed' : 'read-only'}\n\n` }
run.report = null
for await (const event of helperEvents($, { agent, model, edits, cwd: await $.session.cwd(), prompt }, next.signal)) {
if (event.kind === 'text') yield { kind: 'text', index: 0, text: event.text }
else if (event.kind === 'step') yield { kind: 'text', index: 0, text: `\n▸ ${event.text}\n` }
else if (event.kind === 'report') run.report = event.text
else if (event.kind === 'failed') run.report = `${name} failed: ${event.reason}`
}
if (next.signal?.aborted) return
run.report ??= `${name} failed: the helper stopped without an answer.`
}
if (run.handedBack >= 2) {
yield { kind: 'text', index: 1, text: run.report }
yield { kind: 'stop', stopReason: 'end_turn', usage: null }
return { turnId: e.turnId, index: e.index, answer: run.report, toolUses: [], stopReason: 'end_turn', usage: null }
}
run.handedBack += 1
const input = { message: run.report }
yield { kind: 'tool', index: 1, id: `toolu_custom_${e.turnId}_${e.index}`, name: HANDBACK_TOOL }
yield { kind: 'input', index: 1, json: JSON.stringify(input) }
yield { kind: 'stop', stopReason: 'tool_use', usage: null }
return { turnId: e.turnId, index: e.index, answer: '', toolUses: [{ name: HANDBACK_TOOL, input }], stopReason: 'tool_use', usage: null }
}

// The helper's events, one per line of its output. Stops early, ending the helper and the agent, when the turn is
// interrupted.
async function* helperEvents($, request, signal) {
const exe = await $.env.get('CLAUDIU_EXE')
let pending = ''
try {
for await (const chunk of $.process.spawn({ argv: [exe, '--acp'], input: JSON.stringify(request) })) {
if (signal?.aborted) return
if (chunk.stream !== 'stdout') continue
pending += chunk.text
const lines = pending.split('\n')
pending = lines.pop()
for (const line of lines) {
const event = parseEvent(line)
if (event) yield event
}
}
} catch (err) {
yield { kind: 'failed', reason: 'the helper could not run (' + String(err?.message ?? err).slice(0, 200) + ')' }
}
}

function parseEvent(line) {
try {
const event = JSON.parse(line)
return typeof event?.kind === 'string' ? event : null
} catch {
return null
}
}

// ---- Hook handlers ------------------------------------------------------------------------------------------------

async function onMeasure($, e, next) {
Expand Down Expand Up @@ -438,8 +570,10 @@ async function onShowVisual($, e) {
}

// Applies the saved model and effort to this turn's steps, and streams a show_visual call to its card while the model
// writes it. Sub-agent steps are left alone.
// writes it. A custom subagent's steps are answered by customStep; other subagents' steps are left alone.
async function* onTurnStep($, e, next) {
const run = e.agentId ? await customRun($, e.agentId) : undefined
if (run) return yield* customStep($, e, next, run)
const step = !e.agentId && (want.model || want.effort)
? { ...e, model: want.model ?? e.model, effort: want.effort ?? e.effort }
: e
Expand Down Expand Up @@ -514,6 +648,7 @@ async function onSessionStart($, e, next) {
rowsPoll?.cancel()
rowsPoll = $.clock.every(200, () => readCardRows($))
await watchSessionName($)
await registerSubagents($)
return r
}

Expand All @@ -527,5 +662,6 @@ export function register(on) {
on('ui.render', { component: 'ToolUse' }, onVisualRow)
on('ui.render', { component: 'ToolGroup' }, onVisualGroup)
on('turn.step', onTurnStep)
on('agent.spawn', onAgentSpawn)
on('session.start', onSessionStart)
}
Loading
Loading