How size_weight and count_weight Work in the GitHub Readme Stats Language Ranking Algorithm

The language ranking algorithm calculates a comparative score for each programming language by raising the total byte size to the power of size_weight and multiplying it by the repository count raised to the power of count_weight, then sorts the results in descending order.

GitHub Readme Stats generates the popular Top Languages card by analyzing every repository owned by a user and ranking the programming languages detected within them. The anuraghazra/github-readme-stats repository exposes two query parameters—size_weight and count_weight—that allow users to customize how the language ranking algorithm balances raw code volume against repository diversity.

How the Language Ranking Algorithm Processes Repository Data

The algorithm operates in four distinct phases to produce the final language ranking.

First, it fetches every language used across a user’s repositories via a GraphQL query to the GitHub API. Second, it aggregates each language’s total size (bytes of code) and the count of repositories containing that language. Third, it applies the user-supplied weights to generate a comparative score. Finally, it sorts languages by that score and renders the SVG card.

Default Weight Values and Parameter Passing

If a caller omits the parameters, the fetcher applies conservative defaults that prioritize code volume over repository diversity.

In src/fetchers/top-languages.js, the function signature defines the defaults:

const fetchTopLanguages = async (
  username,
  exclude_repo = [],
  size_weight = 1,   // default: size dominates
  count_weight = 0,  // default: repository count ignored
) => { … }

Source: [src/fetchers/top-languages.js](https://github.com/anuraghazra/github-readme-stats/blob/master/src/fetchers/top-languages.js#L58-L66)

The API endpoint in api/top-langs.js extracts these values from the query string and passes them unchanged to the fetcher:

const {
  /* … */
  size_weight,
  count_weight,
  /* … */
} = req.query;

// …later
const topLangs = await fetchTopLanguages(
  username,
  parseArray(exclude_repo),
  size_weight,          // ← passed directly
  count_weight,        // ← passed directly
);

Source: [api/top-langs.js](https://github.com/anuraghazra/github-readme-stats/blob/master/api/top-langs.js#L36-L38)

The Mathematical Formula Behind size_weight and count_weight

After aggregating the raw data into an object containing name, color, size, and count, the algorithm computes a comparative index for each language using exponentiation:

Object.keys(repoNodes).forEach((name) => {
  // comparison index calculation
  repoNodes[name].size =
    Math.pow(repoNodes[name].size, size_weight) *
    Math.pow(repoNodes[name].count, count_weight);
});

Source: [src/fetchers/top-languages.js](https://github.com/anuraghazra/github-readme-stats/blob/master/src/fetchers/top-languages.js#L146-L149)

The formula effectively transforms the raw metrics into a weighted product:

  • Size component: Math.pow(totalBytes, size_weight)
  • Count component: Math.pow(repoCount, count_weight)
  • Final score: Size component × Count component

Languages are then sorted by this final score in descending order:

const topLangs = Object.keys(repoNodes)
  .sort((a, b) => repoNodes[b].size - repoNodes[a].size)
  .reduce((result, key) => {
    result[key] = repoNodes[key];
    return result;
  }, {});

Source: [src/fetchers/top-languages.js](https://github.com/anuraghazra/github-readme-stats/blob/master/src/fetchers/top-languages.js#L151-L156)

Practical Examples: Tuning Your Language Card

1. Default behavior (size only)

curl "https://github-readme-stats.vercel.app/api/top-langs?username=octocat"

This applies size_weight=1 and count_weight=0, ranking languages strictly by total bytes of code.

2. Balanced influence

curl "https://github-readme-stats.vercel.app/api/top-langs?username=octocat&size_weight=0.5&count_weight=0.5"

Setting both weights to 0.5 applies a square-root transformation to both metrics, giving equal influence to code volume and repository diversity.

3. Count-only ranking

curl "https://github-readme-stats.vercel.app/api/top-langs?username=octocat&size_weight=0&count_weight=1"

With size_weight=0, the size component becomes Math.pow(size, 0) = 1, effectively neutralizing code volume so the ranking depends solely on how many repositories contain each language.

4. Embedding in a README

[![Top Languages](
  https://github-readme-stats.vercel.app/api/top-langs?username=octocat&size_weight=0.8&count_weight=0.2
)](https://github.com/octocat)

Adjust the ratio to emphasize your most substantial projects (size_weight closer to 1) or your breadth of technologies (count_weight closer to 1).

Summary

  • The language ranking algorithm in anuraghazra/github-readme-stats calculates a weighted product of total code size and repository count.
  • Default weights (size_weight=1, count_weight=0) prioritize languages with the most bytes of code, ignoring how many repositories contain them.
  • The scoring formula uses Math.pow(size, size_weight) * Math.pow(count, count_weight) to generate the comparative index used for sorting.
  • Tuning the weights allows you to highlight either deep expertise in large projects (high size_weight) or broad polyglot experience (high count_weight).

Frequently Asked Questions

What are the default values for size_weight and count_weight?

The defaults are size_weight=1 and count_weight=0, defined in the fetchTopLanguages function signature in src/fetchers/top-languages.js. This configuration means the ranking depends entirely on the total bytes of code written in each language, while the number of repositories containing that language has no impact on the score.

How can I prioritize languages that appear in many repositories rather than those with the most code?

Set size_weight to 0 and count_weight to 1 (or any positive number). When size_weight is 0, the size component becomes Math.pow(size, 0) = 1, effectively neutralizing the byte count. The ranking then depends solely on Math.pow(count, count_weight), pushing languages that appear across many repositories to the top of the card regardless of how much code is written in them.

Can I use decimal values for size_weight and count_weight?

Yes, decimal values are fully supported and commonly used to create balanced rankings. For example, setting both weights to 0.5 applies a square-root transformation to both metrics (Math.pow(x, 0.5)), which dampens extreme values and gives moderate influence to both code volume and repository diversity. The API passes these values directly to the fetcher without integer constraints.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →