@@ -112,9 +112,16 @@ func New(
112112 initialSession * string ,
113113) (* App , error ) {
114114 util .RootPath = project .Worktree
115- util .CwdPath , _ = os .Getwd ()
115+ // Use OPENCODE_ORIGINAL_CWD from environment if available (set by wrapper script)
116+ if originalCwd := os .Getenv ("OPENCODE_ORIGINAL_CWD" ); originalCwd != "" {
117+ util .CwdPath = originalCwd
118+ } else {
119+ util .CwdPath , _ = os .Getwd ()
120+ }
116121
117- configInfo , err := httpClient .Config .Get (ctx , opencode.ConfigGetParams {})
122+ configInfo , err := httpClient .Config .Get (ctx , opencode.ConfigGetParams {
123+ Directory : opencode .F (project .Worktree ),
124+ })
118125 if err != nil {
119126 return nil , err
120127 }
@@ -189,7 +196,9 @@ func New(
189196
190197 slog .Debug ("Loaded config" , "config" , configInfo )
191198
192- customCommands , err := httpClient .Command .List (ctx , opencode.CommandListParams {})
199+ customCommands , err := httpClient .Command .List (ctx , opencode.CommandListParams {
200+ Directory : opencode .F (project .Worktree ),
201+ })
193202 if err != nil {
194203 return nil , err
195204 }
@@ -461,7 +470,9 @@ func findProviderByID(providers []opencode.Provider, providerID string) *opencod
461470}
462471
463472func (a * App ) InitializeProvider () tea.Cmd {
464- providersResponse , err := a .Client .App .Providers (context .Background (), opencode.AppProvidersParams {})
473+ providersResponse , err := a .Client .App .Providers (context .Background (), opencode.AppProvidersParams {
474+ Directory : opencode .F (a .Project .Worktree ),
475+ })
465476 if err != nil {
466477 slog .Error ("Failed to list providers" , "error" , err )
467478 // TODO: notify user
@@ -717,6 +728,7 @@ func (a *App) InitializeProject(ctx context.Context) tea.Cmd {
717728
718729 go func () {
719730 _ , err := a .Client .Session .Init (ctx , a .Session .ID , opencode.SessionInitParams {
731+ Directory : opencode .F (a .Project .Worktree ),
720732 MessageID : opencode .F (id .Ascending (id .Message )),
721733 ProviderID : opencode .F (a .Provider .ID ),
722734 ModelID : opencode .F (a .Model .ID ),
@@ -747,6 +759,7 @@ func (a *App) CompactSession(ctx context.Context) tea.Cmd {
747759 compactCtx ,
748760 a .Session .ID ,
749761 opencode.SessionSummarizeParams {
762+ Directory : opencode .F (a .Project .Worktree ),
750763 ProviderID : opencode .F (a .Provider .ID ),
751764 ModelID : opencode .F (a .Model .ID ),
752765 },
@@ -773,7 +786,9 @@ func (a *App) MarkProjectInitialized(ctx context.Context) error {
773786}
774787
775788func (a * App ) CreateSession (ctx context.Context ) (* opencode.Session , error ) {
776- session , err := a .Client .Session .New (ctx , opencode.SessionNewParams {})
789+ session , err := a .Client .Session .New (ctx , opencode.SessionNewParams {
790+ Directory : opencode .F (a .Project .Worktree ),
791+ })
777792 if err != nil {
778793 return nil , err
779794 }
@@ -798,6 +813,7 @@ func (a *App) SendPrompt(ctx context.Context, prompt Prompt) (*App, tea.Cmd) {
798813
799814 cmds = append (cmds , func () tea.Msg {
800815 _ , err := a .Client .Session .Prompt (ctx , a .Session .ID , opencode.SessionPromptParams {
816+ Directory : opencode .F (a .Project .Worktree ),
801817 Model : opencode .F (opencode.SessionPromptParamsModel {
802818 ProviderID : opencode .F (a .Provider .ID ),
803819 ModelID : opencode .F (a .Model .ID ),
@@ -832,6 +848,7 @@ func (a *App) SendCommand(ctx context.Context, command string, args string) (*Ap
832848
833849 cmds = append (cmds , func () tea.Msg {
834850 params := opencode.SessionCommandParams {
851+ Directory : opencode .F (a .Project .Worktree ),
835852 Command : opencode .F (command ),
836853 Arguments : opencode .F (args ),
837854 Agent : opencode .F (a .Agents [a .AgentIndex ].Name ),
@@ -872,8 +889,9 @@ func (a *App) SendShell(ctx context.Context, command string) (*App, tea.Cmd) {
872889 context .Background (),
873890 a .Session .ID ,
874891 opencode.SessionShellParams {
875- Agent : opencode .F (a .Agent ().Name ),
876- Command : opencode .F (command ),
892+ Directory : opencode .F (a .Project .Worktree ),
893+ Agent : opencode .F (a .Agent ().Name ),
894+ Command : opencode .F (command ),
877895 },
878896 )
879897 if err != nil {
@@ -895,7 +913,9 @@ func (a *App) Cancel(ctx context.Context, sessionID string) error {
895913 a .compactCancel = nil
896914 }
897915
898- _ , err := a .Client .Session .Abort (ctx , sessionID , opencode.SessionAbortParams {})
916+ _ , err := a .Client .Session .Abort (ctx , sessionID , opencode.SessionAbortParams {
917+ Directory : opencode .F (a .Project .Worktree ),
918+ })
899919 if err != nil {
900920 slog .Error ("Failed to cancel session" , "error" , err )
901921 return err
@@ -904,7 +924,9 @@ func (a *App) Cancel(ctx context.Context, sessionID string) error {
904924}
905925
906926func (a * App ) ListSessions (ctx context.Context ) ([]opencode.Session , error ) {
907- response , err := a .Client .Session .List (ctx , opencode.SessionListParams {})
927+ response , err := a .Client .Session .List (ctx , opencode.SessionListParams {
928+ Directory : opencode .F (a .Project .Worktree ),
929+ })
908930 if err != nil {
909931 return nil , err
910932 }
@@ -916,7 +938,9 @@ func (a *App) ListSessions(ctx context.Context) ([]opencode.Session, error) {
916938}
917939
918940func (a * App ) DeleteSession (ctx context.Context , sessionID string ) error {
919- _ , err := a .Client .Session .Delete (ctx , sessionID , opencode.SessionDeleteParams {})
941+ _ , err := a .Client .Session .Delete (ctx , sessionID , opencode.SessionDeleteParams {
942+ Directory : opencode .F (a .Project .Worktree ),
943+ })
920944 if err != nil {
921945 slog .Error ("Failed to delete session" , "error" , err )
922946 return err
@@ -936,7 +960,9 @@ func (a *App) UpdateSession(ctx context.Context, sessionID string, title string)
936960}
937961
938962func (a * App ) ListMessages (ctx context.Context , sessionId string ) ([]Message , error ) {
939- response , err := a .Client .Session .Messages (ctx , sessionId , opencode.SessionMessagesParams {})
963+ response , err := a .Client .Session .Messages (ctx , sessionId , opencode.SessionMessagesParams {
964+ Directory : opencode .F (a .Project .Worktree ),
965+ })
940966 if err != nil {
941967 return nil , err
942968 }
@@ -958,7 +984,9 @@ func (a *App) ListMessages(ctx context.Context, sessionId string) ([]Message, er
958984}
959985
960986func (a * App ) ListProviders (ctx context.Context ) ([]opencode.Provider , error ) {
961- response , err := a .Client .App .Providers (ctx , opencode.AppProvidersParams {})
987+ response , err := a .Client .App .Providers (ctx , opencode.AppProvidersParams {
988+ Directory : opencode .F (a .Project .Worktree ),
989+ })
962990 if err != nil {
963991 return nil , err
964992 }
0 commit comments