Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Claudiu is a native desktop app, written in Rust with [Rune](https://github.com/

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. 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.
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.

Expand Down
8 changes: 6 additions & 2 deletions mod/hooks/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// - Messages: sends a message Claudiu asks for through the same file (the editor's Ask Claude) as the user's own words,
// when the session is idle, without typing into the terminal. (Claudiu itself pastes the editor's `@file#L`
// reference into Claude's input box; that is not done here.)
// - Usage and status: reports context, the 5-hour and 7-day limits, auto-compact, background compaction, advisor and
// the last command to `CLAUDIU_USAGE_DIR/<claude session id>.json`. No tokens are spent.
// - Usage and status: reports context, the 5-hour and 7-day limits, auto-compact, background compaction and advisor to
// `CLAUDIU_USAGE_DIR/<claude session id>.json`, after each request, command and setting change. No tokens are spent.
// - Cards: answers `show_visual` in-process and, while the model is still writing the call, streams its Markdown to
// `CLAUDIU_VISUAL_PREFIX<call>.json`. Under each call it reserves rows, each with a link naming the call, and Claudiu
// paints the live card over them. Claudiu's measured height comes back in `CLAUDIU_VISUAL_PREFIX<call>.rows`.
Expand Down Expand Up @@ -354,6 +354,10 @@ async function onMeasure($, e, next) {

async function onCommandRun($, e, next) {
const r = await next(e) // the command has run: a setting it changed is read after it
// A name the user gave with /rename is the session's now. Claudiu reads it from the transcript and writes it back to
// CLAUDIU_NAME_FILE; it is already applied, so that must not run /rename again.
const name = e.command === 'rename' ? e.args.trim() : ''
if (name) named = (await $.session.id()) + '\n' + name
await report($, true)
return r
}
Expand Down
20 changes: 20 additions & 0 deletions mod/hooks/rename.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,23 @@ test('applies a changed name with /rename, never the launch name, and again afte
await clock.advance(1000)
expect(renames).toEqual(['rename New name', 'rename New name'])
})

test('a name the user gave with /rename is not applied again when Claudiu writes it back', async ($, on) => {
const clock = mock.clock(on)
mock.env(on, { CLAUDIU_NAME_FILE: 'names/s.txt' })
let name = 'Launch name'
const renames: string[] = []
on('fs.read', () => ({ value: name }))
on('session.id', () => ({ value: 'claude-1' }))
on('session.start', (_$, e) => ({ cwd: e.cwd }))
on('command.run', (_$, e) => {
renames.push(`${e.command} ${e.args}`)
return {}
})

await $.session.start({ cwd: '/repo', surface: 'terminal', isInteractive: true })
await $.command.run({ command: 'rename', args: ' Typed name ', origin: { kind: 'composer' }, presentation: { isFullscreen: false, columns: 80 } })
name = 'Typed name' // Claudiu adopted it from the transcript and wrote it back
await clock.advance(3000)
expect(renames).toEqual(['rename Typed name '])
})
26 changes: 3 additions & 23 deletions src/app/ingest.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Taking in what other processes left in the data folder: the per-process mod's usage snapshots (limits, context,
//! settings), the tab titles Claude chose, and the links and GitHub items sessions asked for. Reading the files is
//! settings), and the links and GitHub items sessions asked for. Reading the files is
//! off the UI thread; applying them is a handful of small, separately testable steps.

use super::*;
Expand All @@ -10,10 +10,9 @@ impl Workspace {
/// Costs no tokens; the files are tiny.
pub(super) fn ingest_usage(&mut self) {
self.rt.spawn_quietly(
move || { (usage::read_snapshots(&usage::snapshot_dir()), mcp::read_titles(), mcp::read_attached()) },
move |ws: &mut Workspace, (snaps, titles, items)| {
move || { (usage::read_snapshots(&usage::snapshot_dir()), mcp::read_attached()) },
move |ws: &mut Workspace, (snaps, items)| {
let mut changed = false;
changed |= titles.into_iter().fold(false, |c, (stem, title, stamp)| ws.apply_title(&stem, title, stamp) | c);
changed |= snaps.iter().fold(false, |c, snap| ws.apply_snapshot(snap) | c);
changed |= items.into_iter().fold(false, |c, (stem, item)| ws.apply_attachment(&stem, item) | c);
if changed {
Expand All @@ -24,25 +23,6 @@ impl Workspace {
);
}

/// A title Claude chose for its session through the MCP tool.
fn apply_title(&mut self, stem: &str, title: String, stamp: Option<SystemTime>) -> bool {
let Some(rec) = self.store.data.sessions.iter_mut().find(|s| s.claude_id().is_some_and(|id| datadir::safe_file_stem(id) == stem)) else { return false };
if let Some(l) = self.live.iter_mut().find(|l| l.id == rec.id)
&& l.title_stamp != stamp
{
// The first read only records the stamp: a resumed session already got `--name`.
if l.title_stamp.is_some() {
l.claude_name = None;
}
l.title_stamp = stamp;
}
if rec.auto_title.as_deref() == Some(title.as_str()) {
return false;
}
rec.auto_title = Some(title);
true
}

/// One mod report: the account's limits, and the session's own figures and settings.
fn apply_snapshot(&mut self, snap: &Snapshot) -> bool {
let account = snap.account.as_deref().unwrap_or(MAIN_ACCOUNT);
Expand Down
2 changes: 1 addition & 1 deletion src/app/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn tidy_leftovers() {
datadir::prune(attached, 7 * 86_400);
datadir::prune(mcp_configs, 7 * 86_400);
datadir::prune(crate::claude::trim::settings_dir(), 7 * 86_400);
// Titles are copied into the store on the next tick, so an old file is only a duplicate.
// Nothing writes titles any more; the old files go.
datadir::prune(titles, 7 * 86_400);
datadir::prune(usage::snapshot_dir(), 30 * 86_400);
datadir::prune(usage::ctl_dir(), 7 * 86_400);
Expand Down
3 changes: 0 additions & 3 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,6 @@ pub struct Live {
pub view: TerminalView,
/// The session name Claude Code was last given (`--name` or `/rename`), so a changed title is sent once.
pub claude_name: Option<String>,
/// When Claude last called the title tool. A later call (e.g. after `/clear`, which starts a nameless
/// Claude session) clears `claude_name` so the title is sent again.
pub title_stamp: Option<std::time::SystemTime>,
/// The account this process was started under; a session on another account than the active one can be handed off.
pub account: Id,
}
Expand Down
1 change: 0 additions & 1 deletion src/app/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ impl Workspace {
id: id.clone(),
view,
claude_name,
title_stamp: None,
account,
});
self.activate(&id);
Expand Down
110 changes: 99 additions & 11 deletions src/claude/config_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,41 @@ use serde_json::{Map, Value};

/// Files inside each account's config folder that every account shares.
const FILES: &[&str] = &["settings.json", "CLAUDE.md", "keybindings.json"];
/// Top-level keys of an account's `.claude.json` that every account shares: the user's MCP servers.
const SHARED_KEYS: &[&str] = &["mcpServers"];
/// Top-level keys of an account's `.claude.json` that every account shares: the user's MCP servers, and the
/// preferences `/config` saves there. The preferences are Claude Code's own list of global config keys (2.1.325),
/// without the sign-in, install details, counters, notices and caches it also holds, and without the ones tied to a
/// login: uploading sessions, remote control at startup, phone push and Claude in Chrome. Claude Code writes only the
/// ones changed from their defaults, so most are usually absent.
const SHARED_KEYS: &[&str] = &[
"mcpServers",
"theme",
"verbose",
"editorMode",
"preferredNotifChannel",
"autoCompactEnabled",
"autoScrollEnabled",
"showTurnDuration",
"showMessageTimestamps",
"diffTool",
"todoFeatureEnabled",
"showExpandedTodos",
"briefTranscript",
"messageIdleNotifThresholdMs",
"autoConnectIde",
"autoInstallIdeExtension",
"fileCheckpointingEnabled",
"terminalProgressBarEnabled",
"showStatusInTerminalTab",
"taskCompleteNotifEnabled",
"inputNeededNotifEnabled",
"respectGitignore",
"copyFullResponse",
"copyOnSelect",
"leftArrowOpensAgents",
"defaultToAgentsView",
"prStatusFooterEnabled",
"teammateMode",
];
/// One project's trust in `.claude.json`: once any account trusts a folder, every account does.
const TRUST_KEY: &str = "hasTrustDialogAccepted";

Expand Down Expand Up @@ -174,8 +207,9 @@ fn sync_claude_json(accounts: &[Account], state: &mut State) -> io::Result<()> {
})
.collect();
let mut dirty = vec![false; accounts.len()];
let mut incomplete = false;
// Each key is agreed on alone, once every account holds it: a busy account behind on one key holds back only that.
let mut agreed_now: Vec<(String, u64, Vec<usize>)> = vec![];
let mut needs_write: Vec<Vec<usize>> = vec![];

for key in SHARED_KEYS {
let state_key = format!("json:{key}");
Expand All @@ -197,23 +231,30 @@ fn sync_claude_json(accounts: &[Account], state: &mut State) -> io::Result<()> {
let Some(winner) = pick(&held, state.agreed.get(&state_key).copied()) else { continue };
let source = held[winner].as_ref().expect("the winner holds a value");
let (print, value) = (source.print, source.value.clone());
let mut behind = false;
let mut written_to = vec![];
for (i, file) in files.iter_mut().enumerate() {
let Some((map, _)) = file else { continue };
if map.get(*key) == value.as_ref() {
continue;
}
if accounts[i].busy {
incomplete = true;
behind = true;
continue;
}
match &value {
Some(value) => map.insert((*key).into(), value.clone()),
None => map.remove(*key),
};
dirty[i] = true;
written_to.push(i);
}
if behind {
continue;
}
let holders = if value.is_some() { (0..files.len()).filter(|i| files[*i].is_some()).collect() } else { vec![] };
agreed_now.push((state_key, print, holders));
needs_write.push(written_to);
}

// Trust only grows: a folder any account trusts is trusted everywhere.
Expand All @@ -233,7 +274,6 @@ fn sync_claude_json(accounts: &[Account], state: &mut State) -> io::Result<()> {
continue;
}
if accounts[i].busy {
incomplete = true;
continue;
}
let Some(projects) = map.entry("projects").or_insert_with(|| Value::Object(Map::new())).as_object_mut() else { continue };
Expand All @@ -246,19 +286,21 @@ fn sync_claude_json(accounts: &[Account], state: &mut State) -> io::Result<()> {
}

let mut result = Ok(());
let mut failed = vec![false; accounts.len()];
for (i, file) in files.iter().enumerate() {
let (true, Some((map, _))) = (dirty[i], file) else { continue };
let text = serde_json::to_string_pretty(map).map_err(io::Error::other);
let written = text.and_then(|text| crate::datadir::write_atomic(&accounts[i].claude_json, &text));
incomplete |= written.is_err();
failed[i] = written.is_err();
keep(&mut result, written);
}
if !incomplete {
for (state_key, print, holders) in agreed_now {
state.agreed.insert(state_key.clone(), print);
state.had.retain(|h| !h.starts_with(&format!("{state_key}|")));
state.had.extend(holders.into_iter().map(|i| had_key(&state_key, &accounts[i])));
for ((state_key, print, holders), written_to) in agreed_now.into_iter().zip(needs_write) {
if written_to.iter().any(|i| failed[*i]) {
continue;
}
state.agreed.insert(state_key.clone(), print);
state.had.retain(|h| !h.starts_with(&format!("{state_key}|")));
state.had.extend(holders.into_iter().map(|i| had_key(&state_key, &accounts[i])));
}
result
}
Expand Down Expand Up @@ -384,6 +426,52 @@ mod tests {
assert!(main.get("mcpServers").is_none(), "the removal reached main");
}

#[test]
fn a_config_option_changed_in_one_account_reaches_every_account_and_its_reset_does_too() {
let s = setup(3);
for (a, who) in s.accounts.iter().zip(["main", "alt1", "alt2"]) {
write_at(&a.claude_json, &format!(r#"{{"oauthAccount":{{"email":"{who}"}},"numStartups":1}}"#), 1000);
}
sync(&s.accounts, &s.state).unwrap();
let json = |a: &Account| serde_json::from_str::<Value>(&fs::read_to_string(&a.claude_json).unwrap()).unwrap();

// `/config` in the second alt: the theme and auto-compact.
write_at(&s.accounts[2].claude_json, r#"{"oauthAccount":{"email":"alt2"},"numStartups":9,"theme":"light","autoCompactEnabled":false}"#, 2000);
sync(&s.accounts, &s.state).unwrap();
for (a, who) in s.accounts.iter().zip(["main", "alt1", "alt2"]) {
let j = json(a);
assert_eq!((j["theme"].as_str(), j["autoCompactEnabled"].as_bool()), (Some("light"), Some(false)), "{who}");
assert_eq!(j["oauthAccount"]["email"], who, "the login stays the account's own");
}
assert_eq!(json(&s.accounts[0])["numStartups"], 1, "counters are not shared");

// Back to the default in main: Claude Code drops the key, and the others drop it too.
write_at(&s.accounts[0].claude_json, r#"{"oauthAccount":{"email":"main"},"numStartups":1,"autoCompactEnabled":false}"#, 3000);
sync(&s.accounts, &s.state).unwrap();
assert!(s.accounts.iter().all(|a| json(a).get("theme").is_none()));
assert!(s.accounts.iter().all(|a| json(a)["autoCompactEnabled"] == false), "the other option stays");
}

#[test]
fn an_account_busy_with_another_difference_does_not_hold_back_an_option() {
let mut s = setup(3);
write_at(&s.accounts[0].claude_json, r#"{"projects":{"/p":{"hasTrustDialogAccepted":true}}}"#, 1000);
write_at(&s.accounts[1].claude_json, r#"{"theme":"light"}"#, 1000);
write_at(&s.accounts[2].claude_json, r#"{"theme":"light"}"#, 2000);
s.accounts[1].busy = true; // it lacks the trust and takes nothing while busy, but agrees on the theme
sync(&s.accounts, &s.state).unwrap();
let json = |a: &Account| serde_json::from_str::<Value>(&fs::read_to_string(&a.claude_json).unwrap()).unwrap();
assert_eq!(json(&s.accounts[0])["theme"], "light");

// Back to the default in main while the alt is still busy: the reset spreads, it is not filled back in.
let mut main = json(&s.accounts[0]);
main.as_object_mut().unwrap().remove("theme");
write_at(&s.accounts[0].claude_json, &main.to_string(), 3000);
sync(&s.accounts, &s.state).unwrap();
assert!(json(&s.accounts[0]).get("theme").is_none());
assert!(json(&s.accounts[2]).get("theme").is_none());
}

#[test]
fn a_busy_accounts_claude_json_is_not_written_and_catches_up_when_idle() {
let mut s = setup(2);
Expand Down
Loading
Loading