Problem
Currently all Discord threads share the same working_dir (from config). When multiple threads run concurrently, their coding agents operate in the same directory, which can cause file conflicts and unexpected behavior.
Proposed Solution
Create a unique subdirectory for each thread under working_dir:
<working_dir>/sessions/<thread_id>/
Each AcpConnection spawns into its own isolated directory, so parallel sessions never interfere with each other.
Implementation
Minimal change in pool.rs — create the per-thread directory before spawning the agent and pass it as the cwd:
// In get_or_create(), before spawning:
let thread_dir: PathBuf = [&self.config.working_dir, "sessions", thread_id].iter().collect();
tokio::fs::create_dir_all(&thread_dir).await?;
let thread_dir_str = thread_dir.to_string_lossy().to_string();
let mut conn = AcpConnection::spawn(
&self.config.command,
&self.config.args,
&thread_dir_str, // per-thread dir instead of shared working_dir
&self.config.env,
).await?;
conn.initialize().await?;
conn.session_new(&thread_dir_str).await?;
Additional Considerations
- Cleanup: Should idle session directories be cleaned up when
cleanup_idle removes stale connections?
- Git worktree: An alternative approach could use
git worktree for repo-based workflows, but simple directory isolation covers the general case.
- Config opt-in: Could add a config flag like
isolate_sessions = true if backward compatibility is a concern, though isolated dirs seem like a safer default.
Happy to submit a PR if this direction looks good. We've already tested this locally and it works well with claude-agent-acp.
Problem
Currently all Discord threads share the same
working_dir(from config). When multiple threads run concurrently, their coding agents operate in the same directory, which can cause file conflicts and unexpected behavior.Proposed Solution
Create a unique subdirectory for each thread under
working_dir:Each
AcpConnectionspawns into its own isolated directory, so parallel sessions never interfere with each other.Implementation
Minimal change in
pool.rs— create the per-thread directory before spawning the agent and pass it as thecwd:Additional Considerations
cleanup_idleremoves stale connections?git worktreefor repo-based workflows, but simple directory isolation covers the general case.isolate_sessions = trueif backward compatibility is a concern, though isolated dirs seem like a safer default.Happy to submit a PR if this direction looks good. We've already tested this locally and it works well with
claude-agent-acp.