@carlrannaberg/cclint

中文文档
0.2.10发布于 2025/09/10MITTypeScriptES Module近 30 天下载 2.8万

Claude Code Lint - A comprehensive linting tool for Claude Code projects

原始使用文档
文档目录28 节
  1. Features
  2. Installation
  3. Usage
  4. Basic Linting
  5. Specialized Linting
  6. Report Generation
  7. CI/CD Integration
  8. Symlink Support
  9. SDK/Programmatic Usage
  10. Return Types Explained
  11. Use Cases
  12. What It Checks
  13. Official Claude Code Fields
  14. Agent/Subagent Files (*.md with frontmatter)
  15. Command Files (*.md with frontmatter)
  16. Settings Files (.claude/settings.json)
  17. Documentation (CLAUDE.md/AGENTS.md)
  18. Project Structure Detection
  19. Configuration
  20. Custom Schema Configuration
  21. Examples
  22. GitHub Actions Integration
  23. Pre-commit Hook
  24. Report Generation Script
  25. Exit Codes
  26. Contributing
  27. License
  28. Related Projects

cclint (Claude Code Lint)

npm version License: MIT Node.js Version

A comprehensive linting tool for Claude Code projects that validates agent definitions, command configurations, settings files, and project documentation.

Features

  • Agent/Subagent Linting: Validates frontmatter, tools configuration, and naming conventions
  • Command Linting: Checks slash command definitions and tool permissions
  • Settings Validation: Validates .claude/settings.json hook configurations
  • Documentation Linting: Ensures CLAUDE.md follows best practices and template structure
  • Custom Schema Support: Extend base schemas with Zod for project-specific validation
  • Project Auto-Detection: Automatically finds project root using directory climbing
  • Multiple Output Formats: Console, JSON, and Markdown reports
  • CI/CD Friendly: Configurable exit codes and quiet mode

Installation

# Install globally
npm install -g @carlrannaberg/cclint

# Install as dev dependency
npm install --save-dev @carlrannaberg/cclint

# Use without installing
npx @carlrannaberg/cclint

Usage

Basic Linting

# Lint current project (auto-detects root)
cclint

# Lint specific directory
cclint --root /path/to/project

# Quiet mode (minimal output)
cclint --quiet

# Verbose mode (show all files)
cclint --verbose

Specialized Linting

Lint only specific file types for faster, focused validation:

# Lint only agent definition files
cclint agents

# Lint only command definition files  
cclint commands

# Lint only settings.json files
cclint settings

# Lint only CLAUDE.md context files
cclint context

# Use with options for specialized linting
cclint agents --verbose --follow-symlinks
cclint commands --root /path/to/project --quiet

Report Generation

# Generate JSON report
cclint --format json --output lint-report.json

# Generate Markdown report
cclint --format markdown --output reports/lint-report.md

CI/CD Integration

# Fail on errors only (default)
cclint --fail-on error

# Fail on warnings or errors
cclint --fail-on warning

# Fail on suggestions, warnings, or errors
cclint --fail-on suggestion

# Disable custom schema validation
cclint --no-custom-schemas
# Follow symlinks when discovering files (secure by default)
cclint --follow-symlinks

# Symlinks are NOT followed by default for security
# When enabled, validates that symlink targets remain within project root
# Useful for projects with shared agent/command definitions

SDK/Programmatic Usage

CCLint can be used programmatically in your Node.js applications:

import CClint from '@carlrannaberg/cclint';

// Create linter instance
const linter = new CClint();

// Lint entire project
const summary = await linter.lintProject('./my-project', {
  quiet: true,
  followSymlinks: true  // Enable symlink support
});

// Lint specific file types
const agentResults = await linter.lintAgents('./my-project');
const commandResults = await linter.lintCommands('./my-project');

Return Types Explained

lintProject() returns a LintSummary:

{
  totalFiles: 35,
  validFiles: 24,
  totalErrors: 11,
  totalWarnings: 2,
  totalSuggestions: 0,
  duration: 150,
  results: [...] // Array of all individual file results
}

lintAgents(), lintCommands(), etc. return LintResult[]:

[
  {
    file: '/path/to/agent.md',
    valid: true,
    errors: [],
    warnings: [],
    suggestions: [],
    missingFields: []
  },
  // ... more individual file results
]

Use Cases

  • lintProject(): Full project validation, CI/CD integration, comprehensive reports
  • lintAgents(): Validate only agent definitions, useful for agent-focused tools
  • lintCommands(): Validate only command definitions, useful for command management tools
  • lintSettings(): Validate settings.json, useful for configuration tools

What It Checks

Official Claude Code Fields

cclint validates against the official Claude Code specifications. Any additional fields must be added via custom schema extensions.

Agent/Subagent Frontmatter Fields

Required:

  • name - Agent identifier (lowercase, alphanumeric with hyphens)
  • description - Natural language description of when to invoke

Optional:

  • tools or allowed-tools - Tool access: "*" for all, or array of tool names
  • model - Preferred model: sonnet, opus, haiku, sonnet[1m], opusplan, inherit
  • color - UI color (must be one of: red, blue, green, yellow, purple, orange, pink, cyan)

Command Frontmatter Fields

All fields are optional:

  • description - Command description (defaults to first heading or line from content)
  • allowed-tools - Tools the command can use (string format: "Tool1, Tool2")
  • argument-hint - Hint for command arguments shown in UI
  • model - Model to use (same values as agents)

Agent/Subagent Files (*.md with frontmatter)

  • ✅ Required fields: name, description
  • ✅ Tool configurations and syntax
  • ✅ Color validation (8 valid Claude Code colors: red, blue, green, yellow, purple, orange, pink, cyan)
  • ✅ Naming conventions and filename matching
  • ⚠️ Unknown tools and deprecated fields
  • 💡 Content optimization suggestions

Command Files (*.md with frontmatter)

  • ✅ Frontmatter schema validation
  • ✅ Tool permissions in allowed-tools
  • ✅ Bash command usage validation
  • ✅ File reference patterns
  • ⚠️ Unknown tools and syntax errors
  • 💡 Missing descriptions and argument hints

Settings Files (.claude/settings.json)

  • ✅ JSON syntax and schema validation
  • ✅ Hook configuration structure
  • ✅ Event types and matchers
  • ✅ Command syntax validation
  • ⚠️ Unknown hook events and tools
  • 💡 Configuration optimization suggestions

Documentation (CLAUDE.md/AGENTS.md)

  • ✅ Required sections presence
  • ✅ Document structure validation
  • ✅ Template compliance checking
  • ⚠️ Missing sections and content
  • 💡 Content quality improvements

Project Structure Detection

cclint automatically detects your project root by climbing up directories looking for:

  • .git directory
  • package.json file
  • .claude directory

It then scans for files in common locations:

project-root/
├── .claude/
│   ├── settings.json     # Settings validation
│   ├── agents/           # Agent definitions
│   └── commands/         # Command definitions
├── src/
│   ├── agents/           # Alternative agent location
│   └── commands/         # Alternative command location
├── CLAUDE.md             # Documentation validation
└── AGENTS.md             # Alternative documentation

Configuration

cclint works without configuration by using sensible defaults and auto-detection. For advanced usage, you can:

  1. Specify custom paths with --root
  2. Control output verbosity with --quiet/--verbose
  3. Choose output formats with --format
  4. Set failure thresholds with --fail-on
  5. Create custom schemas with configuration files

Custom Schema Configuration

cclint supports extending the base validation schemas with your own Zod schemas for project-specific requirements.

Configuration Files

cclint looks for configuration in the following files (in order of precedence):

  • cclint.config.js - JavaScript configuration
  • cclint.config.mjs - ES Module configuration
  • cclint.config.ts - TypeScript configuration (requires compilation)
  • .cclintrc.json - JSON configuration
  • .cclintrc.js - JavaScript configuration
  • .cclintrc.mjs - ES Module configuration

JSON Configuration Example

{
  "agentSchema": {
    "extend": {
      "priority": "number",
      "tags": "array",
      "experimental": "boolean"
    }
  },
  "commandSchema": {
    "extend": {
      "timeout": "number",
      "retryCount": "number"
    }
  },
  "rules": {
    "unknownFields": "warning",
    "strict": true,
    "excludePatterns": ["**/legacy/**"]
  }
}

JavaScript Configuration Example

// cclint.config.js
import { z } from 'zod';

export default {
  agentSchema: {
    extend: {
      // Custom fields for agents
      priority: z.number().min(1).max(5).describe('Agent priority level'),
      tags: z.array(z.string()).optional().describe('Categorization tags'),
      experimental: z.boolean().optional().describe('Experimental feature flag'),
      owner: z.string().email().describe('Agent maintainer email')
    },
    customValidation: (data) => {
      const errors = [];
      
      // Custom validation logic
      if (data.experimental && !data.description?.includes('EXPERIMENTAL')) {
        errors.push('Experimental agents must include "EXPERIMENTAL" in description');
      }
      
      if (data.priority > 3 && !data.owner) {
        errors.push('High priority agents must have an owner assigned');
      }
      
      return errors;
    }
  },
  
  commandSchema: {
    extend: {
      timeout: z.number().positive().describe('Command timeout in milliseconds'),
      retryCount: z.number().min(0).max(3).default(0),
      async: z.boolean().optional().describe('Run command asynchronously')
    },
    customValidation: (data) => {
      const errors = [];
      
      if (data.async && !data.timeout) {
        errors.push('Async commands must specify a timeout');
      }
      
      return errors;
    }
  },
  
  settingsSchema: {
    extend: {
      // Custom settings fields
      customHooks: z.record(z.array(z.string())),
      teamSettings: z.object({
        lead: z.string(),
        members: z.array(z.string())
      }).optional()
    }
  },
  
  claudeMdRules: {
    requiredSections: [
      'project overview',
      'setup instructions', 
      'development workflow',
      'testing strategy'
    ],
    customValidation: (content, sections) => {
      const errors = [];
      
      if (!content.includes('## Security')) {
        errors.push('CLAUDE.md must include a Security section');
      }
      
      return errors;
    }
  },
  
  rules: {
    unknownFields: 'error',
    strict: true,
    includePatterns: ['custom-agents/**'],
    excludePatterns: ['**/legacy/**', '**/deprecated/**']
  }
};

TypeScript Configuration Example

// cclint.config.ts
import { z } from 'zod';
import type { CclintConfig } from 'cclint';

const AgentPriority = z.enum(['low', 'medium', 'high', 'critical']);

const config: CclintConfig = {
  agentSchema: {
    extend: {
      priority: AgentPriority,
      team: z.string().min(1),
      version: z.string().regex(/^\d+\.\d+\.\d+$/)
    }
  }
};

export default config;

Schema Override Example

For complete control, you can override the entire schema:

// cclint.config.js
import { z } from 'zod';

export default {
  agentSchema: {
    override: z.object({
      // Completely custom schema
      id: z.string().uuid(),
      name: z.string().min(1),
      version: z.string(),
      config: z.record(z.unknown())
    }).strict()
  }
};

Configuration Options

FieldTypeDescription
agentSchema.extendRecord<string, ZodType>Additional fields for agent frontmatter
agentSchema.overrideZodTypeComplete replacement for agent schema
agentSchema.customValidation(data) => string[]Custom validation function
commandSchema.*Same as agentCustom command schema configuration
settingsSchema.*Same as agentCustom settings schema configuration
claudeMdRules.requiredSectionsstring[]Required sections in CLAUDE.md
claudeMdRules.recommendedSectionsstring[]Recommended sections
claudeMdRules.customValidation(content, sections) => string[]Custom validation
rules.unknownFields'error' | 'warning' | 'suggestion' | 'ignore'How to handle unknown fields
rules.strictbooleanEnable strict mode validation
rules.includePatternsstring[]Additional file patterns to include
rules.excludePatternsstring[]File patterns to exclude

Examples

GitHub Actions Integration

name: Claude Code Lint
on: [push, pull_request]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '18'
      - run: npm install -g @carlrannaberg/cclint
      - run: cclint --fail-on warning

Pre-commit Hook

#!/bin/sh
# .git/hooks/pre-commit
cclint --quiet --fail-on error

Report Generation Script

#!/bin/bash
# scripts/lint-report.sh
mkdir -p reports
cclint --format markdown --output reports/claude-lint-$(date +%Y%m%d).md
echo "Lint report generated in reports/"

Exit Codes

  • 0: Success (no issues above failure threshold)
  • 1: Failure (issues found above failure threshold)

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT

版本与发布记录

@carlrannaberg/cclint 共发布 12 个版本,首次发布于 2025/08/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.10latest2025/09/101.2 年前
0.2.92025/09/051.2 年前
0.2.82025/08/291.2 年前
0.2.72025/08/281.2 年前
0.2.62025/08/281.2 年前
0.2.52025/08/281.2 年前

关于 @carlrannaberg/cclint 的常见问题

@carlrannaberg/cclint 是什么?

Claude Code Lint - A comprehensive linting tool for Claude Code projects

如何安装 @carlrannaberg/cclint?

在项目目录运行 npm install @carlrannaberg/cclint,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 cclint,可以用 npx cclint 直接运行。

@carlrannaberg/cclint 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@carlrannaberg/cclint 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@carlrannaberg/cclint 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@carlrannaberg/cclint 可以商用吗?

@carlrannaberg/cclint 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@carlrannaberg/cclint 的下载量有多少?

根据 npm 官方下载统计,@carlrannaberg/cclint 在 2026/10/09 – 2026/11/07 这 30 天内被下载 27,954 次,日均约 932 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@carlrannaberg/cclint 还在维护吗?

最新版本 0.2.10 发布于 2025/09/10(1.2 年前);至今共发布 12 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/08/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。