Skip to content

Fix restart using wrong default-directory#450

Merged
xenodium merged 1 commit intoxenodium:mainfrom
zackattackz:restart-keep-default-dir
Mar 25, 2026
Merged

Fix restart using wrong default-directory#450
xenodium merged 1 commit intoxenodium:mainfrom
zackattackz:restart-keep-default-dir

Conversation

@zackattackz
Copy link
Contributor

@zackattackz zackattackz commented Mar 24, 2026

agent-shell-restart kills the buffer and calls agent-shell--start directly after.
Since kill-buffer will have the effect of changing the default directory to the "other buffer", agent-shell--start can possibly end up creating the new shell an unexpected project (e.g if the user's last buffer was in a different project, the new shell will be made for this project instead of the expected behavior of being for the same project the original shell was for).

The fix is to bind default-directory around calling agent-shell--start, since this will retain the default directory across the kill-buffer call.

agent-shell-reload was also affected, since it delegates to agent-shell-restart.

A new test is added to ensure that, in a frame whose last buffer was another project than the current shell's, calling restart will still use the shell's project as expected. Without the fix, the test fails.

Thank you for contributing to agent-shell!

Checklist

  • I agree to communicate (PR description and comments) with the author myself (not AI-generated).
  • I've reviewed all code in PR myself and will vouch for its quality.
  • I've read and followed the Contributing guidelines.
  • I've filed a feature request/discussion for a new feature.
  • I've added tests where applicable.
  • I've updated documentation where necessary.
  • I've run M-x checkdoc and M-x byte-compile-file.

Copy link
Owner

@xenodium xenodium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Left a minor comment. Could you take a look please?

agent-shell.el Outdated
(config (map-elt (buffer-local-value 'agent-shell--state shell-buffer)
:agent-config)))
:agent-config))
(shell-dir (buffer-local-value 'default-directory shell-buffer)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can likely just do (default-directory (buffer-local-value 'default-directory shell-buffer)) here and drop the change below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, yeah I think there was a part in the contributing guide about excluding redundant variables - my bad! I'll push that up sometime later :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in latest force push, also rebased onto current main!

`agent-shell-restart` kills the buffer and calls `agent-shell--start`
directly after.
Since `kill-buffer` will have the effect of changing the default directory to
the "other buffer", `agent-shell--start` can possibly end up creating the new
shell an unexpected project (e.g if the user's last buffer was in a different
project, the new shell will be made for this project instead of the expected
behavior of being for the same project the original shell was for).

The fix is to bind `default-directory` around calling `agent-shell--start`, since this will retain the default directory across the `kill-buffer` call.

`agent-shell-reload` was also affected, since it delegates to `agent-shell-restart`.

A new test is added to ensure that, in a frame whose last buffer was another project than the current shell's, calling restart will still use the shell's project as expected.
Without the fix, the test fails.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@zackattackz zackattackz force-pushed the restart-keep-default-dir branch from 30203b8 to 844af9e Compare March 25, 2026 01:32
@xenodium xenodium merged commit 4d7db3a into xenodium:main Mar 25, 2026
@xenodium
Copy link
Owner

Thanks for the fix. Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants