A GitHub Action that counts the lines of code in the repository it lives in and
writes a language breakdown into that repo's README. Runs on a schedule (and on
push to main), needs no Personal Access Token, and never looks at any other repo.
This is a repo-local fork of arhamkhnz/github-code-analyzer. The upstream tool scans every public repo on your account and reports one account-wide total, which needs a broad
repo-scoped PAT. This version counts only the repo it is installed in, using the runner's built-inGITHUB_TOKEN— so there is nothing to set up beyond enabling write permissions for Actions.
[ LANGUAGES BREAKDOWN ]
[ TOTAL LINES OF CODE: 0 ]
Filled in automatically the first time the workflow runs.
This GitHub Action checks out the repository it is installed in, counts its lines of
code with cloc via --vcs=git (so only
git-tracked files count and .gitignore is honored — no node_modules, no build
output), and rewrites the README.md breakdown between two markers. It runs every
Sunday at midnight UTC, on push to main, and on manual dispatch. Because it only
touches this one repo, it authenticates with the runner's built-in GITHUB_TOKEN
and needs no Personal Access Token.
-
Add the Workflow File
Copy theanalyze-code.ymlfile into your repository at:.github/workflows/analyze-code.ymlThen commit and push the changes.
-
Allow Actions to write to the repo
The workflow already declarespermissions: contents: write, which is enough on its own. If your org sets Actions to read-only by default, also flip it at Settings → Actions → General → Workflow permissions → "Read and write permissions". No secret or token is required. -
Trigger the Workflow
- It runs every Sunday at midnight UTC and on push to
main. - To run manually, go to GitHub Actions → Select Workflow → Run Workflow.
- It runs every Sunday at midnight UTC and on push to
-
Wait for Processing
Counting a single repository takes seconds. Once done, yourREADME.mdis updated with the latest lines of code breakdown. -
Ensure Placeholders Are Present
To allow automatic updates, yourREADME.mdmust include the following placeholders:<!-- LANGUAGES BREAKDOWN START -->
[ LANGUAGES BREAKDOWN ]
TypeScript --> 338,462 lines
JavaScript --> 123,742 lines
JSX --> 20,576 lines
PHP --> 5,248 lines
Others --> 9,942 lines
[ TOTAL LINES OF CODE: 497,970 ]
<!-- LANGUAGES BREAKDOWN END -->
The workflow will update the stats between these markers.
*Remove `(STATIC EXAMPLE)` when adding it in your README, as it's just a placeholder. It's included here only to prevent automatic updates in this README.*
### Configure languages
The workflow uses cloc **language names** (not file extensions).
- **HIGHLIGHT_LANGS** → languages shown individually in the README; everything else is grouped under **Others**
- **IGNORE_LANGS** → languages dropped completely (not shown, not counted)
Edit these in `.github/workflows/analyze-code.yml` under the job `env:` block:
```yaml
env:
# Use cloc LANGUAGE NAMES (not extensions). Example: "Vuejs Component" for .vue, "C#" for C#
# HIGHLIGHT_LANGS: show these languages individually; everything else goes to "Others"
HIGHLIGHT_LANGS: "JavaScript,TypeScript,JSX,Vuejs Component,PHP,C#"
# IGNORE_LANGS: drop these languages entirely (not shown and not counted)
IGNORE_LANGS: "JSON,HTML,CSS,SCSS,Sass,Markdown,SVG,XML,YAML,TOML,CSV,Text,Properties"
The workflow counts only git-tracked files and excludes languages using cloc’s own
filter, so totals match cloc’s SUM:
cloc --vcs=git --json --report-file=output/cloc-output.json --exclude-lang="${IGNORE_LANGS}"--vcs=git runs git ls-files under the hood, which is what keeps the count to
this repository's tracked source and honors .gitignore. For a complete list of
language names supported by cloc, see the cloc documentation.
Contributions are welcome! Feel free to fork the repository, submit a PR, or open an issue.