pub fn detect() -> Option<DetectedAgent>Expand description
Detect the AI coding agent present in the current process environment.
Returns None when no known agent is detected.
ยงExample
if let Some(agent) = detect_coding_agent::detect() {
eprintln!("Running inside: {}", agent.name);
}Examples found in repository?
examples/detect.rs (line 9)
8fn main() {
9 let agent = detect_coding_agent::detect();
10
11 match &agent {
12 Some(agent) => {
13 println!("โ
Coding agent detected!");
14 println!(" Name : {}", agent.name);
15 println!(" ID : {}", agent.id);
16 println!(" Kind : {}", agent.kind);
17 }
18 None => {
19 println!("โ No coding agent detected.");
20 println!(
21 " The process does not appear to be running inside a known AI coding agent."
22 );
23 }
24 }
25
26 // Convenience helpers
27 if agent
28 .map(|a| a.is_agent() || a.is_hybrid())
29 .unwrap_or(false)
30 {
31 println!();
32 println!("๐ก Tip: This is an autonomous agent session โ consider offering a");
33 println!(" machine-friendly interface (e.g. via MCP) for better results.");
34 }
35}