1<!doctype html> 2<html lang="en"> 3 <head> 4 <meta charset="utf-8" /> 5 <meta name="viewport" content="width=device-width, initial-scale=1" /> 6 <title>GitHub SLOC Counter Guide | OctoCounts</title> 7 <meta name="description" content="Learn how OctoCounts counts source lines of code for public GitHub repositories: files, code, comments, blanks, languages, badges, exports, and API usage." /> 8 <meta name="robots" content="index,follow,max-image-preview:large,max-snippet:-1" /> 9 <link rel="canonical" href="https://octocounts.com/docs/github-sloc-counter" /> 10 <link rel="alternate" type="text/markdown" href="https://octocounts.com/docs/github-sloc-counter.md" /> 11 <meta property="og:type" content="article" /> 12 <meta property="og:site_name" content="OctoCounts" /> 13 <meta property="og:title" content="GitHub SLOC Counter Guide | OctoCounts" /> 14 <meta property="og:description" content="Count source lines of code for public repositories without cloning. Understand SLOC, code lines, comments, blanks, language totals, badges, exports, and API usage." /> 15 <meta property="og:url" content="https://octocounts.com/docs/github-sloc-counter" /> 16 <meta property="og:image" content="https://octocounts.com/og-image.jpg" /> 17 <meta name="twitter:card" content="summary_large_image" /> 18 <meta name="twitter:title" content="GitHub SLOC Counter Guide | OctoCounts" /> 19 <meta name="twitter:description" content="A practical guide to repository SLOC counts, language totals, badges, exports, and the OctoCounts API." /> 20 <meta name="twitter:image" content="https://octocounts.com/og-image.jpg" /> 21 <style> 22 :root { color-scheme: light dark; } 23 * { box-sizing: border-box; } 24 body { max-width: 920px; margin: 40px auto; padding: 0 20px 56px; font: 16px/1.65 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: #1f2328; background: #ffffff; overflow-x: hidden; } 25 nav, .meta, .note { color: #57606a; } 26 h1, h2, h3 { line-height: 1.2; color: #111827; } 27 h1 { font-size: clamp(2rem, 5vw, 3.25rem); letter-spacing: 0; margin: 0 0 16px; } 28 h2 { font-size: 1.45rem; margin: 36px 0 12px; } 29 h3 { font-size: 1.05rem; margin: 24px 0 8px; } 30 a { color: #0969da; } 31 code, pre { background: #f6f8fa; border: 1px solid #d0d7de; border-radius: 6px; } 32 code { padding: 1px 5px; overflow-wrap: anywhere; } 33 pre { max-width: 100%; padding: 14px; overflow: auto; } 34 pre code { overflow-wrap: normal; } 35 table { width: 100%; max-width: 100%; border-collapse: collapse; margin: 18px 0; display: block; overflow-x: auto; } 36 th, td { border: 1px solid #d0d7de; padding: 10px; text-align: left; vertical-align: top; } 37 th { background: #f6f8fa; } 38 .note { border-left: 4px solid #1a7f37; padding: 12px 14px; background: #f6f8fa; } 39 @media (prefers-color-scheme: dark) { 40 body { color: #e6edf3; background: #0d1117; } 41 h1, h2, h3 { color: #f0f6fc; } 42 nav, .meta, .note { color: #8b949e; } 43 code, pre, th, .note { background: #161b22; border-color: #30363d; } 44 td, th { border-color: #30363d; } 45 a { color: #58a6ff; } 46 } 47 </style> 48
48<script type="application/ld+json"> 49 { 50 "@context": "https://schema.org", 51 "@type": "TechArticle", 52 "headline": "GitHub SLOC Counter Guide", 53 "description": "A practical guide to counting source lines of code in public GitHub repositories with OctoCounts.", 54 "datePublished": "2026-06-12", 55 "dateModified": "2026-09-17", 56 "author": { 57 "@type": "Person", 58 "name": "huanglizhuo", 59 "url": "https://github.com/huanglizhuo" 60 }, 61 "publisher": { 62 "@type": "Organization", 63 "name": "OctoCounts", 64 "url": "https://octocounts.com/" 65 }, 66 "mainEntityOfPage": "https://octocounts.com/docs/github-sloc-counter", 67 "speakable": { 68 "@type": "SpeakableSpecification", 69 "cssSelector": ["h1", ".answer"] 70 } 71 } 72 </script>
72 73
73<script type="application/ld+json"> 74 { 75 "@context": "https://schema.org", 76 "@type": "BreadcrumbList", 77 "itemListElement": [ 78 { "@type": "ListItem", "position": 1, "name": "Home", "item": "https://octocounts.com/" }, 79 { "@type": "ListItem", "position": 2, "name": "Docs", "item": "https://octocounts.com/docs" }, 80 { "@type": "ListItem", "position": 3, "name": "GitHub SLOC Counter Guide", "item": "https://octocounts.com/docs/github-sloc-counter" } 81 ] 82 } 83 </script>
83 84
84<script type="application/ld+json"> 85 { 86 "@context": "https://schema.org", 87 "@type": "FAQPage", 88 "mainEntity": [ 89 { 90 "@type": "Question", 91 "name": "What does OctoCounts count?", 92 "acceptedAnswer": { 93 "@type": "Answer", 94 "text": "OctoCounts counts files, total lines, code lines, comment lines, blank lines, and per-language totals for public GitHub repositories." 95 } 96 }, 97 { 98 "@type": "Question", 99 "name": "Do I need to clone the repository?", 100 "acceptedAnswer": { 101 "@type": "Answer", 102 "text": "No. OctoCounts downloads the source archive for a branch, tag, or commit SHA, runs tokei on the extracted files, and caches the result by commit and analysis options." 103 } 104 }, 105 { 106 "@type": "Question", 107 "name": "Does OctoCounts support private repositories?", 108 "acceptedAnswer": { 109 "@type": "Answer", 110 "text": "No. OctoCounts analyzes public repositories only and does not accept source-code uploads or request account access." 111 } 112 } 113 ] 114 } 115 </script>
115 116
116<script type="application/ld+json"> 117 { 118 "@context": "https://schema.org", 119 "@type": "Person", 120 "@id": "https://github.com/huanglizhuo", 121 "name": "huanglizhuo", 122 "url": "https://github.com/huanglizhuo", 123 "sameAs": ["https://github.com/huanglizhuo"], 124 "knowsAbout": ["source lines of code", "code metrics", "tokei", "developer tools"] 125 } 126 </script>
126 127 </head> 128 <body> 129 <nav><a href="/">OctoCounts</a> / <a href="/docs/api">API docs</a> / SLOC guide</nav> 130 <main> 131 <p class="meta">Updated September 17, 2026 · Maintained by <a href="https://github.com/huanglizhuo">huanglizhuo</a></p> 132 <h1>GitHub SLOC Counter Guide</h1> 133 <p class="answer">OctoCounts is a free SLOC counter for public GitHub repositories. Paste a repository URL, optionally pick a branch, tag, or commit SHA, and OctoCounts downloads the source archive, counts every file with tokei, and returns files, total lines, code lines, comments, blanks, and per-language totals. Reports are cached by commit SHA and can be exported as plain text, JSON, or a PNG card, or added to a README as a live badge.</p> 134 <p class="note">OctoCounts is a free source lines of code counter for public repositories. It works from a URL, does not clone git history, and reports files, total lines, code, comments, blanks, and language totals.</p> 135 136 <h2>What OctoCounts Is Best For</h2> 137 <ul> 138 <li>Quickly estimate the size of an unfamiliar open source repository.</li> 139 <li>Compare a dependency, fork, alternative project, branch, tag, or commit.</li> 140 <li>Add a live SLOC badge to a README.</li> 141 <li>Export language counts as text, JSON, or a social share image.</li> 142 <li>Use an API for public repository size checks in internal tools or CI dashboards.</li> 143 </ul> 144 145 <h2>Supported Repository Hosts</h2> 146 <table> 147 <thead> 148 <tr><th>Host</th><th>Support</th><th>Entry point</th></tr> 149 </thead> 150 <tbody> 151 <tr><td>GitHub public repositories</td><td>Web app, API, report pages, badges, Chrome extension, Edge extension, Firefox extension</td><td><code>https://github.com/owner/repo</code></td></tr> 152 <tr><td>Private repositories</td><td>Not supported</td><td>Run <code>tokei</code> locally instead</td></tr> 153 </tbody> 154 </table> 155 156 <h2>How the Count Works</h2> 157 <ol> 158 <li>OctoCounts validates the public repository URL and resolves the requested branch, tag, or commit SHA.</li> 159 <li>The backend downloads a source archive for that exact ref instead of cloning full git history.</li> 160 <li>The extracted source tree is counted with <a href="https://github.com/XAMPPRocky/tokei">tokei</a>.</li> 161 <li>Generated and heavy dependency folders such as <code>.git</code>, <code>node_modules</code>, <code>target</code>, <code>dist</code>, and <code>vendor</code> are ignored by default.</li> 162 <li>The report is cached by repository, commit SHA, tokei version, and analysis options.</li> 163 </ol> 164 <p>For the full counting policy, cache key, exclusions, limitations, and citation format, see the <a href="/docs/methodology">OctoCounts methodology</a>. Agent-readable context is also available in <a href="/llms.txt">/llms.txt</a> and <a href="/llms-full.txt">/llms-full.txt</a>. For measured examples of how the exclusion options change the reported numbers, see the <a href="/research">pilot study on SLOC filtering effects</a>.</p> 165 166 <h2>Metrics Explained</h2> 167 <table> 168 <thead> 169 <tr><th>Metric</th><th>Meaning</th></tr> 170 </thead> 171 <tbody> 172 <tr><td>Files</td><td>Source files detected by language rules.</td></tr> 173 <tr><td>Total lines</td><td>Code lines + comment lines + blank lines.</td></tr> 174 <tr><td>Code lines</td><td>Executable or meaningful source lines after language parsing.</td></tr> 175 <tr><td>Comments</td><td>Line and block comments recognized by the language parser.</td></tr> 176 <tr><td>Blanks</td><td>Whitespace-only lines.</td></tr> 177 <tr><td>Languages</td><td>Detected programming languages and file types, sorted by code lines.</td></tr> 178 </tbody> 179 </table> 180 181 <h2>Examples</h2> 182 <pre><code>https://octocounts.com/?q=https://github.com/huanglizhuo/OctoCounts 183https://octocounts.com/github/huanglizhuo/OctoCounts 184https://octocounts.com/github/huanglizhuo/OctoCounts/tree/main
185https://octocounts.com/compare?left=https://github.com/huanglizhuo/OctoCounts&right=https://github.com/tokio-rs/axum 186https://octocounts.com/diff?repo=https://github.com/huanglizhuo/OctoCounts&base=main&head=22c3647</code></pre> 187 188 <h2>Badges</h2> 189 <p>Use live badges to show repository size in a README:</p> 190 <pre><code>[](https://octocounts.com/github/huanglizhuo/OctoCounts) 191[](https://octocounts.com/github/huanglizhuo/OctoCounts) 192[](https://octocounts.com/github/huanglizhuo/OctoCounts)</code></pre> 193 194 <h2>API</h2> 195 <p>Programmatic users can start an analysis with <code>POST /api/analyze</code>, poll <code>GET /api/jobs/:jobId</code>, and fetch the result with <code>GET /api/reports/:reportId</code>. See the <a href="/docs/api">OctoCounts API docs</a> for request bodies, report fields, and badge routes.</p> 196 197 <h2>Privacy and Scope</h2> 198 <p>OctoCounts analyzes public repositories only. It does not request GitHub account access, does not support private repositories, and does not accept source-code uploads. Cached reports contain public repository statistics only.</p> 199 </main> 200 <!-- Cloudflare Pages Analytics -->
vendor: 99 bytes, line 200
200<script defer src='https://static.cloudflareinsights.com/beacon.min.js' data-cf-beacon='{"token": "
20071af94b0ca2c4711a817b0cb99d9eb5b
vendor: 13 bytes, line 200
200"}'></script>
200<!-- Cloudflare Pages Analytics -->
200<script type="module" src="https://static.cloudflareinsights.com/beacon.min.js/v31edd6df95cf4e85bb4c19e7a9bdbcba1788362987495" integrity="sha512-iIg7k2xntmwu6/uSb5tpc/hySgZc4eoL31yB29W6tJFo2akwjPWcEqnCEdJvGexCL0KEQwVYv5BlowfhVz26hg==" data-cf-beacon='{"version":"2024.11.0","token":"236ed5144ce44b0c9b780a2b74cdf95f","r":1,"spa":2}' crossorigin="anonymous"></script>
vendor: 1 bytes, line 200
200
201<script>(function(){function c(){var b=a.contentDocument||(a.contentWindow&&a.contentWindow.document);if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'a4024f5668f1d2e5',t:'MTc5MDI1ODM2OQ=='};var a=document.createElement('script');a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();</script>
201</body> 202</html>
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.