Manuel B. Garcia

Manuel B. Garcia serves as the Senior Director for Educational Technology and Digital Learning at FEU Institute of Technology, Manila, Philippines. Read More

Contact Info

1607, FEU Tech Building,
P. Paredes St, Sampaloc,
Manila, Philippines
mbgarcia@feutech.edu.ph

Follow Me

How Do Researchers Distinguish Human-Written From AI-Generated Code in a Research Project?

Research code often combines human-written functions, AI-generated suggestions, and subsequent revisions. Learn how to document these contributions accurately without relying on unreliable AI-code detection or confusing code provenance with scientific responsibility.

727
Distinguishing Human and AI-Generated Research Code Guide 727 of 1196
01 · The Question

When Researchers and AI Write Code Together, Who Actually Wrote What?

A researcher writes the initial Python script for analyzing survey data, then asks a generative AI assistant to improve its efficiency. The AI rewrites several functions, introduces a new approach to handling missing values, and recommends additional calculations. The researcher reviews the suggestions, rejects some, modifies others, and integrates the accepted changes into the project.

By the time the analysis is complete, the script contains a mixture of original human-written code, AI-generated code, and functions that have been repeatedly revised by both.

How should researchers distinguish these contributions? Is it necessary to identify the origin of every line, and can anyone reliably determine whether a particular function was written by a human or generated by AI?

02 · The Short Answer

Document Code Provenance Rather Than Trying to Detect AI Authorship From the Code Alone

In Brief

Researchers can distinguish human-written from AI-generated research code by maintaining development records that identify which components were written by researchers, which were generated or substantially modified with AI assistance, and how those components were subsequently reviewed and revised. Version-control history, AI-assistance logs, and links between prompts and accepted code can support this documentation.

However, source code alone generally cannot establish its human or AI origin reliably, particularly after substantial editing. Researchers do not ordinarily need to assign an authorship label to every line. A more defensible approach is to document consequential contributions accurately while maintaining human responsibility for the final research software.

03 · What You Need to Know

Understanding Human and AI Contributions to Research Software

What Does It Mean for Research Code to Be AI-Generated?

AI-generated research code is source code produced by a generative AI system in response to instructions or contextual information. It may consist of a complete script, an individual function, a modification to existing code, or a suggested implementation of an analytical procedure.

However, research programming rarely follows a simple division between code written entirely by humans and code generated entirely by AI.

A researcher might specify the algorithm, request an implementation from AI, correct its errors, and integrate the result into an existing project. Another researcher might write the implementation independently but use AI to explain an error message.

These interactions involve different levels of AI contribution, even though both researchers could reasonably describe their workflows as AI-assisted programming.

For transparency, it is useful to distinguish the origin of a code component from the nature of the assistance involved in developing it.

Why Is the Human-Written Versus AI-Generated Distinction Often Incomplete?

The distinction becomes difficult when code undergoes iterative development.

Consider a function initially generated by AI. A researcher changes its parameters, replaces its calculations, corrects its handling of missing data, and rewrites its documentation. Is the resulting function still AI-generated?

There is no universally accepted numerical threshold at which an AI-generated function becomes human-written. Counting changed lines would not necessarily resolve the question because a small methodological correction can be more consequential than extensive cosmetic rewriting.

A more useful classification describes the development process rather than assigning an artificial percentage of authorship.

Development situation Possible description What should be documented
Researcher writes the implementation independently Human-written code Relevant development and verification records
AI generates a function that is accepted with minimal changes AI-generated, human-reviewed code AI contribution, accepted implementation, and verification
AI generates a function that the researcher substantially revises AI-assisted, human-modified code Original contribution and consequential corrections
Researcher writes code and AI suggests a correction Human-written code with AI-assisted revision Nature and significance of the accepted correction
AI only explains syntax without changing the implementation Human-written code developed with AI assistance Assistance where relevant or required
Several researchers and AI systems iteratively revise a function Collaboratively developed, AI-assisted code Traceable revisions and consequential contributions

These descriptions are practical documentation categories, not standardized legal or research-integrity classifications. Researchers should use terminology that accurately represents the development process.

Can Researchers Identify AI-Generated Code by Examining Its Style?

Not reliably.

AI-generated code may exhibit recognizable stylistic patterns, such as conventional variable names, extensive comments, or standardized function structures. However, human programmers also use these conventions, and AI systems can generate code in many different styles.

Common algorithms and programming idioms further complicate identification. A short function for calculating a mean or sorting observations may look nearly identical regardless of whether it was written by a researcher, copied from documentation, or generated by AI.

Subsequent editing can remove stylistic characteristics that might otherwise suggest a particular origin.

Consequently, researchers should not treat stylistic impressions or unsupported AI-code detection scores as definitive evidence of authorship.

Reliable provenance generally depends on contemporaneous records of how the code was developed.

How Can Git Help Distinguish Human and AI Contributions?

Git can record changes to research software and associate those changes with identifiable commits. This allows researchers to inspect when functions were introduced, modified, or removed.

For example, a commit message might explain that a data-cleaning function was drafted with AI assistance and subsequently corrected to match the study's missing-data protocol.

However, Git does not automatically know whether code was generated by AI. Its author and committer metadata identify configured Git identities, not necessarily the original intellectual source of every line.

Git's history and blame functionality can help locate the revision that introduced particular code, but the interpretation of that revision still depends on the available development documentation.

Researchers should therefore combine version control for AI-generated code changes with descriptive commit messages or a separate AI-assistance log.

Should Every AI-Generated Line Be Labeled?

Usually, no.

Line-by-line labels may appear precise, but they can become misleading when code is repeatedly modified. A function may retain some AI-generated syntax while implementing a researcher-designed algorithm that differs substantially from the original suggestion.

Likewise, a single AI-generated line may introduce a consequential methodological change, while dozens of generated comments may have no effect on the analysis.

Researchers should prioritize the significance of the contribution rather than the number of lines involved.

For relatively simple projects, a project-level statement describing the extent of AI assistance may be sufficient. More complex projects may benefit from function-level documentation or records associated with particular commits.

Where AI-generated code is itself the object of investigation, more granular provenance may be necessary because the origin of specific outputs forms part of the research evidence.

What Should an AI-Assistance Log Record?

A structured development log can document AI contributions without placing repetitive comments throughout the source code.

For consequential interactions, the log may identify:

  • The date and purpose of the AI-assisted coding activity.
  • The AI provider, model identifier, and available version information.
  • The relevant source-code files or functions.
  • The nature of the contribution, such as generation, debugging, refactoring, or test creation.
  • Whether the generated suggestion was accepted, modified, or rejected.
  • The significant human corrections or methodological decisions.
  • The verification procedures applied to the accepted code.
  • The corresponding Git commit or archived release.

When the original instructions materially explain the implementation, researchers may also preserve relevant AI prompts and responses.

The log should distinguish verified information from retrospective recollections. If the exact model or original prompt is unavailable, that limitation should be recorded rather than concealed.

Should Researchers Record Which AI Model Generated Each Component?

Model-level provenance can be useful when different AI systems contribute to separate parts of a project.

For instance, one model may generate preprocessing functions while another suggests statistical analysis code. If the distinction is relevant to an audit or research evaluation, documenting the models separately can clarify the development history.

However, a project does not necessarily require a model identifier beside every function. The appropriate level of detail depends on the significance of the contribution and the research purpose.

Researchers should consider documenting the models used for consequential coding tasks, especially where model behavior itself is being evaluated.

How Should Researchers Handle Code That Has Been Heavily Rewritten?

Substantial human revision does not erase the historical fact that AI contributed to an earlier implementation. At the same time, describing the final code simply as AI-generated may understate the researcher's subsequent work.

The most accurate description may be that the implementation was initially drafted with AI assistance and subsequently revised and verified by the researcher.

Researchers should document the important changes rather than attempt to calculate an unsupported percentage of human or AI authorship.

If the final implementation no longer contains any of the AI-generated code, the earlier interaction may still be relevant to development provenance, particularly if it influenced the chosen algorithm or analytical approach.

Whether that interaction requires disclosure depends on its significance and applicable policies.

Does Code Provenance Determine Scientific Responsibility?

No. The origin of code and responsibility for its use are separate questions.

Code provenance Describes how source code originated, which tools or people contributed to its development, and how it changed over time.
Scientific responsibility Concerns the research team's obligation to evaluate the methods, verify the computations, and justify the results reported in the study.

Researchers cannot establish scientific validity merely by showing that code was written by a human. Human-written code can contain serious errors.

Similarly, AI-generated code is not automatically incorrect. Its suitability depends on whether it accurately implements the intended method and passes appropriate verification.

The question of whether code authorship matters after full verification therefore requires distinguishing scientific reliability from transparency about the development process.

In ordinary research practice, the researchers using the code remain accountable for its analytical consequences.

Does AI-Generated Code Need Different Verification From Human-Written Code?

Both require verification appropriate to their purpose and potential consequences.

AI-generated code may introduce particular review challenges because a researcher can receive a substantial implementation without having constructed each step personally. Plausible explanations accompanying the generated code may also encourage unwarranted confidence.

However, the appropriate response is not to assume that human-written code is trustworthy by default. Research software should be evaluated according to what it does.

Verification may involve reviewing algorithms, checking statistical assumptions, comparing outputs with independently established calculations, and applying unit tests to consequential functions.

When AI helps generate the tests themselves, researchers should assess whether those tests independently evaluate the intended behavior rather than merely reproduce the implementation's assumptions.

What If Multiple Researchers Use AI on the Same Project?

Collaborative research introduces additional provenance questions. Different team members may use different AI systems, prompts, or coding environments.

Without agreed documentation practices, the project may contain AI-assisted components whose development histories are difficult to reconstruct.

Research teams can establish conventions for recording consequential AI assistance, reviewing proposed changes, and linking accepted implementations to identifiable revisions.

The objective is not to monitor every programming interaction. It is to ensure that the team can explain how important analytical components were developed and verified.

These conventions may be especially useful when code is transferred between collaborators or when the original developer is no longer available.

Should Human and AI Contributions Be Disclosed in the Manuscript?

Researchers should distinguish internal provenance documentation from public disclosure.

Internal records may contain detailed information about individual functions, prompts, model versions, and corrections. A manuscript disclosure may instead summarize the purpose and extent of AI assistance.

The appropriate disclosure depends on the journal's current policies, institutional requirements, and the role of AI in the research.

Where AI-generated code is central to the methodology, the methods section or supplementary materials may need to explain how the code was generated, verified, and used.

Researchers should not assume that disclosing AI assistance eliminates the need for verification. Nor should they assume that fully verified code automatically makes its development provenance irrelevant to every disclosure policy.

04 · A Practical Example

Documenting Mixed Human and AI Contributions to a Research Script

Hypothetical Example

A Survey Analysis Developed Through Human and AI Collaboration

A researcher is investigating whether students' engagement with an online learning platform is associated with their academic performance. The analytical workflow contains three Python modules: data preparation, questionnaire scoring, and regression analysis.

Step 1: Identify the original human-written components

The researcher independently develops the data-import and validation functions. These are preserved in the repository with ordinary development records.

Step 2: Record an AI-generated scoring function

An AI assistant generates a function for calculating questionnaire scores. The researcher records the AI model information available at the time and associates the generated implementation with a development commit.

Step 3: Document consequential human corrections

The researcher discovers that the AI-generated function incorrectly handles reverse-scored items. The function is revised, tested against manually calculated expected scores, and committed as a corrected implementation.

Step 4: Record AI-assisted debugging

The researcher independently writes the regression analysis but uses AI to help investigate a software error. The AI suggests a change to a function argument, which the researcher verifies against the statistical package's documentation.

Step 5: Create a concise provenance record

The project documentation identifies the data-preparation module as human-written, the scoring module as AI-assisted and human-modified, and the regression module as human-written with AI-assisted debugging.

Step 6: Verify and preserve the final workflow

The researcher runs the complete analysis in a clean environment, compares the outputs with expected results, and archives the verified code revision with the relevant documentation.

This record does not attempt to assign a percentage of authorship to each module. Instead, it identifies the development activities that matter for understanding the software's provenance.

Another researcher can determine where AI contributed, which changes were made by the researcher, and how the final implementation was verified. The distinction remains informative without implying that the origin of a function determines its scientific reliability.

05 · What Researchers Often Get Wrong

Common Misconceptions About Human and AI Code Contributions

Misconception

AI-Generated Code Can Be Reliably Identified by Its Writing Style

Programming conventions are widely shared, and both humans and AI systems can produce similar implementations. Stylistic resemblance alone is insufficient to establish provenance, especially after code has been edited.

Misconception

Git Automatically Reveals Whether Code Was Written by AI

Git identifies recorded changes and configured commit identities. It does not independently establish whether an implementation originated from a human or an AI system. Accurate provenance requires additional documentation.

Misconception

Every Line Must Be Classified as Human-Written or AI-Generated

Line-level classification is not universally necessary and may become misleading after extensive revision. Function-level or project-level records may provide a more useful account of consequential contributions.

Misconception

Human Editing Automatically Makes AI-Generated Code Entirely Human-Written

Human revision changes the development history but does not necessarily erase the relevance of earlier AI contributions. A description such as AI-assisted and human-modified may more accurately represent the process.

Misconception

Human-Written Code Is More Scientifically Trustworthy by Definition

Human programmers can introduce errors, inappropriate assumptions, and incorrect calculations. Scientific reliability depends on the correctness of the implementation and its verification, not simply on its origin.

Misconception

Documenting AI Contributions Transfers Responsibility to the AI System

Provenance documentation does not remove the research team's obligation to verify the code and justify the analysis. The researchers remain responsible for the computational procedures used to support their findings.

06 · What This Means for You

Use a Proportionate Approach to Documenting Human and AI Code Contributions

Researchers should prioritize records that explain consequential analytical decisions rather than attempting to reconstruct an artificial division of authorship for every line of source code.

The appropriate level of documentation depends on how AI contributed and whether that contribution affects the interpretation, verification, or reproducibility of the research.

A simple decision framework

If AI only explains syntax or programming concepts
Document the assistance according to applicable requirements without automatically classifying the final implementation as AI-generated.
If AI generates a function that is accepted substantially unchanged
Identify the function as AI-generated and human-reviewed, and preserve the relevant verification evidence.
If AI-generated code undergoes substantial human revision
Describe the implementation as AI-assisted and human-modified, with records of consequential corrections.
If AI modifies a statistical or data-processing procedure
Record the proposed change, the researcher's methodological decision, and the verification performed.
If AI-generated code is the subject of the research itself
Preserve sufficiently detailed generation records to identify which outputs came from which models and experimental conditions.

For collaborative projects, establish shared documentation conventions early. A concise AI-assistance log connected to Git revisions may be sufficient for many projects, while studies evaluating AI coding behavior may require more granular records.

Whatever documentation approach is selected, researchers should ensure that the final code can be independently examined and that its analytical behavior is verified.

The objective is to make the research record more informative, not to create an elaborate authorship classification system that contributes little to scientific evaluation.

07 · A Quick Checklist

Before Finalizing the Provenance Record for Research Code

Check whether human and AI contributions are documented accurately:
Identify which consequential code components were generated or substantially modified with AI assistance.
Distinguish AI-generated implementations from human-written code that received minor AI assistance.
Use descriptive Git commits or development records to preserve important changes.
Record the relevant AI tool, model, and purpose of assistance when available and appropriate.
Document consequential human corrections and methodological decisions.
Avoid unsupported claims about AI authorship based solely on coding style or automated detection.
Verify the analytical behavior of all consequential code, regardless of its origin.
Ensure that provenance records do not expose confidential data, credentials, or restricted materials.
Review applicable institutional and journal policies governing AI assistance and disclosure.
08 · Frequently Asked Questions

Frequently Asked Questions About Human-Written and AI-Generated Research Code

Can researchers reliably detect whether code was generated by AI?

Code style alone generally cannot establish AI origin reliably. Similar implementations can be produced by humans and AI systems, and editing can obscure stylistic patterns. Contemporaneous development records provide stronger provenance evidence.

Does Git show which code was written by AI?

Not automatically. Git records revisions and commit metadata but does not independently identify AI-generated content. Researchers can improve traceability through descriptive commit messages and AI-assistance logs.

Should every AI-generated function be labeled in the source code?

Not necessarily. Function-level labels may be useful for consequential contributions, but a structured project-level record can sometimes provide clearer documentation. The appropriate granularity depends on the research purpose and applicable policies.

If I substantially rewrite AI-generated code, is it still AI-generated?

The most accurate description may be that the code was initially AI-generated and subsequently modified by a researcher. There is no universal percentage of editing that determines when code becomes entirely human-written.

Does using AI to debug human-written code make the entire script AI-generated?

No. AI-assisted debugging does not automatically make the entire script AI-generated. Researchers should describe the actual assistance and identify consequential AI-suggested modifications where relevant.

Can human-written code contain the same errors as AI-generated code?

Yes. Both human-written and AI-generated implementations can contain logical, statistical, or computational errors. Verification should evaluate the code's behavior rather than rely on its origin as an indicator of correctness.

Who is responsible when AI-generated research code produces incorrect results?

The researchers who use the code remain responsible for evaluating its suitability and verifying the results they report. Documenting AI assistance does not transfer scientific accountability to the AI system.

Should researchers disclose mixed human and AI code contributions in a manuscript?

Researchers should follow the target journal's current AI disclosure requirements. Where AI materially contributes to analytical procedures, describing the assistance and verification may also be important for methodological transparency.

09 · The Bottom Line

Document How Research Code Was Developed Without Reducing It to an Artificial Authorship Label

The Bottom Line

Researchers can distinguish human-written from AI-generated research code through documented development histories, version-control records, and descriptions of consequential AI contributions and human revisions. They should not rely on coding style or unsupported detection methods to establish authorship.

The most informative record explains what AI contributed, what researchers changed, and how the final implementation was verified. Code provenance strengthens transparency, but the scientific reliability of the analysis ultimately depends on the methods and computations actually used.

10 · Sources and Further Reading

Authoritative Resources on Research Code Provenance and AI-Assisted Development

11 · Cite this Guide

How to Cite This Guide

This guide is intended to be read, shared, and used in research, teaching, and academic work. If you draw on its ideas, explanations, or other content, please acknowledge the source by citing the guide. Doing so gives appropriate credit and helps your readers locate the original resource.

Has the Field Guide helped your research?

If a guide helped clarify a question, inform a research decision, or move your work forward, I would love to hear about your experience. Your story may also help other researchers discover the Field Guide.

Share Your Experience
Takes only a few minutes