Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

docs(ai-task): /ai-task no longer loads an old personal copy (#16761)

Hazem Adel676b419fc63b
diff --git a/.agents/skills/ai-task/SKILL.md b/.agents/skills/ai-task/SKILL.md
index b4f49b41132..85516e525eb 100644
--- a/.agents/skills/ai-task/SKILL.md
+++ b/.agents/skills/ai-task/SKILL.md
@@ -47,7 +47,7 @@ Run these checks before anything else, silently when they pass. If one fails, sh
> **One setup step left: your Linear API key.** I use it to keep the merge queue in order.
> In a terminal in the repo (any OS), run `node .agents/skills/ai-task/linear.mjs setup` and follow it. Then restart Claude Code. Don't paste the key here.
- `setup` reads the key hidden, checks it with Linear, and saves it to `env` in `~/.claude/settings.json`, which Claude Code loads on every OS. It needs a real terminal, so not through `!`. A key pasted into the chat is leaked: don't use it, tell them to revoke it and run `setup` with a new one.
+ `setup` reads the key hidden, checks it with Linear, and saves it to `env` in `~/.claude/settings.json`, which Claude Code loads on every OS. It also moves any old personal copy of this skill (in `~/.claude/skills/` or `~/.claude/commands/ai-task.md`) to `~/.claude/ai-task-old/`, since a personal copy loads instead of the repo's version. It needs a real terminal, so not through `!`. A key pasted into the chat is leaked: don't use it, tell them to revoke it and run `setup` with a new one.
## Help (no arguments, "help", or "?")
diff --git a/.agents/skills/ai-task/linear.mjs b/.agents/skills/ai-task/linear.mjs
index 785d9555a80..12951c346cb 100644
--- a/.agents/skills/ai-task/linear.mjs
+++ b/.agents/skills/ai-task/linear.mjs
@@ -1,8 +1,10 @@
-import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises'
+import { chmod, lstat, mkdir, readdir, readFile, realpath, rename, writeFile } from 'node:fs/promises'
import { homedir } from 'node:os'
-import { dirname, join } from 'node:path'
+import { basename, dirname, join } from 'node:path'
+import { fileURLToPath } from 'node:url'
-const SETTINGS_PATH = join(homedir(), '.claude', 'settings.json')
+const CLAUDE_DIR = join(homedir(), '.claude')
+const SETTINGS_PATH = join(CLAUDE_DIR, 'settings.json')
const COMMANDS = { setup, order }
const [command, ...args] = process.argv.slice(2)
@@ -12,6 +14,7 @@ if (!COMMANDS[command]) {
await COMMANDS[command](args)
async function setup() {
+ await moveOldSkillCopies()
if (!process.stdin.isTTY) {
fail('Run this in your own terminal (not inside Claude Code), so the key stays hidden.')
}
@@ -89,6 +92,35 @@ function askHidden(prompt) {
})
}
+async function moveOldSkillCopies() {
+ const skillsDir = join(CLAUDE_DIR, 'skills')
+ const oldCommand = join(CLAUDE_DIR, 'commands', 'ai-task.md')
+ const repoSkill = await realpath(dirname(fileURLToPath(import.meta.url)))
+ const entries = await readdir(skillsDir).catch(() => [])
+ const oldSkills = await Promise.all(entries.map((entry) => oldSkillAt({ path: join(skillsDir, entry), repoSkill })))
+ const hasOldCommand = (await lstat(oldCommand).catch(() => null)) !== null
+ const oldCopies = [...oldSkills.filter(Boolean), ...(hasOldCommand ? [oldCommand] : [])]
+ if (oldCopies.length === 0) {
+ return
+ }
+ const backupDir = join(CLAUDE_DIR, 'ai-task-old', String(Date.now()))
+ await mkdir(backupDir, { recursive: true })
+ for (const path of oldCopies) {
+ await rename(path, join(backupDir, basename(path)))
+ console.log(`Moved an old copy of /ai-task (${path}) to ${backupDir}, so the repo's version loads.`)
+ }
+ console.log('')
+}
+
+async function oldSkillAt({ path, repoSkill }) {
+ const real = await realpath(path).catch(() => null)
+ if (!real || real === repoSkill) {
+ return null
+ }
+ const skill = await readFile(join(path, 'SKILL.md'), 'utf8').catch(() => '')
+ return /^name:\s*ai-task\s*$/m.test(skill) ? path : null
+}
+
async function readSettings() {
const raw = await readFile(SETTINGS_PATH, 'utf8').catch(() => '{}')
try {