Skip to main content

claude_wrapper/command/
agents.rs

1//! The deprecated `agents` subcommand builder.
2//!
3//! [`AgentsCommand`] wraps `claude agents`. It is retained for
4//! back-compat; prefer the read-side [`crate::artifacts`] introspection
5//! for agent definitions and `--agent` / `--agents` on
6//! [`QueryCommand`](crate::QueryCommand) for selecting one.
7
8#[cfg(feature = "async")]
9use crate::Claude;
10use crate::command::ClaudeCommand;
11#[cfg(feature = "async")]
12use crate::error::Result;
13#[cfg(feature = "async")]
14use crate::exec;
15use crate::exec::CommandOutput;
16
17/// **Deprecated.** Wraps `claude agents`, which as of Claude Code
18/// 2.1.143 is an interactive TUI for managing background agent
19/// sessions -- not a way to list user-defined subagent definitions.
20/// Calling `.execute()` non-interactively just emits
21/// `'claude agents' is not available in this environment.` to
22/// stderr and returns empty stdout.
23///
24/// Use [`crate::artifacts::AgentsRoot`] to enumerate / read /
25/// write user-level subagent definitions in `~/.claude/agents/`.
26/// There is no current non-interactive CLI surface for the
27/// background-session manager.
28///
29/// Kept for back-compat; will be removed in a future major release.
30#[deprecated(
31    since = "0.10.0",
32    note = "`claude agents` is now an interactive TUI in Claude Code 2.1.143+ (background-session manager). \
33            For listing/reading/writing user subagents in `~/.claude/agents/`, use \
34            `claude_wrapper::artifacts::AgentsRoot`."
35)]
36#[derive(Debug, Clone, Default)]
37pub struct AgentsCommand {
38    setting_sources: Option<String>,
39}
40
41#[allow(deprecated)]
42impl AgentsCommand {
43    /// Create a new [`AgentsCommand`].
44    #[must_use]
45    pub fn new() -> Self {
46        Self::default()
47    }
48
49    /// Set which setting sources to load (comma-separated: user, project, local).
50    #[must_use]
51    pub fn setting_sources(mut self, sources: impl Into<String>) -> Self {
52        self.setting_sources = Some(sources.into());
53        self
54    }
55}
56
57#[allow(deprecated)]
58impl ClaudeCommand for AgentsCommand {
59    type Output = CommandOutput;
60
61    fn args(&self) -> Vec<String> {
62        let mut args = vec!["agents".to_string()];
63        if let Some(ref sources) = self.setting_sources {
64            args.push("--setting-sources".to_string());
65            args.push(sources.clone());
66        }
67        args
68    }
69
70    #[cfg(feature = "async")]
71    async fn execute(&self, claude: &Claude) -> Result<CommandOutput> {
72        exec::run_claude(claude, self.args()).await
73    }
74}
75
76#[cfg(test)]
77#[allow(deprecated)]
78mod tests {
79    use super::*;
80    use crate::command::ClaudeCommand;
81
82    #[test]
83    fn test_agents_default() {
84        let cmd = AgentsCommand::new();
85        assert_eq!(ClaudeCommand::args(&cmd), vec!["agents"]);
86    }
87
88    #[test]
89    fn test_agents_with_sources() {
90        let cmd = AgentsCommand::new().setting_sources("user,project");
91        assert_eq!(
92            ClaudeCommand::args(&cmd),
93            vec!["agents", "--setting-sources", "user,project"]
94        );
95    }
96}