Smart Context codeblock
The smart-context codeblock lets you pin a curated context set inside a note.
It is especially useful when your "must-include context" is not just vault notes, but also external folders and files (like code repos) that live next to your vault.
Once the codeblock exists, it renders as a compact UI with:
- Edit context (open the selector modal)
- Copy to clipboard (export the codeblock context)
- a live size estimate (chars + approximate tokens)

Who this helps
- You work with AI across multiple sessions and want your context to be consistent.
- You are a coder and want to include repo files without copy-pasting code manually.
- You keep project instructions in a note and want that note to "carry its own context".
- You want a lightweight, visible, auditable list of what will be included when you copy context.
The best mental model:
"This note is the hub. The codeblock is the context manifest."
What the codeblock does
A smart-context codeblock is just a list of paths.
- A folder path means: include files inside that folder.
- A file path means: include that file.
- A line starting with
!means: exclude matching files (path or simple glob pattern).
This gives you a fast way to keep a context pack "attached" to the note you are working in.
Add and edit the codeblock
Recommended: use the command
Use the command:
- Smart Context: External source file context codeblock
This opens the external selector modal and inserts (or updates) the smart-context codeblock in the active note.
Then use the codeblock UI
Once it is in the note, you will typically use:
- Edit context to add/remove items
- Copy to clipboard to export just the codeblock items
- Show to render the context tree (helpful when you want to sanity-check what will be copied)
Select external files and folders
The external selector modal is optimized for keyboard navigation:

Navigation cheatsheet
- Arrow keys: move selection
- Enter: add the highlighted file/folder
- Right Arrow: open a folder
- Cmd/Ctrl + Enter: add an entire folder in one action
- .. (parent folder): go up a directory
If you already know the repo folder you want, select the folder and use Cmd/Ctrl + Enter. Then prune what you do not want.
Exclude noise with ignore lines
Sometimes you want "most of a folder" but not everything.
Add an exclusion line by prefixing the pattern with !.
Examples:
```smart-context
../my-repo
!*.test.js
!../my-repo/dist
!../my-repo/obsidian/obsidian.min.js
```
What this solves
- Keeps your context smaller and higher-signal.
- Prevents large generated files from blowing up token counts.
- Lets you include a whole folder while carving out a few unwanted files.
Folder includes also respect .gitignore and .scignore, so you often get a clean set by default. Exclusions are for the cases where you want even tighter control.
Copy options
Copy just the codeblock context
Use the codeblock button:
- Copy to clipboard
This exports the selected items listed in the codeblock.
Copy the current note plus the codeblock context
If you use a "Copy current note" style command, the codeblock items are treated as "depth zero" context alongside the current note.
This is ideal when the current note contains the instructions and the codeblock contains the supporting references.
When to use a codeblock vs a named context
Use a codeblock when:
- The context should live inside a specific note (a project hub, spec, or agent instructions note).
- You want the context list to be visible and editable right where you write.
- You want external folders/files included as part of the note.
Use a named context (Builder) when:
- You want a reusable bundle that is not tied to any single note.
- You want to reuse the same bundle across many projects or workflows.
Many people use both:
- named contexts for vault notes
- codeblocks for external repos and files
Workflow recipes
These are practical patterns that solve common AI + PKM problems.
1) "Agent handoff" note for a repo
Use this when you want any new chat or agent session to start grounded.
- Create a note like "Repo - Agent Brief".
- Add the repo folder to the
smart-contextcodeblock. - Add exclusions for generated or irrelevant files.
- Write the instructions in the note body.
- Use "Copy current note" so the instructions and repo context travel together.
Outcome: you stop re-explaining the repo and rules every session.
2) Debug pack with tight token budget
Use this when you need help debugging but do not want to paste half the repo.
- Include
src/(or the smallest folder that contains the bug). - Exclude tests, build output, and large vendor files.
- Add the one config file that changes behavior (example: env, build config).
- Copy to clipboard and ask for a diagnosis with specific reproduction steps.
Outcome: high-signal debugging context without token blowups.
3) "Include the folder, exclude the one giant file"
Use this when one file is too large or irrelevant, but the rest of the folder is useful.
- Add the folder.
- Remove the specific file via Edit context.
- Let the codeblock keep the folder line and add a
!exclusion for that file.
Outcome: your codeblock stays short and readable (no need to list every included file).
4) Spec note that stays linked to implementation
Use this when your spec lives in Obsidian but implementation lives in a repo.
- Write the spec in a note.
- Add the implementation folder(s) in the codeblock.
- Add a few targeted exclusions to avoid noise.
- When you ask AI for changes or review, copy the note + codeblock.
Outcome: fewer hallucinations about what the code does, and better alignment with the actual implementation.
5) Multi-repo architecture context
Use this when work spans multiple repos and you want AI to reason across boundaries.
- Add each repo root folder as a line in the codeblock.
- Exclude build output and lockfiles if they are not needed.
- Keep one "Architecture" note as the hub and store the codeblock there.
- Copy for design review, migration planning, or dependency analysis.
Outcome: architectural reasoning stays grounded in real code, not vague descriptions.
6) "Docs and code together" writing loop
Use this when drafting docs, READMEs, or internal guides.
- Add the docs folder and the relevant code folder to the codeblock.
- Exclude auto-generated docs artifacts.
- Copy and ask AI to propose edits with references to file paths.
Outcome: faster documentation that matches the current codebase.