Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

glm-coding

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glm-coding

GLM CLI - AI Code Generator with streaming output

Source
npmnpm
Version
0.4.0
Version published
Weekly downloads
12
71.43%
Maintainers
1
Weekly downloads
 
Created
Source

GLM CLI - AI Code Generator

AI-powered code generation with streaming output. Generate code directly from your terminal with real-time feedback.

Installation Model

GLM CLI is installed globally, but Claude prompts can be installed globally or locally:

┌─────────────────────────────────────────────────────────┐
│  NPM Global Install (once)                              │
│  npm install -g glm-coding                              │
│  → glm command available system-wide                    │
└─────────────────────────────────────────────────────────┘
                         ↓
        ┌────────────────┴────────────────┐
        ↓                                 ↓
┌──────────────────┐            ┌─────────────────────┐
│ Global Setup     │            │ Local Setup         │
│ glm init -g      │            │ glm init            │
│                  │            │                     │
│ ~/.glm/          │            │ {project}/.glm/     │
│ ~/.claude/       │            │ {project}/.claude/  │
└──────────────────┘            └─────────────────────┘

Quick Start

1. Install GLM CLI Globally

npm install -g glm-coding

This installs the glm command system-wide.

2. Choose Your Setup Style

Option A: Global Setup (Shared Across All Projects)

glm init -g

This creates:

  • ~/.glm/config.json - Your API key and settings
  • ~/.glm/instructions/ - Code quality guidelines
  • ~/.glm/profiles/ - Specialized agent profiles
  • ~/.glm/logs/ - Usage statistics
  • ~/.claude/CLAUDE.md - Instructions for Claude Code

Use when: You want one configuration for all projects.

Option B: Local Setup (Per-Project Configuration)

cd your-project
glm init

This creates:

  • {project}/.glm/config.json - Project-specific API key/settings
  • {project}/.glm/instructions/ - Project-specific quality guidelines
  • {project}/.glm/profiles/ - Project-specific profiles
  • {project}/.claude/CLAUDE.md - Project-specific Claude instructions

Use when: Different projects need different API keys, profiles, or quality standards.

Hybrid Approach (Global + Local Override)

# Set up global defaults
glm init -g

# Override in specific projects
cd special-project
glm init

Local settings override global ones. Logs always go to ~/.glm/logs/.

Usage

Generate Code

# Basic usage
glm -q "Create a function to validate emails"

# With profile
glm -q "React user profile component" -p frontend-design

# Save to file
glm -q "REST API client for GitHub" -o client.py -p api-integration

# Pipe input
echo "Parse JSON with error handling" | glm -o parser.py

Available Profiles

ProfileUse CaseExample
defaultGeneral codingglm -q "utility function"
frontend-designUI/UX, React, componentsglm -q "navbar component" -p frontend-design
api-integrationREST, GraphQL, OAuthglm -q "API client" -p api-integration
database-opsSQL, queries, migrationsglm -q "user schema" -p database-ops
web-crawlerWeb scraping, parsingglm -q "scrape prices" -p web-crawler

Options

-q, --query <prompt>      Query prompt (required if no pipe)
-o, --output <file>       Save output to file
-p, --profile <name>      Use specific profile
--no-quality              Disable quality instructions

Commands

glm init                  Initialize local configuration
glm init -g               Initialize global configuration
glm stats                 Show usage statistics (daily)
glm stats --monthly       Show monthly statistics
glm version               Show version
glm help                  Show help

Configuration

Config File Structure

Global: ~/.glm/config.json Local: {project}/.glm/config.json

{
  "apiKey": "your-glm-api-key",
  "apiModel": "glm-4.6",
  "apiBaseUrl": "https://api.z.ai/api/coding/paas/v4/chat/completions",
  "apiPlan": "max",
  "maxRetries": 5,
  "timeout": 120000,
  "debug": false,
  "useQuality": true,
  "verboseLog": true,
  "enableLogging": true
}

Environment Variables (Fallback)

If config.json doesn't have a value, GLM checks environment variables:

export GLM_API_KEY="your-api-key"
export GLM_API_MODEL="glm-4.6"
export GLM_DEBUG="true"

Configuration Priority

  • Local config: {project}/.glm/config.json
  • Global config: ~/.glm/config.json
  • Environment variables: GLM_API_KEY, etc.
  • Default values

Usage Limits and Plans

GLM CLI supports three API plan tiers:

PlanPrompts/5hConcurrentUse Case
Lite~1205Light/hobby use
Pro~6005Regular development
Max~24005Heavy/team use (default)

Note: Each prompt ≈ 15-20 model calls internally.

Setting Your Plan

Edit ~/.glm/config.json:

{
  "apiPlan": "pro"
}

Or set environment variable:

export GLM_API_PLAN="pro"

Monitoring Usage

View 5-hour usage window:

glm stats

Output:

5-Hour Usage Window
────────────────────────────────────────────────────────────────────────────────
Plan: PRO
Limit: 600 prompts per 5 hours
Used:  145 prompts (24.2%)

[█████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 24.2%

Claude Code Integration

When you run glm init (global or local), it automatically:

  • Updates CLAUDE.md with GLM usage guidelines
  • Preserves existing content (only adds/updates GLM section)

Using in Claude Code

The CLAUDE.md section includes:

  • Complexity guidelines (Simple < 50 lines, Medium < 200 lines, Complex > 500 lines)
  • Profile list (default, frontend-design, api-integration, database-ops, web-crawler)
  • Usage example

This helps Claude understand when to suggest using GLM for appropriate tasks.

Usage Statistics

Track API usage with detailed statistics:

# View 5-hour usage + daily stats
glm stats

# View monthly stats
glm stats --monthly

Statistics include:

  • 5-Hour Usage Window: Current usage vs plan limit with progress bar
  • Historical Stats: Daily/monthly aggregated data
  • Profile breakdown: Top 5 profiles used
  • Request counts (total, successful, failed)
  • Token usage (prompt, completion, total)

Log locations:

  • Token stats: ~/.glm/usage.jsonl
  • Chat logs: ~/.glm/logs/chat-*.jsonl

Project Structure

{user-home}/
├── .glm/                    # Global config (if using glm init -g)
│   ├── config.json
│   ├── usage.jsonl          # Token usage statistics (centralized)
│   ├── logs/
│   │   ├── chat-2025-12-01T10-30-45-123Z.jsonl
│   │   ├── chat-2025-12-01T11-15-22-456Z.jsonl
│   │   └── ...              # Per-run chat logs (detailed)
│   ├── instructions/
│   │   └── quality.txt
│   └── profiles/
│       ├── default/
│       ├── frontend-design/
│       ├── api-integration/
│       ├── database-ops/
│       └── web-crawler/
└── .claude/
    └── CLAUDE.md            # GLM section added here

{project}/
├── .glm/                    # Local config (if using glm init)
│   ├── config.json
│   ├── instructions/
│   └── profiles/
└── .claude/
    └── CLAUDE.md

Development

Prerequisites

  • Node.js 18+
  • npm

Setup

git clone https://github.com/your-org/glm-coding.git
cd glm-coding
npm install

Building

npm run build          # Build CLI
npm run dev            # Watch mode
npm run typecheck      # Type check without build
npm run clean          # Clean build output

Testing Locally

# Link package globally
npm link

# Test in a directory
cd /tmp/test
glm init
glm -q "hello world function"

# Unlink when done
npm unlink -g glm-coding

Repository Structure

glm-coding/
├── src/
│   └── cli/              # CLI source code
│       ├── cli.ts        # Entry point & router
│       ├── commands/     # Command implementations
│       │   ├── generate.ts   # Code generation
│       │   ├── init.ts       # Installation
│       │   ├── stats.ts      # Statistics
│       │   ├── help.ts       # Help
│       │   └── version.ts    # Version
│       └── core/         # Core modules
│           ├── glmClient.ts     # API client
│           ├── config.ts        # Config loader
│           ├── instructions.ts  # Quality loader
│           ├── profiles.ts      # Profile loader
│           ├── usageLogger.ts   # Usage logging
│           └── ...
├── templates/            # Installed to ~/.glm/ or {project}/.glm/
│   ├── instructions/
│   │   └── quality.txt
│   └── profiles/
│       ├── default/
│       ├── frontend-design/
│       ├── api-integration/
│       ├── database-ops/
│       └── web-crawler/
├── dist/                 # Build output (gitignored)
├── package.json
├── tsconfig.json
└── tsconfig.cli.json

Making Changes

  • Edit src/cli/ files
  • Run npm run build
  • Test with npm link
  • Commit and push

Publishing

npm version patch  # or minor, major
npm publish

Migration from MCP Server

If you're migrating from the old MCP server version:

# Old MCP installation will be detected
glm init -g

# Remove old MCP server manually
rm -rf ~/.claude/mcp-servers/glm-coding
# Remove "glm-coding" from ~/.claude/mcp.json

Examples

Simple Function

glm -q "Python function to calculate fibonacci"

React Component

glm -q "React card component with image, title, description" \
  -p frontend-design \
  -o components/Card.tsx

API Client

glm -q "REST client for GitHub API with auth, pagination, error handling" \
  -p api-integration \
  -o github_client.py

Database Schema

glm -q "PostgreSQL schema for e-commerce with users, products, orders" \
  -p database-ops \
  -o schema.sql

License

MIT

Support

For issues and questions, visit GitHub Issues.

Keywords

glm

FAQs

Package last updated on 01 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts