跳到主要内容
知仓学习社ZHICANG

claude-code-skill

Development conventions and architecture guide for the Claude Code CLI repository.

读凭据执行命令联网写文件改身份文件读文件严重 103 · 高危 1798codeaashu/claude-code

它会碰到什么

扫了多少1518 个文本文件,13871 KB
它会碰到什么读凭据执行命令联网写文件改身份文件读文件
命中总数3121 处
命中统计严重 103 · 高 1798 · 中 979 · 低 235
逐条看命中(30 条严重或高危)
  • 严重 docker/entrypoint.sh:10cred-paths
    echo "  Or via docker-compose with a .env file:" >&2
  • 严重 prompts/00-overview.md:11cred-paths
    | 05 | `05-env-and-auth.md` | Set up `.env` file, API key config, OAuth stubs | 01 |
  • 严重 prompts/01-install-bun-and-deps.md:13exec-pipe-to-shell
    curl -fsSL https://bun.sh/install | bash
  • 严重 prompts/05-env-and-auth.md:14cred-paths
    ### Part A: Create `.env` file from the existing code
  • 严重 prompts/05-env-and-auth.md:24cred-paths
    Create a `.env.example` file (or update the existing one if it exists) with ALL discoverable env vars, organized by category, with documentation comments. At mi
  • 严重 prompts/05-env-and-auth.md:53cred-paths
    Create a comment block at the top of `.env.example` explaining how auth works.
  • 严重 prompts/05-env-and-auth.md:93cred-paths
    Don't modify source files yet — just document findings in a comment at the bottom of `.env.example`.
  • 严重 prompts/05-env-and-auth.md:97cred-paths
    1. `.env.example` exists with comprehensive env var documentation
  • 严重 prompts/14-dev-runner.md:99cred-paths
    ### Part D: Create a `.env` loader
  • 严重 prompts/14-dev-runner.md:101cred-paths
    If the dev script doesn't automatically load `.env`, add dotenv support:
  • 严重 prompts/14-dev-runner.md:107cred-paths
    "dev": "dotenv -e .env -- bun scripts/dev.ts"
  • 严重 prompts/14-dev-runner.md:110cred-paths
    Or use Bun's built-in `.env` loading (Bun automatically reads `.env` files).
  • 严重 prompts/14-dev-runner.md:110cred-paths
    Or use Bun's built-in `.env` loading (Bun automatically reads `.env` files).
  • 严重 prompts/14-dev-runner.md:114cred-paths
    1. Set `ANTHROPIC_API_KEY` in `.env`
  • 严重 prompts/14-dev-runner.md:136cred-paths
    4. `.env` variables are loaded
  • 严重 scripts/dev.ts:9cred-paths
    // Bun automatically reads .env files from the project root.
  • 严重 src/commands/commit.ts:32cred-paths
    - Do not commit files that likely contain secrets (.env, credentials.json, etc). Warn the user if they specifically request to commit those files
  • 严重 src/memdir/paths.ts:174cred-paths
    * autoMemoryDirectory: "~/.ssh" and gain silent write access to sensitive
  • 严重 src/memdir/teamMemPaths.ts:104cred-paths
    * ~/.ssh/authorized_keys) would pass a resolve()-based containment check.
  • 严重 src/memdir/teamMemPaths.ts:104cred-paths
    * ~/.ssh/authorized_keys) would pass a resolve()-based containment check.
  • 严重 src/memdir/teamMemPaths.ts:104cred-write
    * ~/.ssh/authorized_keys) would pass a resolve()-based containment check.
  • 严重 src/tools/BashTool/bashSecurity.ts:664persistence
    // like `--amend`, leaving `&& evil` or `> ~/.bashrc` in the remainder.
  • 严重 src/tools/BashTool/bashSecurity.ts:675persistence
    // Attack: `git commit --allow-empty -m 'payload' > ~/.bashrc`
  • 严重 src/tools/BashTool/bashSecurity.ts:1611cred-paths
    *   cat safe.txt \; echo ~/.ssh/id_rsa
  • 严重 src/tools/BashTool/bashSecurity.ts:1611cred-paths
    *   cat safe.txt \; echo ~/.ssh/id_rsa
  • 严重 src/tools/BashTool/bashSecurity.ts:1613cred-paths
    * In bash: ONE cat command reading safe.txt, ;, echo, ~/.ssh/id_rsa as files.
  • 严重 src/tools/BashTool/bashSecurity.ts:1613cred-paths
    * In bash: ONE cat command reading safe.txt, ;, echo, ~/.ssh/id_rsa as files.
  • 严重 src/tools/BashTool/bashSecurity.ts:1614cred-paths
    * After splitCommand normalizes: "cat safe.txt ; echo ~/.ssh/id_rsa"
  • 严重 src/tools/BashTool/bashSecurity.ts:1614cred-paths
    * After splitCommand normalizes: "cat safe.txt ; echo ~/.ssh/id_rsa"
  • 严重 src/tools/BashTool/bashSecurity.ts:1615cred-paths
    * Nested re-parse: ["cat safe.txt", "echo ~/.ssh/id_rsa"] — both segments

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Claude Code — Repository Skill

Project Overview

Claude Code is Anthropic's CLI tool for interacting with Claude from the terminal. It supports file editing, shell commands, git workflows, code review, multi-agent coordination, IDE integration (VS Code, JetBrains), and Model Context Protocol (MCP).

Codebase: ~1,900 files, 512,000+ lines of TypeScript under src/.

Tech Stack

| Component | Technology |

|------------------|------------------------------------------------|

| Language | TypeScript (strict mode, ES modules) |

| Runtime | Bun (JSX support, bun:bundle feature flags) |

| Terminal UI | React + Ink (React for CLI) |

| CLI Parser | Commander.js (@commander-js/extra-typings) |

| API Client | @anthropic-ai/sdk |

| Validation | Zod v4 |

| Linter/Formatter | Biome |

| Analytics | GrowthBook (feature flags & A/B testing) |

| Protocol | Model Context Protocol (MCP) |

Architecture

Directory Map (src/)

| Directory | Purpose |

|------------------|-----------------------------------------------------------------|

| commands/ | ~50 slash commands (/commit, /review, /config, etc.) |

| tools/ | ~40 agent tools (Bash, FileRead, FileWrite, Glob, Grep, etc.) |

| components/ | ~140 Ink/React UI components for terminal rendering |

| services/ | External integrations (API, OAuth, MCP, LSP, analytics, plugins)|

| bridge/ | Bidirectional IDE communication layer |

| state/ | React context + custom store (AppState) |

| hooks/ | React hooks (permissions, keybindings, commands, settings) |

| types/ | TypeScript type definitions |

| utils/ | Utilities (shell, file ops, permissions, config, git) |

| screens/ | Full-screen UIs (Doctor, REPL, Resume, Compact) |

| skills/ | Bundled skills + skill loader system |

| plugins/ | Plugin system (marketplace + bundled plugins) |

| coordinator/ | Multi-agent coordination & supervisor logic |

| tasks/ | Task management (shell tasks, agent tasks, teammates) |

| context/ | React context providers (notifications, stats, FPS) |

| memdir/ | Persistent memory system (CLAUDE.md, user/project memory) |

| entrypoints/ | Initialization logic, Agent SDK, MCP entry |

| voice/ | Voice input/output (STT, keyterms) |

| vim/ | Vim mode keybinding support |

| schemas/ | Zod configuration schemas |

| keybindings/ | Keybinding configuration & resolver |

| migrations/ | Config migrations between versions |

| outputStyles/ | Output formatting & theming |

| query/ | Query pipeline & processing |

| server/ | Server/daemon mode |

| remote/ | Remote session handling |

Key Files

| File | Role |

|---------------------|-----------------------------------------------------|

| src/main.tsx | CLI entry point (Commander parser, startup profiling)|

| src/QueryEngine.ts| Core LLM API caller (streaming, tool-call loops) |

| src/Tool.ts | Tool type definitions & buildTool factory |

| src/tools.ts | Tool registry & presets |

| src/commands.ts | Command registry |

| src/context.ts | System/user context collection (git status, memory) |

| src/cost-tracker.ts| Token cost tracking |

Entry Points & Initialization Sequence

  1. src/main.tsx — Commander CLI parser, startup profiling
  2. src/entrypoints/init.ts — Config, telemetry, OAuth, MDM
  3. src/entrypoints/cli.tsx — CLI session orchestration
  4. src/entrypoints/mcp.ts — MCP server mode
  5. src/entrypoints/sdk/ — Agent SDK (programmatic API)
  6. src/replLauncher.tsx — REPL session launcher

Startup performs parallel initialization: MDM policy reads, Keychain prefetch, feature flag checks, then core init.

Patterns & Conventions

Tool Definition

Each tool lives in src/tools/{ToolName}/ and uses buildTool:

export const MyTool = buildTool({
  name: 'MyTool',
  aliases: ['my_tool'],
  description: 'What this tool does',
  inputSchema: z.object({
    param: z.string(),
  }),
  async call(args, context, canUseTool, parentMessage, onProgress) {
    // Execute and return { data: result, newMessages?: [...] }
  },
  async checkPermissions(input, context) { /* Permission checks */ },
  isConcurrencySafe(input) { /* Can run in parallel? */ },
  isReadOnly(input) { /* Non-destructive? */ },
  prompt(options) { /* System prompt injection */ },
  renderToolUseMessage(input, options) { /* UI for invocation */ },
  renderToolResultMessage(content, progressMessages, options) { /* UI for result */ },
})

Directory structure per tool: {ToolName}.ts or .tsx (main), UI.tsx (rendering), prompt.ts (system prompt), plus utility files.

Command Definition

Commands live in src/commands/ and follow three types:

  • PromptCommand — Sends a formatted prompt with injected tools (most commands)
  • LocalCommand — Runs in-process, returns text
  • LocalJSXCommand — Runs in-process, returns React JSX
const command = {
  type: 'prompt',
  name: 'my-command',
  description: 'What this command does',
  progressMessage: 'working...',
  allowedTools: ['Bash(git *)', 'FileRead(*)'],
  source: 'builtin',
  async getPromptForCommand(args, context) {
    return [{ type: 'text', text: '...' }]
  },
} satisfies Command

Commands are registered in src/commands.ts and invoked via /command-name in the REPL.

Component Structure

  • Functional React components with Ink primitives (Box, Text, useInput())
  • Styled with Chalk for terminal colors
  • React Compiler for optimized re-renders
  • Design system primitives in src/components/design-system/

State Management

  • AppState via React context + custom store (src/state/AppStateStore.ts)
  • Mutable state object passed to tool contexts
  • Selector functions for derived state
  • Change observers in src/state/onChangeAppState.ts

Permission System

  • Modes: default (prompt per operation), plan (show plan, ask once), bypassPermissions (auto-approve), auto (ML classifier)
  • Rules: Wildcard patterns — Bash(git ), FileEdit(/src/)
  • Tools implement checkPermissions() returning { granted: boolean, reason?, prompt? }

Feature Flags & Build

Bun's bun:bundle feature flags enable dead-code elimination at build time:

import { feature } from 'bun:bundle'
if (feature('PROACTIVE')) { /* proactive agent tools */ }

Notable flags: PROACTIVE, KAIROS, BRIDGE_MODE, VOICE_MODE, COORDINATOR_MODE, DAEMON, WORKFLOW_SCRIPTS.

Some features are also gated via process.env.USER_TYPE === 'ant'.

Naming Conventions

| Element | Convention | Example |

|-------------|---------------------|----------------------------------|

| Files | PascalCase (exports) or kebab-case (commands) | BashTool.tsx, commit-push-pr.ts |

| Components | PascalCase | App.tsx, PromptInput.tsx |

| Types | PascalCase, suffix with Props/State/Context | ToolUseContext |

| Hooks | use prefix | useCanUseTool, useSettings |

| Constants | SCREAMING_SNAKE_CASE | MAX_TOKENS, DEFAULT_TIMEOUT_MS|

Import Practices

  • ES modules with .js extensions (Bun convention)
  • Lazy imports for circular dependency breaking: const getModule = () => require('./heavy.js')
  • Conditional imports via feature flags or process.env
  • biome-ignore markers for manual import ordering where needed

Services

| Service | Path | Purpose |

|--------------------|-------------------------------|-----------------------------------|

| API | services/api/ | Anthropic SDK client, file uploads|

| MCP | services/mcp/ | MCP client, tool/resource discovery|

| OAuth | services/oauth/ | OAuth 2.0 auth flow |

| LSP | services/lsp/ | Language Server Protocol manager |

| Analytics | services/analytics/ | GrowthBook, telemetry, events |

| Plugins | services/plugins/ | Plugin loader, marketplace |

| Compact | services/compact/ | Context compression |

| Policy Limits | services/policyLimits/ | Org rate limits, quota checking |

| Remote Settings | services/remoteManagedSettings/ | Managed settings sync (Enterprise) |

| Token Estimation | services/tokenEstimation.ts | Token count estimation |

Configuration

Settings locations:

  • Global: ~/.claude/config.json, ~/.claude/settings.json
  • Project: .claude/config.json, .claude/settings.json
  • System: macOS Keychain + MDM, Windows Registry + MDM
  • Managed: Remote sync for Enterprise users

Guidelines

  1. Read relevant source files before making changes — understand existing patterns first.
  2. Follow the tool/command/component patterns above when adding new ones.
  3. Keep edits minimal and focused — avoid unnecessary refactoring.
  4. Use Zod for all input validation at system boundaries.
  5. Gate experimental features behind bun:bundle feature flags or env checks.
  6. Respect the permission system — tools that modify state must implement checkPermissions().
  7. Use lazy imports when adding dependencies that could create circular references.
  8. Update this file as project conventions evolve.

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。

它属于哪个仓库

星标★ 3,338
本站分层T2
该仓技能数1
原文件路径Skill.md