Skip to main content

claude_wrapper/command/
agents.rs

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