Citing AI-generated code means making clear which tool helped, what it contributed, and how you used or changed its output.
The right format depends on your project, citation style, and institution or publisher, so a clear record of your process is the most useful place to start.
What counts as AI-generated code?
AI-generated code is source code produced in whole or in part by a generative system in response to a prompt or other input.
Examples include a function drafted by a coding assistant, a suggested code completion, a test created from a description, or a debugging change proposed by a chatbot.
Using AI does not always mean accepting a complete block of generated code.
You may adapt a suggestion, combine it with your own work, or use an assistant to explain an error.
Keep track of these distinctions: an accurate acknowledgment describes the assistance actually received rather than implying the tool wrote work it did not produce.
Check the rules before choosing a citation format
There is no single citation format that applies to every AI-assisted coding task.
A course may require disclosure in a submission note, a journal may provide a specific policy, and a software project may prefer an entry in its documentation or commit history.
Rules can differ even within the same organization, so consult the requirements for the particular assignment or publication.
Check whether the rules cover code generation, code completion, debugging help, or all uses of AI tools.
Also look for instructions about permitted tools, required disclosure, and whether prompts or outputs must be submitted.
If the guidance is unclear, ask the instructor, editor, or project maintainer before submitting.
What information should you record?
Capture enough detail that another person can understand what assistance was used.
A practical record can include:
- Tool and provider: Name the AI system and, where relevant, the organization that provides it.
- Date: Note when you generated or received the suggestion, since tools and outputs can change over time.
- Purpose: Describe the task, such as drafting a parsing function, suggesting a test, or explaining a compiler error.
- Contribution: Identify the relevant file, function, or code section, and state whether you used, modified, or rejected the suggestion.
- Prompt or conversation reference: Include it if the applicable rules request it or if it helps document a consequential contribution.
- Verification: Record the review and checks you performed, such as reading the code, running tests, or consulting documentation.
Do not include credentials, private data, or confidential source code in a public citation.
If a prompt contains sensitive information, follow your organization’s data-handling rules and describe the interaction without exposing the material.
How to cite AI-generated code in common settings
Coursework and academic projects
Follow the instructor’s or institution’s required disclosure format.
If no citation style is specified, a transparent note may identify the tool, date, task, and extent of use, provided that this meets the assignment rules.
For example: “I used [tool name] on [date] to suggest an initial version of the input-validation function in validate.py.
I reviewed and modified the suggestion and checked it against the project tests.” Replace the brackets with accurate details; do not claim verification you did not perform.
A citation or acknowledgment does not make otherwise prohibited assistance acceptable.
If a course bans generative AI for a task, citing its use does not override that rule.
Open-source and team software projects
For a shared codebase, document AI assistance where contributors can find it and where project conventions allow.
Depending on the project, that could be a pull request description, a commit message, an issue, or a contributor disclosure.
Explain what changed and what you reviewed, then follow the repository’s contribution and licensing requirements.
Do not assume that generated code is automatically free of licensing concerns or suitable for inclusion.
Review the output, check relevant dependencies and copied material, and follow the project’s normal review process.
A citation records assistance; it does not establish legal ownership or replace code review.
Technical reports and publications
Use the publisher’s current policy for AI tools and code.
Some venues may ask for a methods note, acknowledgment, or disclosure rather than a conventional reference entry.
Describe the tool’s role precisely and ensure the account matches the submitted code.
Where a formal citation style is required, use the style guide’s instructions for software or AI outputs instead of inventing a format.
Example disclosure wording
Adapt a short disclosure to the facts and the rules that apply:
“[Tool name] was used on [date] to suggest [specific contribution].
I reviewed the output and [describe modifications and checks performed].”
For a project note, you could write: “AI assistance: [tool name] suggested test cases for parser.py.
The contributor reviewed and edited the suggestions; the tests were run with the project’s standard test command.” Only include statements that are true.
If the tool generated the final code with little modification, say that plainly.
Citation, similarity checking, and authorship detection are different
A citation documents how AI contributed.
Code similarity or plagiarism tools compare code against other material to identify overlap.
AI authorship classification attempts to estimate whether code may have been generated by AI.
These are different tasks, and results from one should not be treated as results from another.
A detector score is not proof that a person used AI or broke a rule.
Likewise, a low or absent score does not verify that code was written without assistance.
Turnitin states that its AI writing model does not reliably detect code; an AI writing report should not be confused with source-code similarity analysis.
Codespy is an external source-code detector.
If you consider using it, review its current information directly and treat any output as one limited signal rather than a finding of authorship or misconduct.
No detector result replaces a documented process, human review, or the relevant policy.
Make your record useful and proportionate
For a small suggestion, a concise acknowledgment may be enough if the applicable rules permit it.
For substantial generated code, keep a more detailed record: save the relevant prompt or conversation where appropriate, identify the affected code, and note the changes and checks.
Use a version-control commit or review note to connect that record to the code that entered the project.
Before submission, compare your disclosure with the final code and the rules you were given.
Make sure the description is specific, the tool’s role is not overstated, and any required documentation is included in the expected place.
This gives reviewers context without presenting a detector score as proof or a citation as a substitute for permission.