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 [GPUI](https://gpui.rs), t

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. Settings has a Check setup button to open it again. A sidebar lists your projects and sessions. 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, 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. Its 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, 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.

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
1 change: 1 addition & 0 deletions src/app/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ impl Workspace {
let update = this.update_in(cx, |ws, window, cx| {
ws.serve_requests(requests, window, cx);
ws.finish_handoffs(window, cx);
ws.run_pending_switches(&statuses, window, cx);
ws.check_open_files(window, cx);
ws.update_activity(window, cx, &statuses)
});
Expand Down
89 changes: 78 additions & 11 deletions src/app/cross.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ pub struct PendingStart {
shown: bool,
}

/// A worktree switch the user approved, waiting for the turn in which the session asked for it to end: the switch restarts
/// the process that made the call.
pub struct PendingSwitch {
id: Id,
folder: PathBuf,
base: crate::git::worktree::Base,
/// Unix seconds when the user approved it.
approved: i64,
}

/// How long an approved switch waits for the turn to end before it is given up.
const SWITCH_PATIENCE_SECS: i64 = 300;

/// Longest part of the first message the dialog quotes.
const SHOWN_PROMPT: usize = 600;

Expand All @@ -28,6 +41,13 @@ fn start_question(asker: &str, folder: &std::path::Path, prompt: &str) -> String
format!("“{asker}” wants to open a new Claude Code session in {} with this first message:\n\n{quoted}{more}", folder.to_string_lossy())
}

/// What the dialog says about the worktree a session wants to move into.
fn switch_question(asker: &str, folder: &std::path::Path, new: bool) -> String {
let name = folder.file_name().map_or_else(|| folder.to_string_lossy().into_owned(), |n| n.to_string_lossy().into_owned());
let what = if new { format!("a new worktree, {name}") } else { format!("the worktree {name}") };
format!("“{asker}” wants to switch to {what}. Its process restarts once its turn ends, and the conversation continues there.")
}

/// `2026-10-22 09:10 UTC` for a Unix time (days since 1970 turned into a calendar date, no time crate needed).
fn utc(ts: i64) -> String {
let (days, secs) = (ts.div_euclid(86_400), ts.rem_euclid(86_400));
Expand Down Expand Up @@ -124,14 +144,13 @@ impl Workspace {
let requester = p.req.from.split_once(':').map_or(p.req.from.as_str(), |(_, id)| id);
let asker = self.store.session(requester).map_or_else(|| "A session".to_string(), |s| s.display_title().to_string());
let folder = PathBuf::from(p.req.args["folder"].as_str().unwrap_or_default());
let prompt = p.req.args["prompt"].as_str().unwrap_or_default().trim().to_string();
self.modal = Some(Modal::Confirm {
title: "Start a Claude Code session?".into(),
body: start_question(&asker, &folder, &prompt),
confirm: "Start session".into(),
danger: false,
act: Act::ConfirmStartSession(p.req.id.clone()),
});
let (title, body, confirm) = if p.req.tool == "switch_worktree" {
("Switch worktree?", switch_question(&asker, &folder, p.req.args["new"].as_bool().unwrap_or(false)), "Switch")
} else {
let prompt = p.req.args["prompt"].as_str().unwrap_or_default().trim().to_string();
("Start a Claude Code session?", start_question(&asker, &folder, &prompt), "Start session")
};
self.modal = Some(Modal::Confirm { title: title.into(), body, confirm: confirm.into(), danger: false, act: Act::ConfirmStartSession(p.req.id.clone()) });
window.focus(&self.modal_focus, cx);
cx.notify();
}
Expand All @@ -146,8 +165,11 @@ impl Workspace {
answer(&req, ok, result.unwrap_or_else(|e| e));
}

/// Check what starting a session needs and resolve the folder into `req.args["folder"]`.
/// Check what the request needs. A new session's folder, or the worktree to switch to, is resolved into `req.args["folder"]`.
fn prepare(&self, req: &mut Request) -> Result<(), String> {
if req.tool == "switch_worktree" {
return self.prepare_switch(req);
}
if req.tool != "start_code_session" {
return Ok(());
}
Expand All @@ -162,6 +184,42 @@ impl Workspace {
Ok(())
}

fn prepare_switch(&self, req: &mut Request) -> Result<(), String> {
let id = req.from.split_once(':').map_or(req.from.as_str(), |(_, id)| id);
let rec = self.store.session(id).ok_or("Claudiu doesn't know this session.")?;
let git = rec.project_id.as_ref().and_then(|p| self.store.project(p)).and_then(|p| p.git.as_ref()).ok_or("This session's project is not a git repository.")?;
let wanted = req.args["worktree"].as_str().unwrap_or_default();
let listed = crate::git::worktree::folders(git).into_iter().skip(1).filter_map(|f| f.file_name().map(|n| n.to_string_lossy().into_owned())).collect::<Vec<_>>();
let target = crate::git::worktree::resolve(git, &rec.cwd, wanted).map_err(|why| format!("{why} Worktrees: main{}{}.", if listed.is_empty() { "" } else { ", " }, listed.join(", ")))?;
req.args["folder"] = target.folder.to_string_lossy().into_owned().into();
req.args["new"] = target.new.into();
Ok(())
}

/// Start the approved switches whose session has ended its turn. Looks at Claude Code's own status, as a switch from
/// the menu does, so the call that asked is finished and answered first.
pub(super) fn run_pending_switches(&mut self, statuses: &std::collections::HashMap<String, String>, window: &mut Window, cx: &mut Context<Self>) {
let now = crate::store::now();
let pending = std::mem::take(&mut self.pending_switches);
for p in pending {
let claude_id = self.store.session(&p.id).and_then(|r| r.claude_id());
// Without a registry entry (older Claude Code) the terminal's own activity decides, as in `switch::inspect`.
let idle = match claude_id.and_then(|c| statuses.get(c)) {
Some(status) => status == "idle",
None => self.live_view(&p.id).is_some_and(|v| !v.read(cx).is_working()),
};
if now - p.approved > SWITCH_PATIENCE_SECS {
self.toast("The worktree switch was dropped: the session's turn did not end.", true, cx);
} else if !self.is_running(&p.id, cx) {
// Closed in the meantime: nothing to move.
} else if idle {
self.switch_session(p.id, p.folder, p.base, false, window, cx);
} else {
self.pending_switches.push(p);
}
}
}

/// Do what was asked.
pub(super) fn run_request(&mut self, req: &Request, window: &mut Window, cx: &mut Context<Self>) -> Result<String, String> {
let id = req.args["id"].as_str().unwrap_or_default().to_string();
Expand Down Expand Up @@ -241,6 +299,13 @@ impl Workspace {
None => Err("The session could not be started (is the `claude` CLI installed?).".into()),
}
}
"switch_worktree" => {
let folder = folder.ok_or("No folder.")?;
let base = if req.args["base"].as_str() == Some("current") { crate::git::worktree::Base::Current } else { crate::git::worktree::Base::Main };
let name = folder.file_name().map_or_else(|| "the main checkout".into(), |n| n.to_string_lossy().into_owned());
self.pending_switches.push(PendingSwitch { id: requester_id.to_string(), folder, base, approved: crate::store::now() });
Ok(format!("Approved. Claudiu switches this session to {name} as soon as your turn ends, so end your turn now: reply in one line and make no more tool calls. The user's next message continues the same conversation there."))
}
other => Err(format!("unknown tool {other}")),
}
}
Expand All @@ -258,9 +323,10 @@ mod tests {
}
}

/// A new session with a first message of its own is a prompt the user did not write.
/// A new session with a first message of its own is a prompt the user did not write, and a worktree switch restarts the
/// session: both wait for the user's yes.
fn wants_confirmation(req: &Request) -> bool {
req.tool == "start_code_session" && req.args["prompt"].as_str().is_some_and(|p| !p.trim().is_empty())
req.tool == "switch_worktree" || (req.tool == "start_code_session" && req.args["prompt"].as_str().is_some_and(|p| !p.trim().is_empty()))
}

#[cfg(test)]
Expand All @@ -278,6 +344,7 @@ mod start_tests {
assert!(!wants_confirmation(&request("start_code_session", json!({"folder": "/p"}))), "no prompt, nothing to approve");
assert!(!wants_confirmation(&request("start_code_session", json!({"folder": "/p", "prompt": " "}))));
assert!(!wants_confirmation(&request("read_code_session", json!({"prompt": "x"}))));
assert!(wants_confirmation(&request("switch_worktree", json!({"worktree": "fix"}))), "a switch always asks");
}

#[test]
Expand Down
8 changes: 6 additions & 2 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub enum Act {
},
/// `SwitchWorktree`, after the user agreed to leave uncommitted files behind.
ConfirmSwitch {
id: Id,
folder: PathBuf,
base: Base,
},
Expand Down Expand Up @@ -495,6 +496,8 @@ pub struct Workspace {
pub config_sync: config_sync::Runner,
/// Sessions asked to open another with a first message; each waits for the user's yes (`cross.rs`).
pub pending_starts: Vec<cross::PendingStart>,
/// Worktree switches the user approved that a session asked for; each waits for the session's turn to end (`cross.rs`).
pub pending_switches: Vec<cross::PendingSwitch>,
pub drag_pos: Option<gpui::Point<gpui::Pixels>>,
pub update: UpdateState,
pub scanning: bool,
Expand Down Expand Up @@ -596,6 +599,7 @@ impl Workspace {
attached_sync: Default::default(),
config_sync: Default::default(),
pending_starts: vec![],
pending_switches: vec![],
update: UpdateState::default(),
scanning: false,
quitting: false,
Expand Down Expand Up @@ -659,9 +663,9 @@ impl Workspace {
}
}
Act::SwitchWorktree { folder, base } => self.switch_shown(folder, base, false, window, cx),
Act::ConfirmSwitch { folder, base } => {
Act::ConfirmSwitch { id, folder, base } => {
self.modal = None;
self.switch_shown(folder, base, true, window, cx)
self.switch_session(id, folder, base, true, window, cx)
}
Act::RemoveWorktree { main_checkout, folder } => self.ask_remove_worktree(main_checkout, folder, cx),
Act::AskDeleteUnlisted(folder) => self.ask_delete_unlisted(folder, cx),
Expand Down
41 changes: 30 additions & 11 deletions src/app/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,13 @@ impl Workspace {

/// `leading` goes before every other argument: the initial prompt must come ahead of the variadic
/// `--allowedTools` / `--mcp-config` flags, or they would swallow it.
pub(super) fn new_claude_with(&mut self, cwd: PathBuf, mut leading: Vec<String>, by: Starter, window: &mut Window, cx: &mut Context<Self>) {
pub(super) fn new_claude_with(&mut self, cwd: PathBuf, leading: Vec<String>, by: Starter, window: &mut Window, cx: &mut Context<Self>) {
// A new session starts in the main checkout, not in a linked worktree. Fix-with-Claude works where the failure was.
let cwd = if by == Starter::FixGit { cwd } else { self.outside_linked_worktree(cwd) };
let Some(exe) = self.claude_exe.clone() else {
self.show_toast("Could not find the `claude` CLI. Install Claude Code, or set its path in Settings.".into(), true, Some(("Check setup".into(), Act::OpenSetup)), cx);
return;
};
let session_id = new_id();
let record_id = new_id();
let mut spec = claude::new_session_spec(&exe, &cwd, &session_id);
let settings = &self.store.data.settings;
let defaults = claude::defaults::flags(&settings.new_session, settings.trimmed_tools.contains(&claude::trim::Trim::PlanMode), &leading, by);
leading.extend(defaults);
spec.args.splice(0..0, leading);
let chrome = self.store.data.settings.chrome_default;
let spec = self.with_helpers(spec, &session_id, &record_id, chrome, cx);
let Some(spec) = self.fresh_spec(&cwd, &session_id, &record_id, chrome, leading, by, cx) else { return };
let record = SessionRecord {
id: record_id,
kind: SessionKind::Claude,
Expand All @@ -144,6 +135,34 @@ impl Workspace {
self.start(record, spec, true, window, cx);
}

/// `claude --session-id` in `cwd` with the new-session defaults. None, with a toast, when `claude` isn't installed.
#[allow(clippy::too_many_arguments)]
fn fresh_spec(&mut self, cwd: &std::path::Path, session_id: &str, record_id: &str, chrome: bool, mut leading: Vec<String>, by: Starter, cx: &mut Context<Self>) -> Option<SpawnSpec> {
let Some(exe) = self.claude_exe.clone() else {
self.show_toast("Could not find the `claude` CLI. Install Claude Code, or set its path in Settings.".into(), true, Some(("Check setup".into(), Act::OpenSetup)), cx);
return None;
};
let mut spec = claude::new_session_spec(&exe, cwd, session_id);
let settings = &self.store.data.settings;
let defaults = claude::defaults::flags(&settings.new_session, settings.trimmed_tools.contains(&claude::trim::Trim::PlanMode), &leading, by);
leading.extend(defaults);
spec.args.splice(0..0, leading);
Some(self.with_helpers(spec, session_id, record_id, chrome, cx))
}

/// Start the session over under its own id in its folder. For a session with no conversation yet: `--resume` has
/// nothing to find, and nothing is lost. A running view of it is replaced, which ends its process.
pub(super) fn relaunch_empty(&mut self, id: &str, window: &mut Window, cx: &mut Context<Self>) {
let Some(rec) = self.store.session(id).cloned() else { return };
let Some(meta) = rec.claude.clone() else { return };
let cwd = self.resume_cwd(&rec, cx);
let Some(mut spec) = self.fresh_spec(&cwd, &meta.session_id, &rec.id, meta.chrome, vec![], Starter::User, cx) else { return };
if let Some(name) = rec.chosen_title() {
spec.args.extend(["--name".into(), name.into()]);
}
self.start(rec, spec, false, window, cx);
}

/// `cwd`, or the project's main checkout when `cwd` is inside one of its linked worktrees.
fn outside_linked_worktree(&self, cwd: PathBuf) -> PathBuf {
let git = self.store.project_for_cwd(&cwd).and_then(|id| self.store.project(&id)).and_then(|p| p.git.as_ref());
Expand Down
Loading
Loading