This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Claude Code Boost is a TypeScript-based CLI tool that provides intelligent auto-approval hooks for Claude Code. It enhances developer productivity by automatically approving safe development operations while blocking genuinely destructive commands.
The project follows a simple CLI architecture:
- Entry Point:
src/index.ts- Uses Commander.js for CLI structure - Main Command:
src/commands/auto-approve-tools.ts- Core logic for tool approval decisions - Hook Integration: Processes Claude Code PreToolUse hooks via stdin/stdout JSON communication
- AI-Powered Decisions: Falls back to Claude API for complex approval decisions
- Type Safety:
src/types/hook-schemas.ts- Zod schemas for input/output validation - Security Model: Two-tier approval system:
- Fast approval for unambiguously safe tools (Read, LS, Glob, etc.)
- AI-powered analysis for complex operations using
prompts/system-prompt.md
npm run build # TypeScript compilation to dist/
npm run type-check # Type checking without compilation
npm run test # Run test suite with Vitest
npm run test:watch # Watch mode for tests
npm run test:env # Run tests with .env.local filenpm run lint # ESLint checking
npm run lint:fix # Auto-fix linting issues
npm run prettier # Format code with Prettier
npm run prettier:check # Check code formattingnpm run dev # Run CLI with tsx (development mode)
npm run prepublishOnly # Full build + test + lint pipeline# Test the CLI locally (requires ANTHROPIC_API_KEY env var or config.json)
echo '{"session_id":"test","transcript_path":"/tmp/test","tool_name":"Read","tool_input":{"file_path":"/test"}}' | ANTHROPIC_API_KEY=your_key npm run dev auto-approve-tools
# Test with Claude CLI (legacy mode)
echo '{"session_id":"test","transcript_path":"/tmp/test","tool_name":"Read","tool_input":{"file_path":"/test"}}' | npm run dev auto-approve-tools --use-claude-cli
# Install CCB hook to Claude Code settings
npm run build && node dist/index.js install --user # Install to user settings
npm run build && node dist/index.js install --project # Install to project settings
npm run build && node dist/index.js install --project-local # Install to project local settings- Reads JSON input from stdin (Claude Code hook format)
- Parses with Zod schema validation
- Checks fast approval list first (read-only operations)
- Falls back to AI analysis via:
- Claude CLI (default when no API key is configured)
- Anthropic API (when API key is available in config or environment)
- Force CLI mode with
--use-claude-cliflag
- Returns JSON decision:
{"decision": "approve|block|undefined", "reason": "..."}
- Permissive by default - Approves standard development operations
- Context-aware - Uses project knowledge to inform decisions
- Destructive-only blocking - Only blocks genuinely harmful operations (rm -rf /, system wipes)
- Developer trust - Assumes most operations are legitimate development work
By default, CCB fast-approves file write operations (Write, Edit, MultiEdit, NotebookEdit) for developer productivity. To require AI approval for all write operations:
- Edit
src/commands/auto-approve-tools.ts - Comment out the
SAFE_WRITE_TOOLSset and the corresponding logic inshouldFastApprove() - Rebuild with
npm run build
This ensures all write operations go through AI analysis for approval, providing an extra layer of security at the cost of some convenience. The code includes clear comments showing how to re-enable fast approval for write operations if needed.
- Unit tests for approval logic
- Integration tests with actual Claude API calls
- Mock scenarios for edge cases
- Environment variable support for API testing
CCB_CONFIG_DIR- Configuration directory for CCB (defaults to$HOME/.ccb)ANTHROPIC_API_KEY- API key for Anthropic Claude API integration (can also be set in config.json)
CCB uses a config.json file located in the CCB configuration directory ($CCB_CONFIG_DIR or $HOME/.ccb). The config schema includes:
{
"log": boolean, // Enable/disable approval logging (default: true)
"apiKey": string // Anthropic API key (optional, overrides ANTHROPIC_API_KEY env var)
}The configuration is validated using Zod schemas and will show warnings for invalid configurations while falling back to defaults.
You can configure authentication for CCB in two ways:
-
Config file (recommended for persistent setup):
mkdir -p ~/.ccb echo '{"log": true, "apiKey": "sk-your-api-key-here"}' > ~/.ccb/config.json
-
Environment variable (good for temporary use):
export ANTHROPIC_API_KEY=sk-your-api-key-here
Priority order: API key in config > ANTHROPIC_API_KEY environment variable > Claude CLI fallback
Use the install command to automatically configure CCB as a PreToolUse hook in Claude Code settings:
ccb install [options]Location options:
--user: Install to user settings (~/.claude/settings.json)--project: Install to project settings (.claude/settings.json)--project-local: Install to project local settings (.claude/settings.local.json)
Authentication options:
--api-key <key>: Set Anthropic API key (non-interactive)--non-interactive: Skip interactive prompts (for testing/automation)
When run without location or authentication flags, CCB will guide you through an interactive setup:
-
Choose Installation Location:
- User settings (recommended) -
~/.claude/settings.json - Project settings -
.claude/settings.json - Project local settings -
.claude/settings.local.json
- User settings (recommended) -
-
Choose Authentication Method:
- Use Claude CLI directly (recommended for most users)
- Use Anthropic API key for direct API access
-
If Using API Key:
- Get your API key from https://console.anthropic.com/
- API keys should start with "sk-"
# Install with Anthropic API key
ccb install --user --api-key sk-your-api-key-here
# Install for automation (uses Claude CLI by default)
ccb install --project-local --non-interactiveThe installer includes conflict detection and will not overwrite existing PreToolUse hooks. When using --project-local, it automatically configures git to ignore the settings file.
The approval logic is customizable via prompts/system-prompt.md and prompts/user-prompt.md which contain the Claude prompt templates for decision-making. The templates use placeholders:
{{toolName}}- Name of the tool being executed{{toolInput}}- JSON input parameters for the tool
CCB automatically logs all approval decisions to ${CCB_CONFIG_DIR}/approval.jsonl in JSONL format. Each log entry contains:
datetime- ISO timestamp of the decisiontool- Name of the tool that was evaluatedinputs- JSON object of tool input parametersreason- Human-readable reason for the decisiondecision- One of: "approve", "block", or "undefined"cwd- Current working directory when the decision was madesession_id- Claude Code session identifier
The logging system is thread-safe and handles concurrent access gracefully. Log entries are atomic writes to prevent corruption.
- Write tests for all new features unless explicitly told not to
- Run tests before committing to ensure code quality and functionality
- Use
npm run testto verify all tests pass before making commits - Tests should cover both happy path and edge cases for new functionality
Before committing any changes, ensure:
- All tests pass (
npm run test) - Code passes type checking (
npm run type-check) - Code passes linting (
npm run lint) - New features have corresponding tests written