From c24e4d3d626217d19507c33f689825bff01dfdd5 Mon Sep 17 00:00:00 2001 From: dj-oyu <68707227+dj-oyu@users.noreply.github.com> Date: Tue, 24 Feb 2026 17:56:33 +0900 Subject: [PATCH] fix: SetWorkDir uses session touch_dir for bootstrap file resolution EffectiveWorkspace only returns worktree paths, defaulting to workspace root when no worktree is active. This meant project-scoped bootstrap files (AGENTS.md, IDENTITY.md) were always loaded from workspace root. Now uses the tool-detected project directory (touch_dir) from the session tracker, resolved as absolute path under workspace. Falls back to EffectiveWorkspace for the first turn before any tools have run. Co-Authored-By: Claude Opus 4.6 --- pkg/agent/loop.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 2453c62c2..5f5c759e7 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -811,8 +811,14 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, agent *AgentInstance, opt // 1. Update tool contexts al.updateToolContexts(agent, opts.Channel, opts.ChatID) - // 1a. Set session-specific working directory for bootstrap file lookup - agent.ContextBuilder.SetWorkDir(agent.EffectiveWorkspace(opts.SessionKey)) + // 1a. Set session-specific working directory for bootstrap file lookup. + // Prefer the tool-detected project directory (touch_dir) from the session tracker, + // resolved as an absolute path under workspace. Fall back to worktree or workspace. + if active := al.sessions.ListActive(); len(active) > 0 && active[0].SessionKey == opts.SessionKey && active[0].TouchDir != "" { + agent.ContextBuilder.SetWorkDir(filepath.Join(agent.Workspace, active[0].TouchDir)) + } else { + agent.ContextBuilder.SetWorkDir(agent.EffectiveWorkspace(opts.SessionKey)) + } // 1b. Inject peer session awareness into system prompt projectPath := agent.ContextBuilder.GetPlanWorkDir()