3
43
Fork
You've already forked opencode.el
16

Add directory to the context #19

Closed
opened 2026年01月27日 22:31:56 +01:00 by daut · 4 comments
Contributor
Copy link

opencode-add-file (C-c f) currently only supports adding a single file. It would be useful to also support adding directories. Either via a separate command/keybinding or by extending the existing command, similar to how the TUI handles @. Going further, it would be nice if typing @ could trigger a unified "add file or directory" command (opencode-add-file-or-dir or similar).

`opencode-add-file` (`C-c f`) currently only supports adding a single file. It would be useful to also support adding directories. Either via a separate command/keybinding or by extending the existing command, similar to how the TUI handles `@`. Going further, it would be nice if typing @ could trigger a unified "add file or directory" command (`opencode-add-file-or-dir` or similar).

Yes, needed

Yes, needed
Owner
Copy link

I added some DWIM commands, now there is opencode-add-file-dwim, if you use from within a dired buffer, it will add all marked files, or if none are marked, it will add the file at point. This will also work for adding directories (the same as done by @ in the TUI, it adds a listing of the directories contents to the context) In any other buffer, it will add that buffer's file to the last active opencode session.

it would be nice if typing @ could trigger a unified "add file or directory" command

I don't want to copy the UI exactly of the TUI, but follow emacs UI conventions, so have mode specific commands bound to C-c .... You can always bind @ to opencode-add-file in opencode-session-mode-map

Regarding adding directories, do you mean adding a directory and the contents of all files within it are brought into context? Or as the TUI does it where it just adds the directory listing to context? that is possible now through opencode-add-file-dwim in dired, but I'm unsure of adding directories to the file picker for opencode-add-file as I think that pollutes the options when my use and probably most use of it is to pick a file. Maybe could add a separate opencode-add-file-or-dir but what should the behavior be? I think I'd have more use for a command that actually adds all files within the directory to context, rather than just the directory listing as done by the TUI.

I added some DWIM commands, now there is `opencode-add-file-dwim`, if you use from within a dired buffer, it will add all marked files, or if none are marked, it will add the file at point. This will also work for adding directories (the same as done by @ in the TUI, it adds a listing of the directories contents to the context) In any other buffer, it will add that buffer's file to the last active opencode session. > it would be nice if typing @ could trigger a unified "add file or directory" command I don't want to copy the UI exactly of the TUI, but follow emacs UI conventions, so have mode specific commands bound to `C-c ...`. You can always bind `@` to `opencode-add-file` in `opencode-session-mode-map` Regarding adding directories, do you mean adding a directory and the contents of all files within it are brought into context? Or as the TUI does it where it just adds the directory listing to context? that is possible now through `opencode-add-file-dwim` in dired, but I'm unsure of adding directories to the file picker for `opencode-add-file` as I think that pollutes the options when my use and probably most use of it is to pick a file. Maybe could add a separate `opencode-add-file-or-dir` but what should the behavior be? I think I'd have more use for a command that actually adds all files within the directory to context, rather than just the directory listing as done by the TUI.
Owner
Copy link

I think my main use of adding a whole directory to context, would be just to add the whole active project to context if the project is small enough. Maybe this could be better addressed with some config option to auto add the full source of the active project to context if it's below some configurable percent of the context limit?

I think my main use of adding a whole directory to context, would be just to add the whole active project to context if the project is small enough. Maybe this could be better addressed with some config option to auto add the full source of the active project to context if it's below some configurable percent of the context limit?
Owner
Copy link

on second thought adding the full contents of the directory is probably too much stuff in context. Opencode TUI and claude code when adding a directory just add the directory listing. So I made it so opencode-add-file (C-c f) if called with a prefix argument (C-u C-c f), will show project directories instead of files in the prompt, and add the directory listing to context. In the rare case where you want to add a directory outside of the project to context, you can add it with opencode-add-file-dwim from dired.

on second thought adding the full contents of the directory is probably too much stuff in context. Opencode TUI and claude code when adding a directory just add the directory listing. So I made it so `opencode-add-file` (`C-c f`) if called with a prefix argument (`C-u C-c f`), will show project directories instead of files in the prompt, and add the directory listing to context. In the rare case where you want to add a directory outside of the project to context, you can add it with `opencode-add-file-dwim` from dired.
Sign in to join this conversation.
No Branch/Tag specified
main
No results found.
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sczi/opencode.el#19
Reference in a new issue
sczi/opencode.el
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?