Skip to content

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:

Who this helps

Tip

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.

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:

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:


Select external files and folders

The external selector modal is optimized for keyboard navigation:

Navigation cheatsheet

Tip

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

Note

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:

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:

Use a named context (Builder) when:

Many people use both:


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.

  1. Create a note like "Repo - Agent Brief".
  2. Add the repo folder to the smart-context codeblock.
  3. Add exclusions for generated or irrelevant files.
  4. Write the instructions in the note body.
  5. 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.

  1. Include src/ (or the smallest folder that contains the bug).
  2. Exclude tests, build output, and large vendor files.
  3. Add the one config file that changes behavior (example: env, build config).
  4. 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.

  1. Add the folder.
  2. Remove the specific file via Edit context.
  3. 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.

  1. Write the spec in a note.
  2. Add the implementation folder(s) in the codeblock.
  3. Add a few targeted exclusions to avoid noise.
  4. 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.

  1. Add each repo root folder as a line in the codeblock.
  2. Exclude build output and lockfiles if they are not needed.
  3. Keep one "Architecture" note as the hub and store the codeblock there.
  4. 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.

  1. Add the docs folder and the relevant code folder to the codeblock.
  2. Exclude auto-generated docs artifacts.
  3. Copy and ask AI to propose edits with references to file paths.

Outcome: faster documentation that matches the current codebase.