Skip to main content

lean_ctx_cli/cli/
claude_mod_cmd.rs

1// SPDX-License-Identifier: Apache-2.0
2//! `lean-ctx claude-mod` — install, refresh, inspect or remove the lean-ctx
3//! Claude Code mod (see `hooks::agents::claude_mod`).
4
5use lean_ctx_hooks::hooks::agents::claude_mod::{self, ModStatus};
6
7const USAGE: &str = "\
8lean-ctx claude-mod — the lean-ctx mod for Claude Code (2.1.287+)
9
10USAGE:
11    lean-ctx claude-mod [status]     Show whether the mod is installed and current
12    lean-ctx claude-mod install      Install, or refresh to this instance's version
13    lean-ctx claude-mod uninstall    Remove the mod and its local marketplace
14    lean-ctx claude-mod code-mode [claude args…]
15                                     Start Claude Code in Code Mode with the mod
16
17The mod is two plugins. lean-ctx keeps lean-ctx's core tools in front of
18ToolSearch, shows the cockpit and adds /leanctx with the session's real request
19and token usage. lean-ctx-jobs wakes the model when ctx_shell background jobs
20finish (no sleep/status polling) and shapes native Bash output.
21
22Claude Code's experimental Code Mode refuses plugins that hook tool calls and a
23custom ANTHROPIC_BASE_URL. code-mode starts one session with lean-ctx-jobs off
24and the lean-ctx proxy bypassed (the MCP tools stay); your settings are not
25changed. Both plugins run inside Claude Code with your permissions; their source
26ships in this binary and is installed from a local marketplace — nothing is
27downloaded.";
28
29pub fn cmd_claude_mod(args: &[String]) {
30    match args.first().map(String::as_str) {
31        Some("-h" | "--help" | "help") => println!("{USAGE}"),
32        None | Some("status") => {
33            let status = claude_mod::status();
34            println!("{}: {}", claude_mod::PLUGIN_ID, status.describe());
35            match status {
36                ModStatus::NotInstalled => println!("  install: lean-ctx claude-mod install"),
37                ModStatus::Stale(_) => println!("  refresh: lean-ctx claude-mod install"),
38                _ => {}
39            }
40        }
41        Some("install" | "update") => report(claude_mod::install()),
42        Some("uninstall" | "remove") => report(claude_mod::uninstall()),
43        Some("code-mode") => match claude_mod::launch_code_mode(&args[1..]) {
44            Ok(code) => std::process::exit(code),
45            Err(e) => {
46                eprintln!("lean-ctx claude-mod code-mode: {e}");
47                std::process::exit(1);
48            }
49        },
50        Some(other) => {
51            eprintln!("unknown claude-mod action: {other}\n\n{USAGE}");
52            std::process::exit(2);
53        }
54    }
55}
56
57fn report(result: Result<String, String>) {
58    match result {
59        Ok(msg) => println!("{msg}"),
60        Err(e) => {
61            eprintln!("lean-ctx claude-mod: {e}");
62            std::process::exit(1);
63        }
64    }
65}