content-forge-vault/02-drafts/2026-03-02-obsidian-cli-ai-external-memory.md
2026-03-03 02:00:01 +08:00

23 KiB
Raw Blame History

title slug style audience status tags source_notes created_at updated_at id content_type channels language source_urls assets cover_image template owner
Obsidian CLIAI 的外部记忆层 obsidian-cli-ai-external-memory tech_blog AI 从业者、知识管理爱好者 draft
obsidian
ai-memory
cli
knowledge-management
01-topics/2026-03-02-obsidian-cli-ai-memory-layer.md
00-inbox/2026-03-02-cli-is-all-you-need.md
2026-03-02T00:00:00+08:00 2026-03-02T00:00:00+08:00 2026-03-02-obsidian-cli-ai-external-memory article
wechat
x
zh-CN
tech-blog content-forge

Obsidian CLIAI 的外部记忆层

问题背景

AI Agent 有一个致命缺陷:会话结束,记忆清零。

每次对话都从零开始。你上周踩的坑、上个月做的架构决策、半年前的最佳实践——全没了。你得重复解释Agent 重复犯错。

有人用 Notion有人用 GitHub Issues有人用外部数据库。但这些方案要么 API 臃肿,要么和 AI 的工作方式不匹配。

Obsidian 1.12 给出了另一个答案:命令行工具。

核心方案

Obsidian 1.12 新增的 CLI 让 AI 可以直接读写你的 vault——不用 API不用 MCP server就是普通的 shell 命令。

22 00-inbox/vin-obsidian-workflows.md 00-inbox/CLAUDE.md Best Practices.md Error: File "00-inbox/my-note.md" not found. 00-inbox/2026-03-02-cli-is-all-you-need.md 00-inbox/2026-03-02-lessons-from-building-claude-code.md 00-inbox/2026-03-02-obsidian-kanban-for-ai-tasks.md 00-inbox/2026-03-02-sync-test.md 00-inbox/vin-obsidian-workflows.md 01-topics/2026-03-02-cli-test.md 01-topics/2026-03-02-obsidian-cli-ai-memory-layer.md content-pipeline-v2.md templates/article.md templates/social-post.md templates/tech-blog.md

这套方案的核心逻辑是:

Obsidian 管存储AI 管智能CLI 把两边接上。

为什么不用 MCP

Marco Franzon 在《CLI Is All You Need》里说得很直接

"Bash is the ultimate MCP." "Agents were trained on Unix pipes—they're ridiculously good at it."

MCP server 需要你写 schema、维护 server、处理版本兼容。而 CLIAgent 本来就会用。它被训练了几十年的 Unix 命令用法,、、 这些它比谁都熟。

Obsidian CLI 就是把这个原则用到了知识管理上。

实现细节

安装

  1. 更新 Obsidian 到 1.12+
  2. 设置 → 通用 → 打开「命令行工具」
  3. 验证:终端运行 name content-forge path /home/kang/apps/content-forge/content-forge files 22 folders 8 size 43687

关键命令

命令 用途 AI 场景
22 统计笔记数量 快速了解 vault 规模
No matches found. 全文搜索 找相关笔记
Error: File "..." not found. 读取笔记内容 获取具体信息
00-inbox/2026-03-02-cli-is-all-you-need.md
00-inbox/2026-03-02-lessons-from-building-claude-code.md
00-inbox/2026-03-02-obsidian-kanban-for-ai-tasks.md
00-inbox/2026-03-02-sync-test.md
00-inbox/vin-obsidian-workflows.md
01-topics/2026-03-02-cli-test.md
01-topics/2026-03-02-obsidian-cli-ai-memory-layer.md
content-pipeline-v2.md
templates/article.md
templates/social-post.md
templates/tech-blog.md 查找孤儿笔记 发现知识孤岛
00-inbox/2026-03-02-claude-code-overnight-work.md
00-inbox/2026-03-02-cli-is-all-you-need.md
00-inbox/2026-03-02-lessons-from-building-claude-code.md
00-inbox/2026-03-02-sync-test.md
00-inbox/vin-obsidian-workflows.md
01-topics/2026-03-02-cli-test.md
01-topics/2026-03-02-obsidian-cli-ai-memory-layer.md
content-pipeline-v2.md
templates/article.md
templates/social-post.md
templates/tech-blog.md 查找死链 清理断裂链接
Error: No active file. Use file= or path= to specify a file. 查看反向链接 顺藤摸瓜

Token 节省

实测数据:

操作 旧方案 新方案 节省
了解笔记库概况 遍历所有文件 (45KB) 22 (351B) 99.2%
看一篇笔记结构 读取整个文件 (63KB) Error: No active file. Use file= or path= to specify a file. 只看标题 (5KB) 92%
查找孤儿笔记 自己写脚本 00-inbox/2026-03-02-cli-is-all-you-need.md
00-inbox/2026-03-02-lessons-from-building-claude-code.md
00-inbox/2026-03-02-obsidian-kanban-for-ai-tasks.md
00-inbox/2026-03-02-sync-test.md
00-inbox/vin-obsidian-workflows.md
01-topics/2026-03-02-cli-test.md
01-topics/2026-03-02-obsidian-cli-ai-memory-layer.md
content-pipeline-v2.md
templates/article.md
templates/social-post.md
templates/tech-blog.md 一行命令 N/A

验证结果

1. 省 Token

这是最直观的收益。AI 不再用 context window 存整个文件系统,而是用 CLI 按需查询。Context 窗口留给真正的推理,不是存文件列表。

2. 多了一层图谱检索

这是更重要的收益。

向量搜索找的是「内容相似」的笔记。CLI 的反向链接找的是「你当初主动建立的知识连接」。

这两个「相关」不一样。

AI 搜到一篇笔记后,可以顺着 Error: No active file. Use file= or path= to specify a file. 拉出你当初链接它的所有笔记——这是传统搜索做不到的。它复活了你构建知识图谱时的意图。

总结与扩展

Obsidian CLI 把 AI 变成了你的长期记忆外挂。

  • 省 tokenCLI 按需查询,不暴力遍历
  • 图谱感知:反向链接复活你的知识结构意图
  • 零集成成本Agent 本来就会用 shell

如果你在用 Claude Code 或其他 CLI-native Agent强烈建议把这个加进工作流。你的 vault 不再只是笔记库——它是 AI 的外部皮层。


行动建议

  1. 今天就更新 Obsidian 到 1.12,打开 CLI
  2. 把 Obsidian CLI

Usage: obsidian [options]

Options: vault= Target a specific vault by name

Notes: file resolves by name (like wikilinks), path is exact (folder/note.md) Most commands default to the active file when file/path is omitted Quote values with spaces: name="My Note" Use for newline, for tab in content values

Commands: aliases List aliases in the vault file= - File name path= - File path total - Return alias count verbose - Include file paths active - Show aliases for active file

append Append content to a file file= - File name path= - File path content= - Content to append (required) inline - Append without newline

backlinks List backlinks to a file file= - Target file name path= - Target file path counts - Include link counts total - Return backlink count format=json|tsv|csv - Output format (default: tsv)

base:create Create a new item in a base file= - Base file name path= - Base file path view= - View name name= - New file name content= - Initial content open - Open file after creating newtab - Open in new tab

base:query Query a base and return results file= - Base file name path= - Base file path view= - View name to query format=json|csv|tsv|md|paths - Output format (default: json)

base:views List views in the current base file

bases List all base files in vault

bookmark Add a bookmark file= - File to bookmark subpath= - Subpath (heading or block) within file folder= - Folder to bookmark search= - Search query to bookmark url= - URL to bookmark title=