Genshijin (原始人)

repository·main·Indexed 42 days ago

https://github.com/interfacex-co-jp/genshijin

A communication optimization tool for Claude Code and other AI agents (Cursor, Windsurf, Cline, Copilot) that reduces token usage by up to 75% by compressing Japanese text into efficient 'caveman-style' formats. It includes genshijin-shrink, an MCP middleware proxy that compresses tool descriptions, and specialized sub-skills for concise commits, PR reviews, and memory file compression.

Tokens
17.3K
Snippets
49
Records
93
Agent score
54%

What's inside Genshijin

  1. Extend support to multi-agent environments

    main

    While genshijin is currently Claude Code specific, caveman supports multiple agents by providing configuration files for each environment:

    • Cursor: .cursor/rules/caveman.mdc
    • Windsurf: .windsurf/rules/caveman.md
    • Cline: .clinerules/caveman.md
    • Copilot: .github/copilot-instructions.md + AGENTS.md
    • Gemini CLI: GEMINI.md + gemini-extension.json
    • Codex: .codex/hooks.json, .codex/config.toml

    For platforms without hook support, use a common activation snippet in rules/caveman-activate.md to enable the mode via a prompt.

  2. Avoid these patterns in commit messages

    main

    To maintain high compression and clarity, genshijin-commit strictly avoids the following:

    • Redundant phrases: Do not use "This commit does...", "I", "We", "Currently", or "Now". The diff makes these obvious.
    • Attribution: Do not use "Requested by [Name]". Instead, use the Co-authored-by trailer.
    • AI Attribution: Never include "Generated with Claude Code" or similar AI markers.
    • Emojis: Do not use emojis unless required by specific project conventions.
    • Redundant Scopes: Do not repeat filenames that are already implied by the <scope>.
  3. Use genshijin-crew subagents for long sessions

    main

    To prevent context exhaustion in long Claude Code sessions, genshijin-crew provides three subagent presets designed to return highly compressed, structured information instead of verbose prose.

    SubagentRoleModel
    genshijin-investigatorRead-only code location identificationHaiku
    genshijin-builder1-2 file surgical editing-
    genshijin-reviewerSeverity-tagged code reviewHaiku

    Why use subagents?

    Standard Claude Explore subagents often return verbose prose (e.g., 2,000 tokens) describing where a function is located. If called repeatedly, this prose consumes the context budget. genshijin-investigator reduces this to a structured format (e.g., 700 tokens).

    Output Contract (SKILL.md)

    Subagents follow a strict output format defined in SKILL.md to ensure results are both human-readable and machine-parsable via regex:

    Format: <path:line> — <symbol> — <≤6 word note>

    Headers for 3+ lines:

    • Defs:
    • Refs:
    • Callers:
    • Tests:
    • Imports:

    Example Output:

    Defs:
    - hooks/genshijin-config.js:81 — `safeWriteFlag` — atomic write w/ O_NOFOLLOW
    
    Callers:
    - hooks/genshijin-mode-tracker.js:33,87
    - hooks/genshijin-activate.js:40
    
    1 def, 2 callers.
  4. Understand caveman skill rules and auto-clarity

    main

    The caveman skill is designed to strip all fluff while preserving technical substance.

    Core Rules

    • Drop: Articles (a, an, the), filler words (just, really, basically, actually, simply), pleasantries (sure, certainly, of course), and hedging.
    • Keep: Exact technical terms, exact error quotes, and unchanged code blocks.
    • Pattern: Follow the structure [thing] [action] [reason]. [next step].

    Auto-Clarity (Safety Mechanism)

    To prevent dangerous misunderstandings, the skill automatically reverts to normal, clear language for:

    • Security warnings.
    • Irreversible action confirmations (e.g., destructive database operations).
    • Complex multi-step sequences where fragments might cause misinterpretation.

    Once the critical information is conveyed, the skill resumes the selected caveman intensity level.

  5. Follow Conventional Commits rules for genshijin-commit

    main

    When using genshijin-commit, the generated messages follow these structural rules:

    Subject Line

    Format: <type>(<scope>): <imperative summary> (where <scope> is optional).

    Allowed Types:

    • feat, fix, refactor, perf, docs, test, chore, build, ci, style, revert

    Constraints:

    • Use imperative mood (e.g., "追加" (Add), "修正" (Fix), "削除" (Remove)). Do not use past tense or polite forms like "追加した" or "追加します".
    • Target length: $\le$ 50 characters (Max limit: 72 characters).
    • No trailing period.
    • Language (Japanese or English) should match the existing repository history (git log).

    Body (Only if necessary)

    Omit the body if the subject line is self-explanatory. Include a body for:

    • Non-obvious "why" (reasons for the change).
    • Breaking changes.
    • Migration warnings.
    • Related Issues/PRs.

    Constraints:

    • Wrap lines at 72 characters.
    • Use - for bullet points (do not use *).
    • Reference issues/PRs at the end using Closes #42 or Refs #17.
  6. When to use expanded descriptions in genshijin-review

    main

    While genshijin-review defaults to ultra-compressed one-liners, it automatically switches to normal paragraph mode (expanded descriptions) for the following specific contexts:

    1. Security Vulnerabilities: CVE-level issues require detailed explanations and reference URLs.
    2. Architectural Disagreements: When challenging the architecture, a one-liner is insufficient; you must provide the underlying reasoning.
    3. Onboarding Context: When reviewing for junior developers, the "why" behind a suggestion must be explained.

    After providing an expanded explanation for these cases, the skill immediately reverts to the compressed one-liner mode for subsequent points.

  7. How genshijin's safety valve works

    main
    To prevent dangerous misunderstandings caused by extreme compression, genshijin includes a 'safety valve' mechanism. When the AI detects a request involving destructive operations (e.g., deleting database tables), it automatically reverts to standard, clear Japanese to ensure the user understands the risks and warnings.
  8. Identify genshijin sub-skill port candidates

    main

    The following sub-skills from caveman are identified as high-value candidates for porting to genshijin to expand its functionality beyond a single core skill:

    • genshijin-commit: Generates Japanese-compatible commits following Conventional Commits (subject $\le$ 50 chars, reason-first).
    • genshijin-review: Provides PR comments in a specific format (e.g., L42: 🔴 バグ: user null。ガード追加。).
    • genshijin-help: Displays a mode intensity table and subcommand list.
    • genshijin-compress: Converts .md files into a 'caveman' format to reduce input tokens by approximately 46% (e.g., optimizing CLAUDE.md).
  9. How genshijin-shrink works as an MCP middleware proxy

    main

    Concept: MCP Middleware Proxy

    genshijin-shrink acts as a stdio middleware proxy positioned between a Claude client (or any MCP client) and an upstream MCP server. Its primary purpose is to reduce token consumption by intercepting and compressing the description fields within JSON-RPC responses.

    How it intercepts tokens

    When an MCP server provides tool metadata via the tools/list RPC, it often includes lengthy English descriptions. For example, a Filesystem MCP server can consume thousands of tokens per session just by listing tool descriptions. genshijin-shrink intercepts these responses and compresses only the prose descriptions while protecting technical identifiers.

    Protection Mechanism

    To ensure that code, URLs, and paths are not corrupted during compression, the proxy uses a sentinel replacement strategy. It identifies protected patterns, replaces them with unique sentinel strings, compresses the remaining prose using regex, and then restores the original tokens.

    Protected patterns include:

    • Fenced code blocks (```...```)
    • Inline code (`code`)
    • URLs (https://...)
    • File paths
    • CONST_CASE identifiers
    • Dotted method calls (object.method())
    • Function calls (function(args))
    • Semantic versioning (1.2.3)

    Implementation Constraints

    • stdio line-buffering: Uses line buffering for both directions to ensure JSON-RPC messages (one per line) are correctly reassembled even if stdin/stdout are partially flushed.
    • Request pass-through: The proxy does not modify request bodies sent to the upstream server.
    • Conservative mutation: It only intervenes in tools/list, prompts/list, and resources/list responses, specifically targeting the description field. It does not mutate tools/call responses to avoid breaking downstream parsing.
    // Protected patterns used by genshijin-shrink
    const PROTECTED_PATTERNS = [
      /```[\s\S]*?```/g,                          // fenced code
      /`[^`\n]+`/g,                               // inline code
      /\bhttps?:\/\/\S+/gi,                       // URLs
      /\b[\w.-]*[\/\\][\w.\/\\\-]+/g,             // paths
      /\b[A-Z][A-Za-z0-9]*(?:_[A-Z][A-Za-z0-9]*)+\b/g, // CONST_CASE
      /\b\w+\.\w+(?:\.\w+)*\(\)?/g,               // dotted.method()
      /[A-Za-z_][A-Za-z0-9_]*\s*\([^)]*\)/g,      // function calls
      /\b\d+\.\d+\.\d+\b/g,                       // semver
    ];
  10. Compare genshijin response efficiency

    main

    genshijin significantly reduces token usage compared to standard AI responses and the caveman mode by utilizing 'Taigen-dome' (noun-ending sentences) and eliminating redundant polite Japanese phrasing.

    Efficiency Metrics (Average across 30 tasks):

    • Standard → caveman: 68% reduction
    • Standard → genshijin: 80% reduction
    • caveman → genshijin: 38% additional reduction

    Key differences in behavior:

    • Information Density: While standard modes provide exhaustive explanations (e.g., explaining what CORS is before solving it), genshijin focuses on direct causes, concise code, and critical check-points.
    • Honesty over Hallucination/Padding: If a prompt is insufficient (e.g., a bug report without code), genshijin will explicitly ask for the code rather than providing generic, unhelpful examples.
  11. Use genshijin-crew subagents for context-efficient tasks

    main

    The genshijin-crew is a set of three subagent presets designed to minimize token consumption in long sessions. Unlike vanilla agents (like Explore or Code Reviewer) that return verbose prose, genshijin-crew agents return highly compressed, structured outputs. This reduces the tool-result injected into the main context by approximately 60%.

    When to use genshijin-crew vs Vanilla agents:

    • Use genshijin-crew if you want the subagent output to consume roughly 1/3 of the tokens compared to vanilla.
    • Use Vanilla agents if you require descriptive prose, architectural explanations, or deep rationale.

    Available Subagents:

    • genshijin-investigator: Locates code definitions, usages, or specific symbols.
    • genshijin-builder: Performs surgical edits on 1-2 files with a clear scope.
    • genshijin-reviewer: Performs diff, branch, or file-level bug reviews.