Smart Context (Early Release)

Smart Context is an Obsidian plugin that helps you copy contents from folders, open files, multiple selected notes, and even external file paths to your clipboard, with advanced configuration—such as excluding specific heading sections or ignoring entire files via .gitignore or .scignore. This is particularly useful when working with AI tools like ChatGPT, letting you feed large sets of project notes, research, or documentation as "context" to improve AI responses and accuracy.


Features


Usage

Main Commands (Command Palette)

  1. Build Context (Multiple File Selection)

    • Opens a modal listing your vault’s notes.
    • Each time you press 'Enter' on a suggestion, that note is added as a pill above the input.
    • Press the "Build Context" button (or hit 'Esc') once finished selecting.
    • The chosen notes are merged, respecting any excluded headings and ignoring patterns, then copied to your clipboard.
  2. Copy Folder Contents to Clipboard

    • Prompts you to pick a folder.
    • Gathers all recognized text files, merges them into a single output, and copies to the clipboard.
    • Respects .scignore or .gitignore patterns within that folder to skip certain files.
  3. Copy Visible Open Files Content to Clipboard

    • Copies only the content from currently visible (active) panes.
  4. Copy All Open Files Content to Clipboard

    • Copies content from every open file in the workspace.
  5. Copy Visible Open Files Content (With Linked Files) to Clipboard

    • Same as #3 but also includes files they link to (recursively).
  6. Copy All Open Files Content (With Linked Files) to Clipboard

    • Same as #4 but also includes files they link to (recursively).
  7. Open External File Browser

    • Desktop-only command.
    • Lets you navigate above or outside your vault and insert external file/folder paths into a smart-context codeblock.

Context Menu on Folders


External File Browser (Desktop Only)

When you run "Open External File Browser":

  1. A modal appears, starting in the vault’s parent folder.
  2. Navigate by:
    • Right Arrow or Shift + Enter: Open (drill into) the selected directory.
    • Enter: Insert the selected file/folder path into the active file's smart-context block and close the modal.
    • Ctrl + Enter: Insert the path but keep the modal open, letting you select multiple external paths.
    • Arrow Left: Go up a directory (or pick ..).
    • Esc: Close the modal.

Any inserted paths appear in a smart-context codeblock within the active note, so the plugin can pull them in later during a copy command.


Using smart-context Codeblocks

A codeblock like this:

```smart-context
folderA/subFolder
path/to/someFile.md
```

Settings

In Settings → Community Plugins → Smart Context, you can configure:


Formatting

When you copy folder contents, open files, or build a custom set of notes, the output might look like:

<folder_name> Folder Structure:
<tree_structure>

File Contents:
----------------------
/<relative_file_path>
-----------------------
<file_content>
-----------------------

For open or selected files, the format is similar:

Open Files Contents:
----------------------
/<file_path>
-----------------------
<file_content>
-----------------------

These sections can also include your custom “before/after” text, placeholders, or any heading exclusions you defined.


Example

# Notes
Some general notes here.

## Secret
This should be excluded.

## Visible
This will be included.

If you set "Secret" as an excluded heading, the "Secret" section won't appear when you copy this file’s contents. If you also had *.pdf in a .scignore, any PDF files in that same directory would be skipped entirely.