Reason Network: your team's coding agents, talking to each other. The engine behind `reason network`.
Rust agent-to-agentai-agentsclaude-codecodexcoding-agentscursorgrokirohmcpmcp-servermulti-agentpeer-to-peerreason
Wire up Grok CLI
watarus1e2db305a439
diff --git a/DESIGN.md b/DESIGN.mdindex 73b4f8c..135614b 100644--- a/DESIGN.md+++ b/DESIGN.md@@ -169,6 +169,7 @@ The hard part. Each session advertises a **delivery tier** so senders know when| Cursor | turn | `postToolUse` `additional_context`; `stop` `followup_message`. Idle: background `reason-network wait`. || Gemini CLI | turn | `AfterTool` `additionalContext`; `AfterAgent` block. Idle: experimental background-shell inject. || Copilot CLI | turn | `postToolUse` `additionalContext`; `agentStop` block; `notification` hook. |+| Grok CLI | turn | `PostToolUse` `additionalContext`; `Stop` block. Prompt-submit output is dropped. || any MCP client | pull | Tools + unread notice on every tool result + `check_inbox(wait_secs)` long-poll. |MCP notifications are not a delivery path: no client passes them to the model (checked Oct 2026).diff --git a/README.md b/README.mdindex 7224e8a..2ec2c26 100644--- a/README.md+++ b/README.md@@ -8,7 +8,7 @@ One small daemon per computer. Peer to peer, no server. Messages land straight iEvery coding agent session on every teammate's computer shows up (who, which repo and branch, busy or idle, what it'sdoing right now), and any of them can message the right one: Claude Code, Codex, Cursor, Gemini CLI, Copilot CLI,-opencode, pi and Reason.+Grok CLI, opencode, pi and Reason.## Get starteddiff --git a/src/agent.rs b/src/agent.rsindex a2fc1de..f0a94a1 100644--- a/src/agent.rs+++ b/src/agent.rs@@ -20,6 +20,8 @@ pub fn detect_env() -> Option<&'static str> {Some(CLAUDE_CODE)} else if has("CODEX_THREAD_ID") || has("CODEX_SESSION_ID") {Some("codex")+ } else if has("GROK_SESSION_ID") || has("GROK_WORKSPACE_ROOT") {+ Some("grok")} else if has("GEMINI_CLI") {Some("gemini")} else if has("CURSOR_AGENT") {@@ -46,6 +48,8 @@ pub fn from_client_name(name: &str) -> Option<&'static str> {"cursor"} else if has("gemini") {"gemini"+ } else if has("grok") {+ "grok"} else if has("opencode") {"opencode"} else if has("copilot") {@@ -82,6 +86,7 @@ pub fn env_session_id(agent: &str) -> Option<String> {"copilot" => "COPILOT_AGENT_SESSION_ID","gemini" => "GEMINI_SESSION_ID","codex" => "CODEX_THREAD_ID",+ "grok" => "GROK_SESSION_ID","opencode" => "OPENCODE_SESSION_ID",_ => return None,};@@ -242,6 +247,8 @@ mod tests {assert_eq!(from_client_name("codex-mcp-client"), Some("codex"));assert_eq!(from_client_name("cursor-vscode"), Some("cursor"));assert_eq!(from_client_name("gemini-cli-mcp-client"), Some("gemini"));+ // grok names its client after the server, so this one also contains "reason".+ assert_eq!(from_client_name("grok-shell-reason-network"), Some("grok"));assert_eq!(from_client_name("claude-ai"), Some("claude-desktop"));assert_eq!(from_client_name("example-client"), None);}diff --git a/src/hook.rs b/src/hook.rsindex 0f45851..de8794c 100644--- a/src/hook.rs+++ b/src/hook.rs@@ -72,8 +72,9 @@ async fn handle(("doing", _) => "doing",_ => return None,};- // Prompt-submit hooks in Cursor and Copilot can't add context, and opencode's status call shows nothing.- let mail = !matches!((agent, event), ("cursor" | "copilot", "user-prompt-submit") | (_, "status" | "doing"));+ // Prompt-submit hooks in Cursor, Copilot and grok can't add context, and opencode's status call shows nothing.+ let mail =+ !matches!((agent, event), ("cursor" | "copilot" | "grok", "user-prompt-submit") | (_, "status" | "doing"));let key = format!("{agent}:{session_id}");let req = Request::Hook(HookCall {@@ -111,10 +112,12 @@ fn format_for(agent: &str, event: &str, ev: &str, text: &str) -> String {("codex", "start") => specific("SessionStart"),("codex", "prompt") => specific("UserPromptSubmit"),("codex", "tool") => specific("PostToolUse"),+ ("grok", "start") => specific("SessionStart"),+ ("grok", "tool") => specific("PostToolUse"),("gemini", "start") => specific("SessionStart"),("gemini", "prompt") => specific("BeforeAgent"),("gemini", "tool") => specific("AfterTool"),- ("codex" | "gemini" | "copilot", "stop") => block(),+ ("codex" | "gemini" | "copilot" | "grok", "stop") => block(),("cursor", "stop") => json!({ "followup_message": text }),("cursor", _) => json!({ "additional_context": text }),("copilot", _) => json!({ "additionalContext": text }),@@ -149,6 +152,9 @@ mod tests {assert_eq!(format_for("cursor", "post-tool-use", "tool", "hi"), r#"{"additional_context":"hi"}"#);assert_eq!(format_for("copilot", "session-start", "start", "hi"), r#"{"additionalContext":"hi"}"#);assert!(format_for("gemini", "user-prompt-submit", "prompt", "hi").contains("BeforeAgent"));+ assert!(format_for("grok", "post-tool-use", "tool", "hi").contains("\"PostToolUse\""));+ assert!(format_for("grok", "session-start", "start", "hi").contains("\"SessionStart\""));+ assert_eq!(format_for("grok", "stop", "stop", "hi"), r#"{"decision":"block","reason":"hi"}"#);assert_eq!(format_for("opencode", "poll", "stop", "hi"), "hi");}}diff --git a/src/setup.rs b/src/setup.rsindex 48dea8f..2eac1f2 100644--- a/src/setup.rs+++ b/src/setup.rs@@ -351,6 +351,81 @@ fn codex(exe: &Path, remove: bool, dry: bool) -> Result<Option<Report>> {Ok(Some(r))}+// ---- Grok CLI ----++fn grok_home() -> PathBuf {+ std::env::var_os("GROK_HOME").map(PathBuf::from).unwrap_or_else(|| home().join(".grok"))+}++/// grok reads the MCP server from `config.toml` and Claude-Code-style hook groups from `hooks/*.json` (global hook+/// files are always trusted, so no prompt).+fn grok(exe: &Path, remove: bool, dry: bool) -> Result<Option<Report>> {+ let dir = grok_home();+ if agent::find_bin("grok").is_none() && !dir.exists() {+ return Ok(None);+ }+ let mut r = Report { agent: "Grok CLI", lines: Vec::new(), notes: Vec::new() };++ let cfg_path = dir.join("config.toml");+ let text = std::fs::read_to_string(&cfg_path).unwrap_or_default();+ let mut doc: toml_edit::DocumentMut = text.parse().with_context(|| format!("parsing {}", cfg_path.display()))?;+ if remove {+ if let Some(servers) = doc.get_mut("mcp_servers").and_then(|t| t.as_table_like_mut()) {+ servers.remove(AGENT_NAME);+ }+ } else {+ let servers = doc.entry("mcp_servers").or_insert(toml_edit::table());+ if let Some(t) = servers.as_table_mut() {+ t.set_implicit(true);+ }+ let mut t = toml_edit::Table::new();+ t["command"] = toml_edit::value(exe.display().to_string());+ t["args"] = toml_edit::value(toml_edit::Array::from_iter(["mcp"]));+ let mut env = toml_edit::InlineTable::new();+ env.insert("REASON_NETWORK_AGENT", "grok".into());+ if let Ok(h) = crate::paths::env_var("HOME") {+ env.insert("REASON_NETWORK_HOME", h.into());+ }+ t["env"] = toml_edit::value(env);+ t["enabled"] = toml_edit::value(true);+ // Room for check_inbox(wait_secs) long-polls.+ t["tool_timeout_sec"] = toml_edit::value(660);+ servers[AGENT_NAME] = toml_edit::Item::Table(t);+ }+ r.lines.push(changed(&cfg_path, write_file(&cfg_path, &doc.to_string(), dry)?));++ let hooks_path = dir.join(format!("hooks/{AGENT_NAME}.json"));+ let mut v = read_json(&hooks_path)?;+ // Stop and PostToolUse default to a 10 minute timeout in grok; the others to 5 seconds.+ let group = |event: &str, matcher: bool, timeout: u64| {+ let mut g = json!({ "hooks": [{ "type": "command", "command": shell_cmd(exe, &format!("hook grok {event}")), "timeout": timeout }] });+ if matcher {+ g["matcher"] = json!("*");+ }+ g+ };+ let groups = vec![+ ("SessionStart", group("session-start", false, 10)),+ ("UserPromptSubmit", group("user-prompt-submit", false, 10)),+ ("PostToolUse", group("post-tool-use", true, 10)),+ ("Stop", group("stop", false, 10)),+ ("SessionEnd", group("session-end", false, 3)),+ ];+ merge_hook_groups(obj(obj(&mut v)?.entry("hooks").or_insert_with(|| json!({})))?, "grok", groups, remove);+ if remove && hollow(&v) {+ if hooks_path.exists() {+ if !dry {+ std::fs::remove_file(&hooks_path)?;+ }+ r.lines.push(format!("removed {}", crate::util::tilde(&hooks_path.display().to_string())));+ }+ } else {+ let did = write_json(&hooks_path, &v, dry)?;+ r.lines.push(changed(&hooks_path, did));+ }+ Ok(Some(r))+}+// ---- Cursor ----fn cursor(exe: &Path, remove: bool, dry: bool) -> Result<Option<Report>> {@@ -936,7 +1011,7 @@ fn me(exe: &Path) -> String {s[1..s.len() - 1].to_string()}-const AGENTS: [Agent; 8] = [+const AGENTS: [Agent; 9] = [Agent {id: "claude",name: "Claude Code",@@ -965,6 +1040,17 @@ const AGENTS: [Agent; 8] = [},apply: codex,},+ Agent {+ id: "grok",+ name: "Grok CLI",+ hint: "at its next step or end of turn",+ installed: || agent::find_bin("grok").is_some() || grok_home().exists(),+ wired: |exe| {+ has(grok_home().join("config.toml"), &exe.display().to_string())+ && has(grok_home().join(format!("hooks/{AGENT_NAME}.json")), "hook grok")+ },+ apply: grok,+ },Agent {id: "cursor",name: "Cursor",@@ -1119,7 +1205,7 @@ pub async fn run(dry: bool, remove: bool, no_service: bool) -> Result<()> {println!("{verb} ({}):", crate::util::tilde(&exe.display().to_string()));if found.is_empty() && !remove {println!(- " no supported agents found (Claude Code, Codex, Cursor, Gemini CLI, Copilot CLI, opencode, pi, Reason)"+ " no supported agents found (Claude Code, Codex, Grok CLI, Cursor, Gemini CLI, Copilot CLI, opencode, pi, Reason)");}let ids: Vec<&str> = found.iter().map(|f| f.id).collect();diff --git a/src/wizard.rs b/src/wizard.rsindex 4eb8611..3bacf09 100644--- a/src/wizard.rs+++ b/src/wizard.rs@@ -189,7 +189,7 @@ pub async fn agents_and_preferences() -> Result<()> {let found = setup::detect(&exe);let chosen: Vec<&str> = if found.is_empty() {log::warning(format!(- "No coding agents found here (Claude Code, Codex, Cursor, Gemini CLI, Copilot CLI, opencode, pi, Reason). Install one, then run `{CLI} setup`."+ "No coding agents found here (Claude Code, Codex, Grok CLI, Cursor, Gemini CLI, Copilot CLI, opencode, pi, Reason). Install one, then run `{CLI} setup`."))?;Vec::new()} else {