Welcome to Chapter 2!
In the previous chapter, User Entitlement Context, we learned how to figure out who the user is and what rights they have.
But here is the problem: currently, our logic is just a loose collection of code. The main application (the Command Line Interface or CLI) doesn't know this feature exists yet.
Itβs like writing a great song but never putting it on Spotify. If you don't list it, no one can play it. In this chapter, we will create that listing. We call this the Command Definition.
Modern applications are often built like a puzzle. The main app is the board, and features are the puzzle pieces. To make a piece fit, it needs a specific shape.
We need to define a "Manifest" or an "ID Card" for our Rate Limit feature that tells the main application three things:
To solve this, we define a standard JavaScript object. Let's break down the properties of this object one by one.
First, we tell the system what we are.
const rateLimitOptions = {
// 'local-jsx' means this command renders a visual UI
type: 'local-jsx',
// The unique ID for this command
name: 'rate-limit-options',
// A human-readable explanation
description: 'Show options when rate limit is reached',
// ... more properties coming up
}
local-jsx. This tells the app, "I am not just text; I draw boxes and buttons on the screen." (We will cover this deeply in Local JSX Interface).isEnabled)We don't want just anyone running this command. For example, if a user isn't even logged in, showing them "Rate Limit Options" makes no sense.
The isEnabled function acts like a bouncer at a club.
import { isClaudeAISubscriber } from '../../utils/auth.js'
// ... inside the object
isEnabled: () => {
// If user is not a subscriber, return false (Block access)
if (!isClaudeAISubscriber()) {
return false
}
// Otherwise, come on in!
return true
},
If this function returns false, the command is completely disabled. The application acts like it doesn't exist.
isHidden)Sometimes, a command exists, but we don't want users to type it manually.
The rate-limit-options command is reactive. It only pops up when an error happens (like hitting a limit). We don't want users typing > rate-limit-options manually just for fun.
// ... inside the object
isHidden: true, // Hidden from the "Help" menu
--help. It is an "internal-only" tool.load)This is the most important part for performance.
The code for our menu (the buttons, logic, and text) might be large. We don't want to load all that code when the app starts upβthat would make the app slow. We only want to load it if the rate limit is actually hit.
// ... inside the object
// Only import the file when the command is actually executed
load: () => import('./rate-limit-options.js'),
}
import) when you are hungry (load).How does the application use this definition? Let's visualize the lifecycle.
isEnabled. If true, it registers the command in memory.load() function fires, fetching the heavy code from disk.
Here is how index.ts looks when we put it all together. It serves as the bridge between the main system and our specific feature.
// index.ts
import type { Command } from '../../commands.js'
import { isClaudeAISubscriber } from '../../utils/auth.js'
const rateLimitOptions = {
type: 'local-jsx',
name: 'rate-limit-options',
description: 'Show options when rate limit is reached',
// The Gatekeeper
isEnabled: () => {
if (!isClaudeAISubscriber()) return false
return true
},
// The Visibility
isHidden: true,
// The Lazy Loader
load: () => import('./rate-limit-options.js'),
} satisfies Command
export default rateLimitOptions
By exporting this object, we have successfully "plugged in" our feature.
In this chapter, we learned that a feature needs a Command Definition to exist within the application.
isEnabled) so only subscribers can use it.isHidden) so it doesn't clutter the help menu.load) to keep the app fast.Now that the application knows how to load our feature, we need to design what the user actually sees when it loads.
Next Chapter: Rate Limit Menu UI
Generated by Code IQ