# Aider Watch Mode — Auto-Edit on `# AI:` Comments > Aider Watch Mode tails files and edits when you save an `# AI:` comment. Trigger Aider from VS Code, vim, Cursor, Claude Code without terminal switch. ## Install Copy the content below into your project: ## Quick Use 1. Already have Aider installed? Start it with `aider --watch-files` 2. Open any tracked file in your editor 3. Add `# AI: ` and save — Aider edits and commits --- ## Intro Aider Watch Mode lets you trigger Aider from inside your editor without switching to a terminal. Add `# AI: ` (or `// AI:` for JS/TS) anywhere in a file and save — Aider notices, edits the file, removes the comment, and commits. Best for: developers who don't want to leave VS Code / vim / Cursor / Claude Code to invoke an AI edit. Works with: Aider 0.50+, any editor that saves files. Setup time: 1 minute. --- ### Start watch mode ```bash # In your repo aider --watch-files # Or set in .aider.conf.yml echo "watch-files: true" >> .aider.conf.yml aider ``` Aider stays running and watches all tracked files. ### Trigger an edit In any file, add an AI comment: ```python # main.py def fetch_user(user_id: int): # AI: add caching with functools.lru_cache, max 1000 entries return db.users.find_one({"_id": user_id}) ``` Save the file. Aider: 1. Detects the AI comment 2. Reads the file (and any other files relevant) 3. Edits the function and removes the AI comment 4. Auto-commits with a generated message Result: ```python # main.py from functools import lru_cache @lru_cache(maxsize=1000) def fetch_user(user_id: int): return db.users.find_one({"_id": user_id}) ``` ### Multi-file via cross-references ```python # models.py class User: # AI! add a 'plan' field with type Literal["free", "pro"], default "free" name: str email: str ``` The `AI!` (with bang) tells Aider to act immediately even without a save trigger. Aider also updates `tests/test_models.py` if it imports User. ### Bang variants | Marker | Behavior | |---|---| | `# AI: ` | Edit on next save | | `# AI! ` | Edit immediately | | `# AI?` | Ask Aider a question; reply in chat | --- ### FAQ **Q: Does watch mode work in any editor?** A: Yes — watch mode tails files at the filesystem level, so VS Code, vim, neovim, JetBrains, Cursor, even Claude Code's internal edits all trigger it. The editor doesn't matter. **Q: Will it edit files I didn't ask it to?** A: Only files you've /add'd to Aider's session, or the file containing the AI comment. Files in `no-edit` are protected. Aider also asks before destructive operations (deleting, renaming) by default. **Q: Can I disable auto-commits in watch mode?** A: Yes — `auto-commits: false` in your config. Aider still edits the files but leaves the changes uncommitted for you to review and commit manually. --- ## Source & Thanks > Built by [Paul Gauthier](https://github.com/paul-gauthier) and the Aider community. Watch mode shipped in Aider 0.50. > > [Aider-AI/aider](https://github.com/Aider-AI/aider) — ⭐ 36,000+ --- ## 快速使用 1. 已经装了 Aider?用 `aider --watch-files` 启动 2. 在编辑器打开任何 tracked 文件 3. 加一行 `# AI: <你的指令>` 并保存,Aider 自己编辑并 commit --- ## 简介 Aider Watch Mode 让你不用切终端就能从编辑器里触发 Aider。在文件任何地方加 `# AI: <指令>`(JS/TS 用 `// AI:`)然后保存 —— Aider 监听到、编辑文件、删掉注释、commit。适合不想离开 VS Code / vim / Cursor / Claude Code 去触发 AI 编辑的开发者。需要 Aider 0.50+ 和任何能保存文件的编辑器。装机时间 1 分钟。 --- ### 起 watch 模式 ```bash # 在仓库里 aider --watch-files # 或者写进 .aider.conf.yml echo "watch-files: true" >> .aider.conf.yml aider ``` Aider 保持运行,监听所有 tracked 文件。 ### 触发编辑 在任何文件里加 AI 注释: ```python # main.py def fetch_user(user_id: int): # AI: add caching with functools.lru_cache, max 1000 entries return db.users.find_one({"_id": user_id}) ``` 保存文件。Aider 会: 1. 检测到 AI 注释 2. 读这个文件(和相关文件) 3. 编辑函数、删掉 AI 注释 4. 自动 commit 带生成 message 结果: ```python # main.py from functools import lru_cache @lru_cache(maxsize=1000) def fetch_user(user_id: int): return db.users.find_one({"_id": user_id}) ``` ### 多文件交叉引用 ```python # models.py class User: # AI! add a 'plan' field with type Literal["free", "pro"], default "free" name: str email: str ``` `AI!`(带感叹号)告诉 Aider 不等保存就立刻动手。如果 `tests/test_models.py` import 了 User,Aider 也会更新。 ### 标记变体 | 标记 | 行为 | |---|---| | `# AI: <指令>` | 下次保存时编辑 | | `# AI! <指令>` | 立刻编辑 | | `# AI?` | 给 Aider 提问;在聊天里回复 | --- ### FAQ **Q: watch 模式在任何编辑器都行吗?** A: 行 —— watch 模式在文件系统层监听,所以 VS Code / vim / neovim / JetBrains / Cursor 甚至 Claude Code 的内部编辑都会触发。编辑器无所谓。 **Q: 会改我没让它改的文件吗?** A: 只改你 /add 进 Aider 会话的文件、或者带 AI 注释的那个文件。`no-edit` 里的文件受保护。Aider 默认在破坏性操作(删除、重命名)前会问。 **Q: watch 模式能关掉自动 commit 吗?** A: 能 —— 配置里设 `auto-commits: false`。Aider 仍然编辑文件,但不 commit,让你自己审完再提交。 --- ## 来源与感谢 > Built by [Paul Gauthier](https://github.com/paul-gauthier) and the Aider community. Watch mode shipped in Aider 0.50. > > [Aider-AI/aider](https://github.com/Aider-AI/aider) — ⭐ 36,000+ --- Source: https://tokrepo.com/en/workflows/aider-watch-mode-auto-edit-on-ai-comments Author: Aider