Skip to content
Development
Hook

Hooks

What ai-devkit runs automatically, and when. A hook is a command Claude Code fires at a fixed moment, without you asking for it.

From plugin
ai-devkit
1.6k28 skills1 hook
Install
$ npx -y skills add codeaholicguy/ai-devkit --agent claude-code

Ships with ai-devkit. Installing the plugin gets these hooks.

What fires, and when

PreToolUse

  • MatchesBash|Edit|Write|AskUserQuestionnode "${CLAUDE_PLUGIN_ROOT}"/hooks/claude-prompt-hook.js
Read hooks/hooks.json

Where it lives

  • hooks/claude-prompt-hook.jsRunsGitHub
    Read the script
    #!/usr/bin/env node
    'use strict';
    
    const fs = require('node:fs');
    const os = require('node:os');
    const path = require('node:path');
    
    const SESSION_ID_KEYS = ['session_id', 'sessionId'];
    const TOOL_NAME_KEYS = ['tool_name', 'toolName'];
    const TOOL_INPUT_KEYS = ['tool_input', 'toolInput'];
    
    function readStdin() {
      if (process.stdin.isTTY) return {};
      try {
        const raw = fs.readFileSync(0, 'utf8').trim();
        return raw ? JSON.parse(raw) : {};
      } catch {
        return {};
      }
    }
    
    function pick(obj, keys) {
      if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return undefined;
      for (const key of keys) {
        if (obj[key] !== undefined && obj[key] !== null && obj[key] !== '') return obj[key];
      }
      return undefined;
    }
    
    function sanitizeSessionId(raw) {
      if (typeof raw !== 'string') return null;
      const clean = raw.replace(/[^a-zA-Z0-9\-]/g, '');
      return clean.length > 0 ? clean : null;
    }
    
    const input = readStdin();
    const rawSessionId = pick(input, SESSION_ID_KEYS) ?? process.env.CLAUDE_SESSION_ID;
    const sessionId = sanitizeSessionId(rawSessionId);
    
    if (!sessionId) {
      process.exit(0);
    }
    
    const toolName = String(pick(input, TOOL_NAME_KEYS) ?? '');
    const toolInput = pick(input, TOOL_INPUT_KEYS) ?? {};
    
    const entry = {
      sessionId,
      toolName,
      toolInput,
      timestamp: new Date().toISOString(),
    };
    
    try {
      const promptsDir = path.join(os.homedir(), '.ai-devkit', 'agent-requests');
      fs.mkdirSync(promptsDir, { recursive: true });
      fs.writeFileSync(path.join(promptsDir, `${sessionId}.json`), JSON.stringify(entry, null, 2), 'utf8');
    } catch {
      // Never disrupt Claude Code
    }
    
    process.exit(0);
    

Read the script before you install anything that runs on your machine. This is the one part of a plugin that acts without being asked.

Ships withai-devkit

The control plane for AI coding agents. AI DevKit gives Claude Code, Codex CLI, Gemini CLI, opencode, Pi, Cursor, GitHub Copilot, Devin, and other coding agents one local-first operating layer: one config, one console, local memory retrieval, cross-agent

Get the whole plugin
Stats
1,634
Stars
253
Forks
Active
Maintenance
TypeScript
Language
Apache-2.0
License
3h ago
Last commit
11mo ago
Created

Repo: codeaholicguy/ai-devkit