<PAGE>
 
                                                                   EXHIBIT 10.45
   

                    STOCK PURCHASE AND LOAN AGREEMENT


     This Stock Purchase, Stock Pledge, and Loan Agreement ("Agreement") is made
as of October 1, 1997, by and between ANNIE'S HOMEGROWN, INC. ("Company") and
Andrew M. Martin ("Key Employee").

                                    RECITALS
                                    --------

     WHEREAS, Key Employee has performed and is expected to continue to
perform valuable services for the Company;

     WHEREAS, the Company granted to Key Employee certain incentive stock
options "(Options") pursuant to the Company's stockholder-approved 1990
Incentive Stock Option Plan;

     WHEREAS, the Options expire on October 1, 1997; and

     WHEREAS, to enable Key Employee to purchase up to Eighty Four Thousand,
Five Hundred Fifty-Two (84,552) shares of the Company's common stock ($.001 par
value) ("Shares") pursuant to the Options, the Company and Key Employee desire
the Company to make a personal loan ("Loan") to Key Employee subject to the
terms and conditions of this Agreement.

                                   AGREEMENT
                                   ---------

     NOW, THEREFORE, in consideration of the covenants, duties, terms, and
conditions set forth in this Agreement, the parties agree as follows:

1 .  Share Purchase.  Subject to the terms and conditions stated in this
     --------------                                                
Agreement, the Company hereby agrees to sell to Key Employee and Key Employee
agrees to purchase 84,552 shares at the price of $0.80 per Share.

2.   Loan.  Subject to the terms and conditions stated in this Agreement, the
     ----                                                                    
Company  hereby agrees to loan Key Employee $67,641.60. The amount of the Loan
is equal to the purchase price of 84,552 Shares at $0.80 per Share.

3.   Use of Proceeds.  Key Employee agrees to use all of the proceeds from the
     ---------------                                                          
Loan to purchase, from the Company, 84,552 Shares at the price of $0.80 per
Share.

4.   Interest.  The outstanding principal amount of the Loan shall bear interest
     -------
("Interest") at the rate of 6.34%, compounded annually, from the date hereof to
the date of payment. This interest rate is equal to the Mid-Term Applicable
Federal Rate as defined in Section 1274(d) of the Internal Revenue Code of 1986,
as amended.

5.   Payment.  Interest on any outstanding principal balance shall be payable
     -------                                                                 
annually on October 1st of each year commencing October 1, l998, subject to (i)
acceleration of payment under the circumstances described below in Section 8 of
this Agreement, and (ii) payment by the Company under Section 6 of this
Agreement.  The outstanding principal balance of the Loan, ("Principal Amount"),
shall be due and payable in full on October 1, 2002 (the "Maturity Date"),
subject to (i) acceleration of payment on termination of
<PAGE>
 
employment under the circumstances described below in Section 8 of this
Agreement, and (ii) the reductions provided under Section 6 of this Agreement.

6.     Payment of Interest: Reduction of Principal Amount.
       -------------------------------------------------- 

       6.1.  Payment of Interest.  If, as of September 30 of each year, Key
             -------------------                                           
Employee is still employed with the Company, the Company agrees to pay, on Key
Employee's behalf, all Interest associated with the Loan.  Any Interest paid by
the Company on Key Employee's behalf will not be distributed to Key Employee
but, rather, will be automatically applied against Key Employee's Interest
payment obligations under this Agreement.  Any Interest paid by the Company on
Key Employee's behalf will be deemed to be additional compensation income to Key
Employee.

       6.2.  Reduction of Principal Amount.  The Company agrees to reduce the
             -----------------------------                                   
Principal Amount as follows:

             (a) If, as of September 30, 1998, Key Employee is still employed by
the Company, the Company agrees to forgive $16,910.40 of the Principal Amount;

             (b) If, as of September 30, 1999, Key Employee is still employed by
the Company, the Company agrees to forgive an additional $16,910.40 of the
Principal Amount;

             (c) If, as of September 30, 2000, Key Employee is still employed by
the Company, the Company agrees to forgive an additional $16,910.40 of the
Principal Amount;

             (d) If, as of September 30, 2001, Key Employee is still employed by
the Company, the Company agrees to forgive an additional $16,910.40 of the
Principal Amount;

             (e) If, as of September 30, 2002, Key Employee is still employed by
the Company, the Company agrees to forgive the remaining $16,910.40 of the
Principal Amount.

       It is the parties intention that, if Key Employee continues to be
employed by the Company as of September 30, 2002, the Principal Amount will be
completely forgiven.
<PAGE>
 
       6.3.  Change in Control.  In the event that a single person or entity
             -----------------                                              
(other than the current shareholders of the Company) acquires more than 50% of
the outstanding stock of the Company, then:

             (a) The full amount of the Principal Amount not yet paid plus all
accrued interest thereon, will become due and payable on either of such events.

             (b) The payment of interest and reduction in Principal Amount
provisions of Sections 6.1 and 6.2 of this Agreement will also be accelerated
and the Shares will be released from the Pledge as provided in Section 7.

7.     Pledge of Stock.
       --------------- 

       7.1.  Pledged Shares. Key Employee's obligations under this Agreement are
             --------------
secured by the Shares, and Key Employee hereby grants the Company a security
interest in the Shares (the "Pledged Shares"). The foregoing security interest
shall constitute a first priority interest to secure the payment of the
Principal Amount as such amount is reduced by Section 6 of this Agreement. All
certificates representing the Shares, if any shall have been issued, shall be
fully endorsed in blank by Key Employee and delivered by Key Employee to the
Company.

       7.2.  Rights of the Company as Secured Party.  The Company shall have all
             --------------------------------------                             
rights and remedies set forth in this Agreement and all other rights of a
secured party at law or in equity.

       7.3.  Rights Regarding Pledged Shares.  The Company has the right to
             -------------------------------                               
deliver any or all of the Pledged Shares to any person, to have any or all of
the Pledged Shares registered in its name or in the name of any other person,
and Key Employee irrevocably appoints the Company its attorney-in-fact
authorized at any time during the term of this Agreement to take any actions or
exercise any rights available to the Company under this Agreement.

       7.4.  Voting Rights.  Key Employee hereby grants the Company the right to
             -------------                                                      
vote the Pledged Shares until either Key Employee makes full payment of the
Principal Amount and any applicable Interest or the Principal Amount is
completely forgiven pursuant to Section 6.2 of this Agreement.

       7.5.  Key Employee's Representations Regarding Shares.  Key Employee
             -----------------------------------------------               
represents that, as of the date of this Agreement, Key Employee has not taken
any action that would result in the Pledged Shares being subject to any adverse
claims, liens, or encumbrances (other than the pledge under this Agreement),
and, to his knowledge, there are no adverse claims, liens, or encumbrances on
the Pledged Shares as of the date of this Agreement.
<PAGE>
 
       7.6.  Release of Security. As the Principal Amount is reduced pursuant to
             -------------------
Section 6, Shares (at a value of $0.80/Share for this purpose) will be released
from the pledge to Key Employee, i.e., 20% of the Shares after one (1) year, an
additional 20% after two (2) years, an additional 20% after three (3) years, an
additional 20% after (4) years, and the balance after five (5) years of
employment. Upon full payment of the Principal Amount and any applicable
Interest or complete forgiveness of the Principal Amount pursuant to Section
6.2 of this Agreement, the Company shall cause the Shares representing the
balance of the Pledged Shares to Key Employee to be registered on the books of
the Company's transfer agent.

       7.7.  Remedies Related to Collateral.  Upon an Event of Default (as
             ------------------------------                               
defined in Section 11 of this Agreement), the Company may, in its sole
discretion and with or without further notice to Key Employee (in addition to
all rights or remedies available at law or equity or otherwise): (i) register
the Pledged Shares in the name of the Company or in any such name as the
Company may decide, and (ii) exercise any rights provided to a secured party
under the applicable commercial code.

8.     Termination of Employment.  In the event that Key Employee ceases to be
       -------------------------                                              
employed by the Company, the Company may purchase the Shares sold to Key
Employee as provided in this section.

       8.1.  Termination of Employment Before July 29, 1999.  In the event of
             ----------------------------------------------                  
termination of Key Employee's employment with the Company before September 30,
2002, the Company shall be entitled to buy back from Key Employee, Shares
purchased pursuant to the terms of this Agreement, at a price equal to $0.80
per Share plus 140% of interest accrued and not yet forgiven on the Loan, as
follows:

             (a)  If Key Employee's employment is terminated before September
30, 1998, the Company will be entitled to buy back from key Employee all of the
Shares purchased pursuant to this Agreement;

             (b)  If Key Employee's employment is terminated on or after
September 30, 1998 but before September 30, 1999, the Company will be entitled
to buy back from Key Employee 67,642 Shares purchased pursuant to this
Agreement;

             (c)  If Key Employee's employment is terminated on or after
September 30, 1999 but before September 30, 2000, the Company will be entitled
to buy back from Key Employee 50,731 Shares purchased pursuant to this
Agreement;

             (d)  If Key Employee's employment is terminated on or after
September 30, 2000 but before September 30, 2001, the Company will be entitled
to buy back from Key Employee 33,821 Shares purchased pursuant to this
Agreement;

             (e)  If Key Employee's employment is terminated on or after
September 30, 2001 but before September 30, 2002, the Company will be entitled
to buy back from Key Employee 16,910 Shares purchased pursuant to this
Agreement.
<PAGE>
 
      8.2.  Company's Election Not to Buy Back Shares.  In the event that
            -----------------------------------------                    
the Company elects not to buy back Key Employee's Shares pursuant to the terms
of Section 8.1 of this Agreement, Key Employee may either (i) obtain title to
the Pledged Shares and a release of the Company's security interest in the
Pledged Shares by making full payment of the Principal Amount and any
applicable Interest within 45 days of the termination date, or (ii) sell some
or all of the Shares to the Company for the price of $0.80 per Share (plus
accrued interest) in repayment of the Principal Amount and any applicable
Interest. The Company will be obligated to purchase the Shares from Key
Employee pursuant to this Section 8.2 if the Company elects not to purchase the
Shares pursuant to Section 8.1 of this Agreement and Key Employee elects to
sell the Shares back to the Company pursuant to the terms of this Section 8.2.

      8.3.  Termination of Employment On or After September 30, 2002 or Before
            ------------------------------------------------------------------
September 30, 2002 for Other Than Good Cause.  In the event of termination of
--------------------------------------------                                 
Key Employee's employment with the Company on or after September 30, 2002 for
any reason whatsoever, or in the event that the Company terminates Key
Employee's employment before September 30, 2002 for other than Good Cause (as
defined below), the Company will not be entitled to buy back the Shares
purchased by Key Employee pursuant to this Agreement other than as provided in
Section 8.4 of this Agreement. Notwithstanding the foregoing, the parties may
enter into a subsequent agreement whereby the Company agrees to purchase Shares
held by Key Employee.

            As used herein, the term "Good Cause" shall mean (i) any act or
omission of gross negligence, willful misconduct, dishonesty, or fraud by Key
Employee in the performance of his duties, (ii) the failure or refusal of Key
Employee to perform the duties or to render the services assigned to him from
time to time, (iii) the charging or indictment of Key Employee in connection
with a felony or any misdemeanor involving dishonesty or moral turpitude, (iv)
the material breach by Key Employee of his fiduciary duty or duty of trust to
the Company, (v) death of Key Employee, or (vi) voluntary termination of
employment by Key Employee.

      8.4.  Principal Amount and Interest in the Event of Termination.  In the
            ---------------------------------------------------------         
event the Company exercises its right to buy back the Shares from Key Employee
pursuant to Section 8.1 of this Agreement, any outstanding Principal Amount and
any applicable Interest will be immediately due and payable and shall be
applied against amounts due to Key Employee for purchase of Shares. In the
        -------
event that the Company terminates Key Employee's employment before September
30, 2002 for other than Good Cause, Key Employee may either (i) obtain title to
the Pledged Shares and a release of the Company's security interest in the
Pledged Shares by making full payment of the Principal Amount and any
applicable interest within 45 days of the termination date, or (ii) sell Shares
to the Company (and the Company agrees to purchase the Shares) for the price of
$0.80 per Share (plus accrued interest) in repayment of the Principal Amount
and any applicable Interest.
<PAGE>
 
9.     Arbitration.  If a dispute arises between the Company and Key Employee
       -----------                                                           
concerning this Agreement, the disputed matter shall be submitted to arbitration
in the City of San Francisco, California, in accordance with the commercial
arbitration rules of the American Arbitration Association ("AAA Rules").  Any
judgment upon the award rendered by the arbitrators may be entered in any court
having jurisdiction thereof.  The arbitrators shall have the authority to grant
any equitable and legal remedies that would be available in any judicial
proceeding instituted to resolve the disputed matter.  The arbitrators shall
apply the laws of the State of California in making any determination hereunder.
Notwithstanding anything to the contrary which may now or hereafter be contained
in the AAA Rules, the parties agree any such arbitration shall be conducted
before a panel of three arbitrators who shall be compensated for their services
at a rate to be determined by the American Arbitration Association in the event
the parties are not able to agree upon their rate of compensation.  Each party
shall have the right to appoint one arbitrator (to be appointed within 20 days
of the notice of a dispute to be resolved by arbitration hereunder), and the two
arbitrators so chosen shall mutually agree upon the selection of the third,
impartial arbitrator.  The majority decision of the arbitrators will be final
and conclusive upon the parties hereto.

10.    Payments. Any payments due from Key Employee under this Agreement shall
       -------- 
be made payable to Annie's Homegrown, Inc. and shall be sent to the Company's
offices at 180 Second Street, Suite 202, Chelsea, MA 02150, Attention: Neil
Raiff.

11.    Event of Default.  It shall be an event of default (an "Event of
       ----------------                                                
Default") if Key Employee fails to pay the Company pursuant to Section 5.

12.    No Right of Employment.  Nothing herein shall confer upon Key
       ----------------------                                       
Employee the right to continue in the employment of the Company nor affect any
right which the Company may have to terminate the employment of Key Employee.

13.    Miscellaneous.
       ------------- 

       13.1. This Agreement contains the full and complete understanding of the
parties and supersedes all prior representations, promises, agreements, and
warranties, whether oral or written.

       13.2. This Agreement shall be governed by and interpreted according to
the laws of the State of California, without regard to the choice of law
provisions thereunder.

       13.3. With respect to the Company, this Agreement shall inure to the
benefit of and be binding upon any successors or assigns of the Company.  With
respect to Key Employee, this Agreement shall not be assignable but shall inure
to the benefit of estate of Key Employee or his legal successor upon death or
disability.
<PAGE>
 
       13.4. The captions of the various sections of this Agreement are inserted
only for convenience and shall not be considered in construing this Agreement.

       13.5. This Agreement can be modified, amended, or any of its terms
waived only by a writing signed by both parties.

       13.6. If any provision of this Agreement shall be held invalid, illegal,
or unenforceable, the remaining provisions of the Agreement shall remain in full
force and effect and the invalid, illegal, or unenforceable provision shall be
limited or eliminated only to the extent necessary to remove such invalidity,
illegality or unenforceability in accordance with the applicable law at that
time.

       13.7. No remedy made available to the Company by any of the provisions of
this Agreement is intended to be exclusive of any other remedy.  Each and every
remedy shall be cumulative and shall be in addition to every other remedy given
hereunder as well as those remedies existing at law, in equity, by statute, or
otherwise.

       13.8. This Agreement may be executed in counterparts, each of which will
be considered an original and each of which will constitute one and the same
document.

    IN WITNESS WHEREOF, this Agreement has been executed as of the date
specified in the first paragraph.

                              ANNIE'S HOMEGROWN, INC.

                              By: __________________________
                                  Neil Raiff
                              Its: Chief Financial Officer

                              KEY EMPLOYEE:

                                    _________________________
                                    Andrew M. Martin