AI History Auto Record(AI历史自动记录)
📖 目录 / Table of Contents中文文档功能特性
安装方式方式一:本地安装(推荐)
方式二:开发模式运行
前置要求
快速上手自动模式(默认开启)
手动模式
自动模式自动模式是本插件的核心创新。启用后,插件在激活时自动开始一个「会话」,持续监听文件变更。 工作流程
切换模式
Claude Code 钩子配置让 Claude Code 在每次会话开始/结束时自动触发快照。 配置步骤在项目根目录的
效果
输出文件说明每次会话在
AI_Summary.md
✅ 修改后(After AI):
metadata.json
回滚操作如果 AI 的修改不理想,可以一键回滚:
扩展配置
快捷键
常见问题Q: 为什么
|
| 方案 | 问题 |
|---|---|
code --command |
会打开新的 VS Code 窗口,无法发给当前窗口 |
| 信号文件轮询 | 需要文件系统轮询,延迟高、可靠性差 |
| HTTP Server | 过度设计,TCP 已足够 |
| ✅ TCP 127.0.0.1 | 轻量、可靠、零依赖,node -e "net.connect()" 一行搞定 |
实现: 扩展启动时在 127.0.0.1 随机端口创建 TCP Server。端口号写入 .vscode/.ai-record-port。钩子脚本读取端口后 net.connect(port).end('start') 发消息。
2. git add 反复失败的排查过程
症状: git add . 在终端执行成功(exit 0),但在 Node.js cp.exec 中始终 exit ≠ 0。
排查链路:
- Shell Profile 污染 → stderr 超 maxBuffer → 改用
execFile绕过 shell - execFile 丢环境变量 → PATH/TEMP 缺失导致 git 写对象失败 → 回退 exec(50MB buffer)
- safecrlf=true(用户全局配置)→ CRLF 警告变硬错误 exit 1 → 加
-c core.safecrlf=false - advice.addIgnoredFile → pathspec 和 .gitignore 重叠时 git 输出 hint 并 exit 1 → 加
-c advice.addIgnoredFile=false - node_modules 未排除 → git add 尝试写入数千个文件 →
.gitignore加node_modules/ - pathspec 与 .gitignore 冲突 → 两者同时排除同一路径导致 exit 1 → pathspec 精简为仅
.git+.claude
最终稳定的 git 命令前缀: git -c core.safecrlf=false -c advice.addIgnoredFile=false
3. Windows 路径长度限制
影子 Git 最初放在 .vscode/.ai-shadow/,导致 Windows 上路径超过 260 字符限制,git add 写入对象时报 unable to create temporary file。最终移到项目根目录 .ai-shadow/,大幅缩短路径。
4. 为什么 prompt 抓取用 UserPromptSubmit 而非 SessionStart
SessionStart的 stdin JSON 不含 prompt 字段——仅包含 session_id、cwd 等会话元数据UserPromptSubmit的 stdin JSON 直接包含"prompt": "用户原始消息"——完美匹配需求UserPromptSubmit只在用户真正发送消息时触发,不会像SessionStart(resume)在 VS Code 启动时误触发
English Documentation
Features
| Feature | Description |
|---|---|
| 🎬 Auto Recording | Automatically tracks file changes with zero manual intervention |
| 🖐️ Manual Snapshots | Manual mode retained for precise snapshot timing |
| 🪝 Claude Hooks | First-class SessionStart / SessionEnd hook support for Claude Code |
| 📝 Markdown Summaries | Human-readable AI_Summary.md with Before/After code blocks |
| 🔧 Git Patch Files | Standard changes.patch — directly consumable by git apply |
| 📊 Structured Metadata | metadata.json records session info for future GUI integration |
| ⏪ One-Click Rollback | Click the revert button in AI_Summary.md to undo AI changes |
| 🌐 Bilingual UI | Chinese + English interface, auto-follows VS Code language |
| 📁 Clean Storage | All snapshots live in .vscode/.ai-history-auto-record/ — no root pollution |
Installation
Option 1: Local Install (Recommended)
# 1. Compile the extension
cd ai-history-auto-record
pnpm install
pnpm run compile
# 2. Copy to VS Code extensions directory
# Windows PowerShell:
Copy-Item -Recurse . "$env:USERPROFILE\.vscode\extensions\local-dev.ai-history-auto-record-0.0.1"
# macOS / Linux:
cp -r . ~/.vscode/extensions/local-dev.ai-history-auto-record-0.0.1/
# 3. Restart VS Code
Option 2: Development Mode
cd ai-history-auto-record
pnpm install
pnpm run watch
# Press F5 to launch Extension Development Host
Prerequisites
- Git CLI must be installed and accessible in PATH (
git --versionshould work) - VS Code
^1.85.0
Quick Start
Auto Mode (Enabled by Default)
- Open a VS Code project → extension auto-activates, status bar shows "AI Recording..."
- Use Claude Code or any AI tool to modify files → extension watches saves automatically
- Press
Ctrl+Alt+Shift+Sor click the editor toolbar button → End Session, generate report AI_Summary.mdopens automatically, showing Before/After comparisons
Manual Mode
① Ctrl+Alt+A (Snapshot)
↓ Captures code state BEFORE AI modifications
② Let AI modify the code
↓ Claude Code / Copilot / manual edits
③ Ctrl+Alt+S (Save Changes)
↓ Enter the prompt you gave to the AI
④ AI_Summary.md auto-generated → review the diff
⚠️ Order matters! Snapshot first, then AI changes. Reversing the order results in an empty diff.
Auto Mode
Auto mode is the core innovation of this extension. When enabled, the extension automatically starts a "session" on activation and continuously monitors file changes.
Workflow
VS Code Launch → Auto-start session → Take initial snapshot
↓
AI modifies files (auto-tracked)
↓
End session (manual or via Claude hooks)
↓
Generate report (AI_Summary.md + changes.patch + metadata.json)
Toggle Mode
- Command Palette:
AI Record: Toggle Auto/Manual Mode - Or edit VS Code settings:
"aiHistoryAutoRecord.autoMode": true/false
Claude Code Hooks Setup
Automatically trigger snapshots when Claude Code sessions start and end.
Configuration
Add the following to .claude/settings.local.json in your project root:
{
"hooks": {
"SessionStart": [
{
"command": "code --command ai-history-auto-record.startSession"
}
],
"SessionEnd": [
{
"command": "code --command ai-history-auto-record.endSession"
}
]
}
}
What Happens
| Event | Automatic Action |
|---|---|
| Claude Code session starts | Full project snapshot taken |
| Claude Code session ends | Diff report generated automatically |
Output Files
Each session produces three files under .vscode/.ai-history-auto-record/<timestamp>/:
.vscode/.ai-history-auto-record/2026-06-02_16-28-33/
├── AI_Summary.md # Markdown summary (human-readable)
├── changes.patch # Git-compatible patch (machine-consumable)
└── metadata.json # Structured metadata (GUI-ready)
AI_Summary.md
Human-readable Markdown with syntax-highlighted Before/After code blocks. See Chinese section above for a detailed example.
changes.patch
Standard unified diff format, consumable by any Git tool:
# Inspect the patch
git apply --stat changes.patch
# Apply the patch
git apply changes.patch
metadata.json
Structured JSON providing session metadata for future GUI integration. See Chinese section above for the schema.
Rollback
If the AI's changes aren't satisfactory, rollback with one click:
- Open
.vscode/.ai-history-auto-record/<timestamp>/AI_Summary.mdin VS Code - Click the 🔄 Revert button in the editor toolbar
- Files are restored to their pre-AI state
- A
🛑 REVERTEDbadge is automatically injected into the summary
⚠️ If files are manually edited after the rollback point, the reverse patch may fail due to merge conflicts. Rollback immediately if you don't like the AI's output.
Extension Settings
| Setting | Type | Default | Description |
|---|---|---|---|
aiHistoryAutoRecord.autoMode |
boolean | true |
Enable automatic recording mode |
aiHistoryAutoRecord.storagePath |
string | .vscode/.ai-history-auto-record |
Storage path for snapshots (relative to project root) |
aiHistoryAutoRecord.watchDebounceMs |
number | 1000 |
Debounce delay for file save events (ms) |
Keyboard Shortcuts
| Shortcut | Command | Description |
|---|---|---|
Ctrl+Alt+Shift+A |
Start Session | Auto mode: begin recording session |
Ctrl+Alt+Shift+S |
End Session | Auto mode: end session & generate report |
Ctrl+Alt+A |
Manual Snapshot | Manual mode: snapshot code before AI changes |
Ctrl+Alt+S |
Save Changes | Manual mode: diff changes & generate report |
| (in AI_Summary.md) | Rollback Button | Click the 🔄 button in the editor toolbar |
FAQ
Q: Why is .vscode/.ai-shadow/ empty or missing?
A: .ai-shadow/ is a temporary directory that only exists during an active session. It's automatically cleaned up when the session ends. This is expected behavior.
Q: I don't see any AI_Summary.md files. Why?
A: Check your operation order: snapshot first → then modify code → then save. If reversed, the diff will be empty and no report is generated.
Q: How do I view snapshots in Windows Explorer?
A: Snapshots are stored at .vscode/.ai-history-auto-record/. You can browse and open them directly in VS Code's file explorer.
Q: What languages are supported for syntax highlighting?
A: 20+ languages including TypeScript, JavaScript, Python, Rust, Go, Java, HTML, CSS, Vue, Svelte, and more. Language is auto-detected from the file extension.
Q: How do I exclude directories from tracking?
A: Create an .aiignore file in your project root (same format as .gitignore), or add rules to .gitignore. The following are always excluded: .git, .vscode/.ai-shadow, .vscode/.ai-history-auto-record.
Key Challenges
1. Hook-to-Extension Communication
Problem: Claude Code hooks run shell commands. How to notify the VS Code extension?
Comparison:
| Approach | Issue |
|---|---|
code --command |
Opens a NEW VS Code window, not the existing one |
| Signal file polling | Filesystem polling — high latency, unreliable |
| HTTP Server | Overengineered for the task |
| ✅ TCP 127.0.0.1 | Lightweight, reliable, zero dependencies |
Implementation: Extension starts a TCP server on 127.0.0.1 with a random port. The port is written to .vscode/.ai-record-port. Hook scripts read the port and connect via net.connect(port).end('start').
2. git add Debugging Journey
Symptom: git add . works in terminal (exit 0) but fails inside Node.js cp.exec (exit ≠ 0).
Debugging chain:
- Shell profile noise → stderr overflow → tried
execFileto bypass shell - execFile missing env → PATH/TEMP lost on Windows → git object write failure → back to exec (50MB buffer)
- safecrlf=true (user global config) → CRLF warnings treated as errors → added
-c core.safecrlf=false - advice.addIgnoredFile → pathspec & .gitignore overlap triggers hint + exit 1 → added
-c advice.addIgnoredFile=false - node_modules not excluded → git add tries to hash thousands of files → added
node_modules/to.gitignore - pathspec conflict with .gitignore → both excluding the same path → exit 1 → pathspec reduced to
.git+.claude
Final stable git prefix: git -c core.safecrlf=false -c advice.addIgnoredFile=false
3. Windows Path Length Limit
Shadow git was initially placed at .vscode/.ai-shadow/. On Windows, this path exceeded the 260-character limit, causing git add to fail with unable to create temporary file. Moved to project root .ai-shadow/, significantly shortening the path.
4. Why UserPromptSubmit for Prompt Capture
SessionStartstdin JSON does NOT contain the prompt field — only session metadata (session_id, cwd)UserPromptSubmitstdin JSON directly contains"prompt": "user's raw message"— exactly what's neededUserPromptSubmitonly fires when the user actually sends a message, unlikeSessionStart(resume)which also fires on VS Code startup
📄 License
GPL-3.0Made with ❤️ for the AI-assisted development workflow.