# How to Count Lines of Code: A Complete Overview | LinearB Blog

> Considering using lines of code to measure how productive your dev teams are? Find out how (and when) to count lines of code.

_This is a markdown rendering of a live HTML page on linearb.io, generated for AI/LLM consumption — it is not a markdown-only site. To get the full HTML page instead, request this URL with an explicit `Accept: text/html` header (no wildcard, no markdown preference)._


```json
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    {
      "@type": "ListItem",
      "position": 1,
      "name": "Home",
      "item": "https://linearb.io/"
    },
    {
      "@type": "ListItem",
      "position": 2,
      "name": "Blog",
      "item": "https://linearb.io/blog"
    },
    {
      "@type": "ListItem",
      "position": 3,
      "name": "How to Count Lines of Code: A Complete Overview",
      "item": "https://linearb.io/blog/counting-lines-of-code"
    }
  ]
}
```

[Home](https://linearb.io/)

/

[Blog](https://linearb.io/blog)

/

How to Count Lines of Code: A Complete Overview

# How to Count Lines of Code: A Complete Overview

![Photo of Nabendu Biswas](https://assets.linearb.io/image/upload/c_limit,w_2560/f_auto/q_auto/v1/logo-mark-lg?_a=BAVMn6ID0)

By [Nabendu Biswas](https://linearb.io/blog/counting-lines-of-code#nabendu-biswas)

|

March 26, 2024

![count_lines_of_code_7b70d99b06](https://assets.linearb.io/image/upload/c_limit,w_2560/f_auto/q_auto/v1/count_lines_of_code_7b70d99b06?_a=BAVMn6ID0)

You’ve just gotten word that you may need to lay off some staff soon, and your CEO is asking you to justify the talent and resources in the org. You need solid data to answer that question. 

You could just count lines of code written by each dev. But lines of code won’t show you how your teams are truly performing. It doesn’t matter if you’ve delivered a lot of code if it’s not what the business is asking for. You need a way to show that your whole org is invaluable because they’re delivering features faster and on time. 

Remember, you only get what you measure. So if you’re only measuring lines of code, you’ll only get more lines of code, not necessarily _quality code_ from a predictable and productive engineering org. We like the way Kathryn Koehler, Director of Productivity Engineering at Netflix, puts it: 

In this article, we’ll show you how (and when) to count lines of code, and help you identify the problems that come up from using this metric incorrectly.  

### **Pros and Cons of Counting Lines of Code**

Although counting lines of code are an old practice, they’re not as useful as you may think today. But that doesn’t mean this metric is inherently bad. As with everything, it has its pros and cons.

### **Pro: Shows You Devs Are Actually Working** 

Teams who are writing code are clearly doing something. So by counting lines of code, you may get some takeaway as to whether devs are actually writing code or just looking at memes all day.

### **Con: Doesn’t Indicate Productivity Accurately**

A junior dev may write a function in ten lines, while a senior dev can write it in just three. Does that make the junior more productive? Clearly not. And does that mean the senior dev was distracted all day? Also no. It just means they wrote the function more efficiently.

### **Pro: Could Help You Optimize Your Resources** 

Counting lines of code can show you how dense your project and its individual components are. This way, you can form a good idea of how complex and resource-intensive a task may be.

### **Con: Bloats Your Software** 

If your devs are convinced that lines of code are of utmost importance, they’ll start opting to write suboptimal code. This, in turn, will inflate your measurements, leading to longer PR processes because each review gets longer and longer. This also means you won’t be able to assess resources properly because your files will all be extra inflated.

![Elon Musk copying the Drake meme, where he's refusing an efficientlywritten function and accepting the same function only when it's written with more lines, to show that he likes to count lines of code.](https://assets.linearb.io/uploads/elon-musk-code-1024x649.png)Don’t be like Elon, don’t count lines of code!

### **Pro: Doesn’t Require Special Tools** 

Unlike other engineering benchmarks and metrics, counting lines of code is fairly simple. Most IDEs and even GitHub will automatically tell you how many lines are in a specific file.

### **Con: Creates a Hostile Environment for Devs** 

If teams are always focusing on their total lines of code, they can easily start believing they wrote more code than other teams. This will negatively affect the overall psychology of your engineering org. A little competition can be good, but that shouldn’t be the general atmosphere in your org. 

### **Pro: Works Well for Non-Developers** 

Everyone understands big numbers. So when you’re trying to convey project size and complexity, everyone can understand that writing a thousand lines of code took more effort than writing a hundred.

### **Con: Leads to Stack-Ranking Individual Devs** 

Teams are just that — a group of developers working toward a shared goal. But if you always count lines of code to provide an easy-to-understand metric for your execs, they could start asking you to separate and rank devs based on their individual performance. This means devs will lose sight of the bigger picture, and may even end up turning on their teammates in a never ending game of _who wrote more_. 

### **Pro: Helps Improve Your PR Process** 

When you count lines of code to track PR sizes, your teams can enforce rules for smaller PRs. With smaller, more digestible PRs, your PR process speeds up, and so does your cycle time.

[![Nobody wants to review your huge pull request.](https://assets.linearb.io/uploads/pr-size-get-started-1024x497.png)](https://linearb.io/get-started)Improve your code quality and developer workflow with smaller pull requests. [Get started with your free-forever LinearB account today.](https://linearb.io/get-started)

So it’s clear that counting lines of code isn’t as beneficial as many paint it to be. But again, it’s not all bad — you can still benefit from it if you use it right. So we’ll show you how to count lines of code properly. 

## **Metrics for Counting Lines of Code**

Most people think counting lines of code is as simple as opening their favorite code editor and seeing the lines of code in the project. But this method doesn’t show you how many lines are comments or formatting breaks. This means you won’t actually know how many lines are _actually_ code. 

On top of that, the process of counting raw lines of code is super tedious. You’ll have to go to every source file in the project, check the number in each file, and add all the values. 

![Screenshot of a Vue program with 89 lines of code.](https://assets.linearb.io/uploads/code1.png)To count lines of code, simply open a file and check the number of the last line!

### **Raw Lines of Code**

Even though it’s not the most efficient thing in the world, counting this raw number can still indicate when you might need to refactor something or break it down into smaller parts.

With LinearB, for example, we use this metric as a part of our [high-risk work detection](https://linearb.helpdocs.io/article/1rk0nrp4yd-how-to-handle-high-risk-work). Our platform checks all active branches and notifies you if any have received an update within the last seven days, have less than 50% of new work, and exceed 300 lines.

Lines of code might also indicate the sheer scale of what needs to be reviewed in a pull request. For example, our [WorkerB bot](https://linearb.io/workflow-optimization) uses lines of code to give you more context for your PRs. In fact, lines of code are essential to the adaptive data modeling approach that we use to calculate your [estimated review time](https://linearb.helpdocs.io/article/7d9makf1og-worker-b-estimated-review-time). 

WorkerB’s estimated review time will help reviewers identify which PRs they can handle right away and which ones they’ll have to block off some time for. And when everyone can plan their schedule to handle PRs quickly, your org’s PR process will improve drastically, reducing your overall cycle times and improving your [software delivery predictability](https://linearb.io/platform/predictable-project-delivery)!

In addition to WorkerB, [gitStream](https://linearb.io/platform/gitstream) can provide context to PRs (like [estimated review time](https://docs.gitstream.cm/automations/provide-estimated-time-to-review/)), [automatically approve safe changes](https://docs.gitstream.cm/automations/approve-safe-changes/), or [automatically assign the best reviewer for the job.](https://docs.gitstream.cm/automations/standard/review-assignment/assign-code-experts/) 

These automated programmable workflows help teams move faster, increase quality, and provide a great developer experience–which drives developer productivity.

Want to see it in action? [Schedule a demo today!](https://linearb.io/book-a-demo)

### **Source Lines of Code**

The next step in accurately counting lines of code is to identify a similar metric called source lines of code (SLOC). This metric doesn’t just count lines in a text file — it tries to filter out comments and empty lines.

Consider the _for_ loop below:

```
for(let i=0; i<names.length; i++)
{
console.log(‘Name is ‘ + names[i]);
}
```

This _for_ loop has four lines of code. As you can see, it has two curly brackets, and each one is taking up an entire line, which is typical for JavaScript developers. Surely, these brackets shouldn’t count as two source lines of code, right? SLOC will filter out the two lines of source code from this _for_ loop. 

Source lines of code are more accurate than a raw count, but they still have some built-in uncertainty. So, another approach is to calculate statements.

### **Logical Lines of Code**

To write a program to count logical lines of code, you could use semicolons to check the end of a line rather than using a carriage return.

This strategy will also help eliminate comments, which generally start with // in most languages. So, this will count the number of lines of code perfectly in Java, C++, and other traditional languages.

But semicolons aren’t necessary in some languages, like JavaScript and Python, so you’ll need different methods for different languages. But this can quickly get out of hand if your teams use several languages.

Most programs that count lines of code will include this sort of logic already, so you don’t need to worry about building a custom solution for your team’s needs. Let’s check some out!

## **3 Ways to Count Lines of Code**

Your engineering leaders and devs don’t have to count lines of code manually or create programs to do that. We’ve got three methods your teams and team leaders can use to measure this metric instead.

### **1\. VS Code Counter**

VS Code has a handy extension that does all the heavy lifting for teams who use it. With [VS Code Counter](https://marketplace.visualstudio.com/items?itemName=uctakeoff.vscode-counter), teams can install this right into their IDEs and start tracking immediately. That way, everyone has access from the start, and no one needs to learn any complex terminal commands.

Here are some of the cool features that come with VS Code Counter:

* Counts lines of source code in whole workspaces and directories
* Tracks lines of code in your current file in real time
* Allows teams to configure how it interprets each tracked language with a .JSON file

![The summary of lines of code provided by VS Code Counter.](https://assets.linearb.io/uploads/code2.png)Here’s what vs code counter will show us for our lines of code.

### **2\. Counting Lines of Code Using cloc**

One of the best applications for counting lines of code is [cloc](https://github.com/AlDanial/cloc), a package that’s been around for nearly 20 years. After installing cloc, you can use it with most operating systems. Here, for example, we’re using Ubuntu in a Windows 11 system through Windows Subsystem for Linux.

![A screenshot of cloc showing multiple file's lines of code.](https://assets.linearb.io/uploads/code3.png)If we pick a directory, cloc will return the results of every file within it if possible.

Here are some of the features cloc offers: 

* Runs on any major OS, so teams don’t need to use a certain IDE or OS
* Can count lines of code in various archived and compressed file formats
* Outputs the results in a variety of formats, so teams can get the data they need in nearly any text format

### **3\. Counting Lines of Code Using xargs**

IIf you’re using Linux (or the Linux subsystem for Windows 11), you can simply use the built-in command xargs. This handy tool is a little more complex than our other two methods, as it will involve some complex terminal commands to get the results your teams need.

Here are some other xarg features:

* Comes built-into most OS, including most Linux distros, macOS, and Windows
* Allows teams to chain multiple commands together to get the data they need, so it’s more than just a program to count lines of code

![Screenshot showing how to count lines of code with the xargs command.](https://assets.linearb.io/uploads/code4.png)You can count lines of code using the xargs command!

## **How to Use Lines of Code Correctly**

Yes, knowing how to count lines of code can come in handy in some situations, but it’ll never be enough on its own. It won’t show you what your org is achieving, and it can’t tell you who’s struggling. And actually assigning too much value to this metric will likely lead you to run your org into the ground. 

Instead, you need to get the proper context when you count lines of code with other engineering metrics as part of a [holistic engineering metrics program.](https://linearb.io/resources/engineering-leader-guide-to-building-a-metrics-program) For example, LinearB helps you track how teams are _actually_ performing. It’ll show you where the bottlenecks are and help you [set goals to improve efficiency.](https://linearb.io/resources/engineering-leader-guide-to-goals-and-reporting) 

LinearB also gives you access to two workflow automation tools, WorkerB and [gitStream](https://linearb.io/dev/gitstream). These will help you identify high-risk work, work that needs to be refactored, or work that may create bottlenecks in your pipeline delivery. And with them, you can finally track PRs and branches that start becoming excessively long, so teams can better separate tasks and reduce review time.

With this powerhouse, you’ll know exactly what your teams are working on without relying on lines of code. You’ll also be able to improve your PR process, boosting cycle time as a result.

## Improve developer productivity with LinearB

Find us on

[](https://www.linkedin.com/company/linearb)
[](https://devinterrupted.substack.com/)

## Your next read

[![Cover image for AI ROI comes from measuring engineering outcomes on day one](https://assets.linearb.io/image/upload/c_limit,w_2560/f_auto/q_auto/v1/Blog_AI_ROI_comes_from_measuring_engineering_software_security_2400x1256_2c5eae0862?_a=BAVMn6ID0)](https://linearb.io/blog/kraken-nik-sudan-measure-ai-roi-engineering-outcomes)

Eng. Metrics

[AI ROI comes from measuring engineering outcomes on day one](https://linearb.io/blog/kraken-nik-sudan-measure-ai-roi-engineering-outcomes)

Kraken Engineering Operations Lead Nik Sudan details how to establish day-one data infrastructure to accurately measure AI ROI. Discover why raw token adoption...

[![Cover image for AI is rebuilding software delivery from SDLC to ADLC](https://assets.linearb.io/image/upload/c_limit,w_2560/f_auto/q_auto/v1/Blog_AI_rebuilding_software_delivery_2400x1256_3fd5887e75?_a=BAVMn6ID0)](https://linearb.io/blog/sdlc-to-adlc-agentic-software-delivery-transformation)

Eng. Metrics

[AI is rebuilding software delivery from SDLC to ADLC](https://linearb.io/blog/sdlc-to-adlc-agentic-software-delivery-transformation)

Discover how engineering organizations are transitioning from the traditional SDLC to an Agentic Development Lifecycle (ADLC). Learn why rising token costs...

[![Cover image for 8 million pull requests reveal where engineering productivity breaks down](https://assets.linearb.io/image/upload/c_limit,w_2560/f_auto/q_auto/v1/Blog_8_million_pull_requests_2400x1256_03724bfbb2?_a=BAVMn6ID0)](https://linearb.io/blog/8-million-prs-engineering-productivity)

Eng. Metrics

[8 million pull requests reveal where engineering productivity breaks down](https://linearb.io/blog/8-million-prs-engineering-productivity)

8.1M pull requests reveal the gap between AI adoption and engineering impact, and why code review is the bottleneck blocking real productivity gains.

## Structured data

_Machine-readable metadata (JSON-LD) embedded in the page for search/AI context — not content rendered on the page itself._

```json
{
  "@context": "https://schema.org",
  "@type": "Organization",
  "name": "LinearB",
  "url": "https://linearb.io/",
  "logo": "https://assets.linearb.io/image/upload/v1715628027/logo-mark-lg.svg",
  "description": "LinearB is the engineering productivity platform that helps engineering leaders prove AI is improving throughput without sacrificing delivery confidence, flow efficiency, or developer experience.",
  "sameAs": [
    "https://www.linkedin.com/company/linearb"
  ],
  "award": [
    {
      "@type": "Award",
      "name": "LinearB is a Leader in the 2026 Gartner® Magic Quadrant™ for Developer Productivity Insight Platforms",
      "dateAwarded": "2026",
      "awardedBy": {
        "@type": "Organization",
        "name": "Gartner®"
      }
    },
    {
      "@type": "Award",
      "name": "Great Place to Work Certification",
      "dateAwarded": "2025-2027",
      "awardedBy": {
        "@type": "Organization",
        "name": "Great Place to Work"
      }
    },
    {
      "@type": "Award",
      "name": "America's Best Startup Employers 2025",
      "dateAwarded": "2025",
      "awardedBy": {
        "@type": "Organization",
        "name": "Forbes Magazine"
      }
    }
  ],
  "hasCertification": [
    {
      "@type": "Certification",
      "name": "SOC 1 Type 2"
    },
    {
      "@type": "Certification",
      "name": "SOC 2 Type 2"
    },
    {
      "@type": "Certification",
      "name": "GDPR Compliance certification"
    },
    {
      "@type": "Certification",
      "name": "ISO 27001"
    }
  ]
}
```

```json
{
  "@context": "https://schema.org",
  "@type": "Article",
  "headline": "How to Count Lines of Code: A Complete Overview",
  "url": "https://linearb.io/blog/counting-lines-of-code",
  "author": {
    "@type": "Person",
    "name": "Nabendu Biswas"
  },
  "datePublished": "2022-01-17T16:41:05.000Z",
  "dateModified": "2024-03-26T05:00:00.000Z",
  "image": "https://assets.linearb.io/image/upload/v1720000000/count_lines_of_code_7b70d99b06.png",
  "publisher": {
    "@type": "Organization",
    "name": "LinearB",
    "logo": "https://assets.linearb.io/image/upload/v1777485755/linearb-logo-2026.png"
  },
  "description": "Considering using lines of code to measure how productive your dev teams are? Find out how (and when) to count lines of code.\n"
}
```

## More on linearb.io

### Top navigation

- [Book a Demo](https://linearb.io/book-a-demo)
- [AI Code Reviews — Catch security risks, bugs, and spec mismatches](https://linearb.io/platform/ai-code-reviews)
- [AI & Productivity Insights — See how AI tools affect cycle time and delivery speed](https://linearb.io/platform/ai-developer-productivity-insights)
- [Measure AI Impact — Track AI adoption and tie it to delivery outcomes](https://linearb.io/use-case/measure-ai-impact)
- [MCP Server — Chat with your data to spot patterns and boost output](https://linearb.io/platform/mcp-server)
- [Resource Allocation — Cost initiatives and shape your investment strategy](https://linearb.io/platform/resource-allocation)
- [Cost Capitalization — Capitalize engineering costs with audit-ready reports](https://linearb.io/platform/cost-capitalization)
- [Dev Team Management — Set targets and tie throughput to business outcomes](https://linearb.io/platform/goals-and-reporting)
- [DevOps Workflow Automation — Policy-based PR routing, approvals, and tests](https://linearb.io/platform/ai-workflow-governance)
- [AI Powered Support — Unify AI and human code delivery in one clear view](https://linearb.io/use-case/ai-powered-support)
- [Optimization — Surface friction with feedback and MCP insights](https://linearb.io/platform/developer-experience)
- [Reporting — Spot what's working and what needs attention](https://linearb.io/use-case/measuring-developer-experience)
- [Surveys — Turn developer feedback into actionable signals](https://linearb.io/platform/developer-surveys)
- [Platform overview](https://linearb.io/platform/overview)
- [Register now](https://linearb.io/event/engineering-productivity-gap)
- [Customers](https://linearb.io/customers)
- [Pricing](https://linearb.io/pricing)
- [Why choose LinearB — Explore your data. Measure performance. Act to improve it.](https://linearb.io/why-linearb)
- [APEX framework — The operating model for AI-era engineering teams](https://linearb.io/resources/apex-framework)
- [Anti-FAQ — The questions other vendors won't answer](https://linearb.io/why-linearb/anti-faq)
- [Security — Enterprise-grade compliance and zero code access](https://linearb.io/security)
- [Build vs. buy — The hidden cost of building it yourself](https://linearb.io/resources/build-vs-buy)
- [Dev Interrupted Podcast — Conversations with engineering leaders](https://linearb.io/dev-interrupted/podcasts)
- [Reports & Guides — Deep dives on productivity and delivery](https://linearb.io/resources)
- [Webinars — Expert sessions on productivity and AI](https://linearb.io/resources?category=workshops)
- [Metrics Benchmarks — See how your engineering org stacks up](https://linearb.io/resources/software-engineering-benchmarks-report)
- [Blog — Product updates and practical insights](https://linearb.io/blog)
- [Help Center — Documentation, setup, and support](https://linearb.helpdocs.io)
- [API Docs](https://docs.linearb.io/api-overview)
- [Status](https://www.linearbstatus.com/)
- [Integrations](https://linearb.io/integrations)
- [LinearB Library](https://linearb.io/library)
- [Engineering metrics](https://linearb.io/library/engineering-metrics)
- [Platform engineering](https://linearb.io/library/platform-engineering)
- [Engineering glossary](https://linearb.io/library/engineering-glossary)
- [Developer productivity](https://linearb.io/library/developer-productivity)
- [AI in software development](https://linearb.io/library/ai-in-software-development)
- [Engineering management](https://linearb.io/library/engineering-management)
- [Developer experience](https://linearb.io/library/developer-experience)
- [DevOps](https://linearb.io/library/devops)
- [Engineering operations and the context layer](https://linearb.io/library/engineering-operations)
- [Engineering efficiency](https://linearb.io/library/engineering-efficiency)
- [Software delivery](https://linearb.io/library/software-delivery)
- [Research and data](https://linearb.io/library/engineering-benchmarks-and-research)
- [LinearB is a Leader in the 2026 Gartner® Magic Quadrant™ for Developer Productivity Insight Platforms](https://linearb.io/resources/gartner-magic-quadrant-dpi-platforms-2026)
- [Sign in](https://app.linearb.io/login)
- [Enterprise](https://linearb.io/solutions/enterprise)
- [Contact](https://linearb.io/contact-us)
- [About us](https://linearb.io/about-us)
- [Careers](https://linearb.io/careers)
- [Service agreement](https://linearb.io/services-agreement)
- [Privacy policy](https://linearb.io/privacy-policy)
- [DPA](https://linearb.io/data-processing-agreement)
- [Security FAQ](https://linearb.io/security-faq)
- [Substack](https://devinterrupted.substack.com/)

### Footer

_Additional links from the site footer, not repeated from the top navigation above._

- [GitHub](https://github.com/linear-b)
- [LinkedIn](https://www.linkedin.com/company/linearb)
- [Twitter](https://twitter.com/LinearB_Inc)