Skip to content

creativeprofit22/subclaude

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

subclaude

Use your Claude Max/Pro subscription in Node.js apps. No API key needed.

What is this?

If you have a Claude Max ($200/mo) or Pro ($20/mo) subscription, you're paying for access to Claude. But that subscription only works on claude.ai and the official CLI - you can't use it in your own apps... until now.

subclaude lets you call Claude from your Node.js code using your existing subscription. No separate API billing, no credit card on file at console.anthropic.com.

How it works

Claude's official CLI (claude) handles authentication via OAuth tokens stored locally. This package simply pipes your prompts through the CLI, giving your apps access to your subscription's quota.

Your App → subclaude → Claude CLI → Your Max/Pro Subscription → Claude

Prerequisites

  1. Claude CLI installed:

    npm install -g @anthropic-ai/claude-code
  2. Logged in with your subscription:

    claude
    # Follow the prompts to authenticate

Installation

# From GitHub
npm install github:creativeprofit22/subclaude

# Or clone and link locally
git clone https://github.com/creativeprofit22/subclaude
cd subclaude && npm link

Usage

Basic

import { askClaude } from 'subclaude';

const answer = await askClaude('Explain quantum computing in one sentence');
console.log(answer);
// "Quantum computing uses quantum mechanical phenomena..."

With System Prompt

const response = await askClaude('Write about coffee', {
  systemPrompt: 'You are a haiku poet. Respond only in haiku format.'
});

// Steam rises slowly
// Dark liquid, morning's first friend
// Caffeine awakens

Choose a Model

// Use Opus for complex tasks
const analysis = await askClaude('Analyze this code for security issues...', {
  model: 'opus'
});

// Use Haiku for quick, simple tasks
const summary = await askClaude('Summarize: ...', {
  model: 'haiku'
});

Get Token Usage

const response = await askClaude('Hello!', { fullResponse: true });

console.log(response.result);           // "Hello! How can I help..."
console.log(response.usage?.input_tokens);  // 5
console.log(response.usage?.output_tokens); // 12
console.log(response.total_cost_usd);   // 0.0001 (counted against subscription)

Check CLI Status

import { checkClaude } from 'subclaude';

const status = await checkClaude();

if (!status.installed) {
  console.log('Install CLI: npm install -g @anthropic-ai/claude-code');
} else if (!status.authenticated) {
  console.log('Run "claude" to log in');
} else {
  console.log(`Ready! Plan: ${status.subscriptionType}`); // "max" or "pro"
}

Error Handling

import { askClaude, ClaudeError } from 'subclaude';

try {
  const answer = await askClaude('...');
} catch (error) {
  if (error instanceof ClaudeError) {
    switch (error.code) {
      case 'CLI_NOT_FOUND':
        console.log('Install the Claude CLI first');
        break;
      case 'NOT_AUTHENTICATED':
        console.log('Run "claude" to log in');
        break;
      case 'TIMEOUT':
        console.log('Request timed out');
        break;
      default:
        console.log('Error:', error.message);
    }
  }
}

API Reference

askClaude(prompt, options?)

Send a prompt to Claude and get a response.

Option Type Default Description
systemPrompt string - System prompt to set behavior
model 'sonnet' | 'opus' | 'haiku' CLI default Model to use
timeout number 120000 Timeout in ms
fullResponse boolean false Return full response object

checkClaude()

Check if CLI is installed and authenticated. Returns:

{
  installed: boolean;
  authenticated: boolean;
  subscriptionType?: 'max' | 'pro';
  rateLimitTier?: string;
}

FAQ

Q: Is this against Anthropic's TOS? A: This uses the official Claude CLI exactly as intended. You're just automating what you could do manually in the terminal.

Q: Why not just use the API? A: The API requires separate pay-per-use billing. If you're already paying $200/mo for Max, why pay twice?

Q: Does this work with the free tier? A: No. Free tier doesn't include CLI access. You need Pro ($20/mo) or Max ($100-200/mo).

Q: What about rate limits? A: Your subscription's rate limits apply. Max gets 20x the limits of Pro.

License

MIT

About

Use your Claude Max/Pro subscription in Node.js apps - no API key needed

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors