Skip to main content
Glama

count_tokens_folder

Count tokens across all text files in a folder, recursively skipping dependency and binary files, to obtain a total token count for a project.

Instructions

Count tokens across all text files in a folder, recursively.

Skips dependency/VCS/build directories (.git, node_modules, .venv, ...)
and binary files (by extension, then a content sniff). Non-UTF-8 text
falls back to UTF-16 (BOM) or cp1252. Returns the sum of per-file counts.

Args:
    folder_path: Absolute path to the folder.
    model: Model or encoding name. Empty uses ANTHROPIC_TOKEN_COUNT_MODEL.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelNo
folder_pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Install Server

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations to lean on, the description discloses key behaviors: skipped dependency/build directories, binary file detection strategy, encoding fallbacks, and the aggregated return value. This is unusually thorough and goes well beyond a simple statement of the operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact and well-organized: a one-sentence summary, followed by behavioral details, then an Args section. Every sentence carries relevant information with no filler or repetition.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a two-parameter tool, the description fully covers inputs, exclusions, encoding handling, and return semantics. Even with an output schema present, the explicit statement that it returns the sum of per-file counts removes any ambiguity about the result.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must do all the work. It explains folder_path must be an absolute path and clarifies the model parameter, including its default env-var behavior. This adds meaningful semantic value beyond the raw schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening sentence names the specific operation: counting tokens across all text files in a folder, recursively. This clearly distinguishes it from sibling tools like count_tokens_file or count_lines_file.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The recursive folder-wide scope strongly implies when to use this tool versus single-file alternatives, but it never explicitly names the alternatives or states when not to use it. The usage context is clear from the description, though exclusions are absent.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/the-phase-space/tokenizer-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server