plan mode: pass --permission-mode plan to claude while /plan is on

This commit is contained in:
hermes committed 2026-11-14 10:56:23 +00:00
1 parent 18eb31ec8b
commit 531919a23c
3 files changed
+27

No files matched your search

+11
View File
@@ -25,6 +25,14 @@ pub type Spawner = Arc<
+ Sync,
>;
/// hx plan mode is on: claude runs with `--permission-mode plan`, else its `ExitPlanMode` is rejected.
// ponytail: process-wide flag; make it per-provider if two claude providers ever run at once.
static PLAN: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
pub fn set_plan(on: bool) {
PLAN.store(on, std::sync::atomic::Ordering::Relaxed);
}
pub struct ClaudeCli {
spawner: Option<Spawner>,
bin: String,
@@ -187,6 +195,9 @@ impl Provider for ClaudeCli {
cmd.args(["--permission-prompt-tool", "mcp__hx__approve"]);
}
}
if PLAN.load(std::sync::atomic::Ordering::Relaxed) {
cmd.args(["--permission-mode", "plan"]);
}
cmd.args(&self.args)
.arg("--")
.arg(prompt(&req.messages, sid.is_some()))
+1
View File
@@ -390,6 +390,7 @@ impl Allow {
pub fn set_plan(&mut self, on: bool) {
self.plan = on;
hx_ai::claude_cli::set_plan(on);
}
pub fn auto_on(&self) -> bool {
+15
View File
@@ -1709,6 +1709,21 @@ async fn submit(app: &mut App, mut line: String, c: &Ctx<'_>) {
)));
line = r.prompt;
}
// a prompt starting with the word `plan` turns plan mode on
if line
.split_whitespace()
.next()
.is_some_and(|w| w.eq_ignore_ascii_case("plan"))
{
let mut al = app.state.allow.lock().unwrap_or_else(|e| e.into_inner());
if !al.plan_on() {
al.set_plan(true);
drop(al);
app.t.push(Item::Info(
"plan on (prompt starts with `plan`): read-only until the plan is approved".into(),
));
}
}
if app
.state
.allow